Skip to content

Commit 1e8d897

Browse files
committed
Add x and caret
1 parent 9f9b362 commit 1e8d897

File tree

7 files changed

+32
-2
lines changed

7 files changed

+32
-2
lines changed

sqlit/core/keymap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"question_mark": "?",
1212
"slash": "/",
1313
"asterisk": "*",
14+
"circumflex_accent": "^",
1415
"dollar_sign": "$",
1516
"percent_sign": "%",
1617
"space": "<space>",
@@ -357,13 +358,15 @@ def _build_action_keys(self) -> list[ActionKeyDef]:
357358
ActionKeyDef("b", "cursor_word_back", "query_normal"),
358359
ActionKeyDef("B", "cursor_WORD_back", "query_normal"),
359360
ActionKeyDef("0", "cursor_line_start", "query_normal"),
361+
ActionKeyDef("circumflex_accent", "cursor_first_non_blank", "query_normal"),
360362
ActionKeyDef("dollar_sign", "cursor_line_end", "query_normal"),
361363
ActionKeyDef("G", "cursor_last_line", "query_normal"),
362364
ActionKeyDef("percent_sign", "cursor_matching_bracket", "query_normal"),
363365
ActionKeyDef("f", "cursor_find_char", "query_normal"),
364366
ActionKeyDef("F", "cursor_find_char_back", "query_normal"),
365367
ActionKeyDef("t", "cursor_till_char", "query_normal"),
366368
ActionKeyDef("T", "cursor_till_char_back", "query_normal"),
369+
ActionKeyDef("x", "delete_char", "query_normal"),
367370
ActionKeyDef("a", "append_insert_mode", "query_normal"),
368371
ActionKeyDef("A", "append_line_end", "query_normal"),
369372
# Query (insert mode)

sqlit/domains/query/editing/motions/lines.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ def motion_line_start(
2222
)
2323

2424

25+
def motion_first_non_blank(
26+
text: str, row: int, col: int, char: str | None = None
27+
) -> MotionResult:
28+
"""Move to first non-whitespace character on line (^)."""
29+
lines, row, col = _normalize(text, row, col)
30+
line = lines[row]
31+
first_col = len(line) - len(line.lstrip())
32+
return MotionResult(
33+
position=Position(row, first_col),
34+
range=Range(
35+
Position(row, min(col, first_col)),
36+
Position(row, max(col, first_col)),
37+
MotionType.CHARWISE,
38+
inclusive=False,
39+
),
40+
)
41+
42+
2543
def motion_line_end(
2644
text: str, row: int, col: int, char: str | None = None
2745
) -> MotionResult:

sqlit/domains/query/editing/motions/registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .lines import (
99
motion_current_line,
1010
motion_first_line,
11+
motion_first_non_blank,
1112
motion_last_line,
1213
motion_line_end,
1314
motion_line_start,
@@ -42,6 +43,7 @@
4243
"e": motion_word_end,
4344
"E": motion_WORD_end,
4445
"0": motion_line_start,
46+
"^": motion_first_non_blank,
4547
"$": motion_line_end,
4648
"G": motion_last_line,
4749
"gg": motion_first_line, # Go to first line

sqlit/domains/query/state/query_normal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def _setup_actions(self) -> None:
3131
self.allows("cursor_WORD_forward", help="Move to next WORD")
3232
self.allows("cursor_word_back", help="Move to previous word")
3333
self.allows("cursor_WORD_back", help="Move to previous WORD")
34+
self.allows("cursor_first_non_blank", help="Move to first non-blank")
3435
self.allows("cursor_line_start", help="Move to line start")
3536
self.allows("cursor_line_end", help="Move to line end")
3637
self.allows("cursor_last_line", help="Move to last line")
@@ -45,6 +46,8 @@ def _setup_actions(self) -> None:
4546
# Vim open line
4647
self.allows("open_line_below", help="Open line below")
4748
self.allows("open_line_above", help="Open line above")
49+
# Vim delete char
50+
self.allows("delete_char", help="Delete character under cursor")
4851
# Vim delete or change
4952
self.allows("change_line_end_motion", help="Change to line end")
5053
self.allows("delete_line_end", help="Delete to line end")

sqlit/domains/query/ui/mixins/query_editing_cursor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def action_cursor_WORD_back(self: QueryMixinHost) -> None:
107107
"""Move cursor to previous WORD (B)."""
108108
self._move_with_motion("B")
109109

110+
def action_cursor_first_non_blank(self: QueryMixinHost) -> None:
111+
"""Move cursor to first non-whitespace character (^)."""
112+
self._move_with_motion("^")
113+
110114
def action_cursor_line_start(self: QueryMixinHost) -> None:
111115
"""Move cursor to start of line (0)."""
112116
self._move_with_motion("0")

sqlit/domains/shell/state/machine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def binding(key: str, desc: str, indent: int = 4) -> str:
224224
lines.append(binding("h/j/k/l", "Cursor left/down/up/right"))
225225
lines.append(binding("w/W", "Word forward"))
226226
lines.append(binding("b/B", "Word backward"))
227-
lines.append(binding("0/$", "Line start/end"))
227+
lines.append(binding("0/^/$", "Line start/first char/end"))
228228
lines.append(binding("gg/G", "File start/end"))
229229
lines.append(binding("f{c}/F{c}", "Find char forward/back"))
230230
lines.append(binding("t{c}/T{c}", "Till char forward/back"))

tests/unit/test_vim_motions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def test_all_motions_registered(self) -> None:
212212
expected = {
213213
"h", "j", "k", "l",
214214
"w", "W", "b", "B", "e", "E",
215-
"0", "$", "G", "gg", "ge", "gE", "_",
215+
"0", "^", "$", "G", "gg", "ge", "gE", "_",
216216
"f", "F", "t", "T",
217217
"%",
218218
}

0 commit comments

Comments
 (0)