diff options
author | Federico Igne <undyamon@disroot.org> | 2024-01-22 23:42:56 +0100 |
---|---|---|
committer | Federico Igne <undyamon@disroot.org> | 2024-01-22 23:42:56 +0100 |
commit | 43bf616d8e58adf393762b13663cbff5ffb84ce3 (patch) | |
tree | c03243a14df68eaf44bba590d4bac15e61b60630 | |
parent | ee2c133e195e0326fcb5cecba723a5c12bdbba27 (diff) | |
download | sandy-43bf616d8e58adf393762b13663cbff5ffb84ce3.tar.gz sandy-43bf616d8e58adf393762b13663cbff5ffb84ce3.zip |
feat(mappings): Page Up/Down, Ctrl-F/B/D/U, Home, End
-rw-r--r-- | lib/command.ml | 6 | ||||
-rw-r--r-- | lib/editor.ml | 40 |
2 files changed, 42 insertions, 4 deletions
diff --git a/lib/command.ml b/lib/command.ml index a68c723..31e2ca2 100644 --- a/lib/command.ml +++ b/lib/command.ml | |||
@@ -53,6 +53,8 @@ let simple_movements = | |||
53 | Arrow_left; | 53 | Arrow_left; |
54 | Arrow_right; | 54 | Arrow_right; |
55 | Backspace; | 55 | Backspace; |
56 | End; | ||
57 | Home; | ||
56 | ] | 58 | ] |
57 | 59 | ||
58 | let to_scope = function | 60 | let to_scope = function |
@@ -60,8 +62,8 @@ let to_scope = function | |||
60 | | Key 'h' | Arrow_left | Backspace -> Left | 62 | | Key 'h' | Arrow_left | Backspace -> Left |
61 | | Key 'l' | Key ' ' | Arrow_right -> Right | 63 | | Key 'l' | Key ' ' | Arrow_right -> Right |
62 | | Key 'k' | Arrow_up -> Up | 64 | | Key 'k' | Arrow_up -> Up |
63 | | Key '0' -> To_bol | 65 | | Key '0' | Home -> To_bol |
64 | | Key '$' -> To_eol | 66 | | Key '$' | End -> To_eol |
65 | | _ -> failwith "Invalid motion." | 67 | | _ -> failwith "Invalid motion." |
66 | 68 | ||
67 | let is_simple_movement k = List.mem ~equal:Poly.equal simple_movements k | 69 | let is_simple_movement k = List.mem ~equal:Poly.equal simple_movements k |
diff --git a/lib/editor.ml b/lib/editor.ml index 96623f2..f91e66d 100644 --- a/lib/editor.ml +++ b/lib/editor.ml | |||
@@ -78,10 +78,11 @@ module Action = struct | |||
78 | in | 78 | in |
79 | modify ~f:aux | 79 | modify ~f:aux |
80 | 80 | ||
81 | let get_mode s = (s.mode, s) | 81 | let get_mode e = (e.mode, e) |
82 | let set_mode m s = ((), { s with mode = m }) | 82 | let set_mode m e = ((), { e with mode = m }) |
83 | let get_focused_buffer e = (e.buffer, e) | 83 | let get_focused_buffer e = (e.buffer, e) |
84 | let set_focused_buffer b e = ((), { e with buffer = Some b }) | 84 | let set_focused_buffer b e = ((), { e with buffer = Some b }) |
85 | let get_terminal_size e = (e.term.size, e) | ||
85 | 86 | ||
86 | let on_focused_buffer f = | 87 | let on_focused_buffer f = |
87 | let f e = { e with buffer = Option.map ~f e.buffer } in | 88 | let f e = { e with buffer = Option.map ~f e.buffer } in |
@@ -198,6 +199,25 @@ let handle_insert_command = | |||
198 | | Simple Enter -> Buffer.Action.newline |> on_focused_buffer | 199 | | Simple Enter -> Buffer.Action.newline |> on_focused_buffer |
199 | | Simple Esc -> | 200 | | Simple Esc -> |
200 | (Buffer.Action.move_left |> on_focused_buffer) *> set_mode Normal | 201 | (Buffer.Action.move_left |> on_focused_buffer) *> set_mode Normal |
202 | | Simple Page_down | Simple (Ctrl 'F') -> | ||
203 | fun e -> | ||
204 | let (n, _), e = get_terminal_size e in | ||
205 | on_focused_buffer (Buffer.Action.move_down ~n) e | ||
206 | | Simple Page_up | Simple (Ctrl 'B') -> | ||
207 | fun e -> | ||
208 | let (n, _), e = get_terminal_size e in | ||
209 | on_focused_buffer (Buffer.Action.move_up ~n) e | ||
210 | | Simple (Ctrl 'D') -> | ||
211 | fun e -> | ||
212 | let (r, _), e = get_terminal_size e in | ||
213 | on_focused_buffer (Buffer.Action.move_down ~n:(r / 2)) e | ||
214 | | Simple (Ctrl 'U') -> | ||
215 | fun e -> | ||
216 | let (r, _), e = get_terminal_size e in | ||
217 | on_focused_buffer (Buffer.Action.move_up ~n:(r / 2)) e | ||
218 | | Simple Home -> Buffer.Action.bol |> on_focused_buffer | ||
219 | | Simple End -> Buffer.Action.eol |> on_focused_buffer | ||
220 | | Simple Tab -> Buffer.Action.insert '\t' |> on_focused_buffer | ||
201 | | Type k -> Buffer.Action.insert k |> on_focused_buffer | 221 | | Type k -> Buffer.Action.insert k |> on_focused_buffer |
202 | | _ -> noop | 222 | | _ -> noop |
203 | 223 | ||
@@ -219,6 +239,22 @@ let handle_normal_command = | |||
219 | | Chord (_, n, Noop, _, To_eol) -> | 239 | | Chord (_, n, Noop, _, To_eol) -> |
220 | let n = Option.value ~default:1 n - 1 in | 240 | let n = Option.value ~default:1 n - 1 in |
221 | Buffer.Action.(move_down ~n &> eol) |> on_focused_buffer | 241 | Buffer.Action.(move_down ~n &> eol) |> on_focused_buffer |
242 | | Simple Page_down | Simple (Ctrl 'F') -> | ||
243 | fun e -> | ||
244 | let (n, _), e = get_terminal_size e in | ||
245 | on_focused_buffer (Buffer.Action.move_down ~n) e | ||
246 | | Simple Page_up | Simple (Ctrl 'B') -> | ||
247 | fun e -> | ||
248 | let (n, _), e = get_terminal_size e in | ||
249 | on_focused_buffer (Buffer.Action.move_up ~n) e | ||
250 | | Simple (Ctrl 'D') -> | ||
251 | fun e -> | ||
252 | let (r, _), e = get_terminal_size e in | ||
253 | on_focused_buffer (Buffer.Action.move_down ~n:(r / 2)) e | ||
254 | | Simple (Ctrl 'U') -> | ||
255 | fun e -> | ||
256 | let (r, _), e = get_terminal_size e in | ||
257 | on_focused_buffer (Buffer.Action.move_up ~n:(r / 2)) e | ||
222 | (* Change *) | 258 | (* Change *) |
223 | | Shortcut (_, n, Change) -> | 259 | | Shortcut (_, n, Change) -> |
224 | let n = Option.value ~default:1 n - 1 in | 260 | let n = Option.value ~default:1 n - 1 in |