Skip to main content

hjkl_vim_types/
lib.rs

1//! Vim vocabulary types for the hjkl editor.
2
3// ─── Modes & parser state ───────────────────────────────────────────────────
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6pub enum Mode {
7    #[default]
8    Normal,
9    Insert,
10    Visual,
11    VisualLine,
12    /// Column-oriented selection (`Ctrl-V`). Unlike the other visual
13    /// modes this one doesn't use tui-textarea's single-range selection
14    /// — the block corners live in [`VimState::block_anchor`] and the
15    /// live cursor. Operators read the rectangle off those two points.
16    VisualBlock,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub enum Pending {
21    #[default]
22    None,
23    /// Operator seen; still waiting for a motion / text-object / double-op.
24    /// `count1` is any count pressed before the operator.
25    Op { op: Operator, count1: usize },
26    /// Operator + 'i' or 'a' seen; waiting for the text-object character.
27    OpTextObj {
28        op: Operator,
29        count1: usize,
30        inner: bool,
31    },
32    /// Operator + 'g' seen (for `dgg`).
33    OpG { op: Operator, count1: usize },
34    /// Bare `g` seen in normal/visual — looking for `g`, `e`, `E`, …
35    G,
36    /// Bare `f`/`F`/`t`/`T` — looking for the target char.
37    Find { forward: bool, till: bool },
38    /// Operator + `f`/`F`/`t`/`T` — looking for target char.
39    OpFind {
40        op: Operator,
41        count1: usize,
42        forward: bool,
43        till: bool,
44    },
45    /// `r` pressed — waiting for the replacement char.
46    Replace,
47    /// Visual mode + `i` or `a` pressed — waiting for the text-object
48    /// character to extend the selection over.
49    VisualTextObj { inner: bool },
50    /// Bare `z` seen — looking for `z` (center), `t` (top), `b` (bottom).
51    Z,
52    /// `m` pressed — waiting for the mark letter to set.
53    SetMark,
54    /// `'` pressed — waiting for the mark letter to jump to its line
55    /// (lands on first non-blank, linewise for operators).
56    GotoMarkLine,
57    /// `` ` `` pressed — waiting for the mark letter to jump to the
58    /// exact `(row, col)` stored at set time (charwise for operators).
59    GotoMarkChar,
60    /// `"` pressed — waiting for the register selector. The next char
61    /// (`a`–`z`, `A`–`Z`, `0`–`9`, or `"`) sets `pending_register`.
62    SelectRegister,
63    /// `q` pressed (not currently recording) — waiting for the macro
64    /// register name. The macro records every key after the chord
65    /// resolves, until a bare `q` ends the recording.
66    RecordMacroTarget,
67    /// `@` pressed — waiting for the macro register name to play.
68    /// `count` is the prefix multiplier (`3@a` plays the macro 3
69    /// times); 0 means "no prefix" and is treated as 1.
70    PlayMacroTarget { count: usize },
71    /// `[` pressed in Normal/Visual mode — waiting for the second key.
72    /// Resolves `[[` → `SectionBackward`, `[]` → `SectionEndBackward`.
73    SquareBracketOpen,
74    /// `]` pressed in Normal/Visual mode — waiting for the second key.
75    /// Resolves `]]` → `SectionForward`, `][` → `SectionEndForward`.
76    SquareBracketClose,
77    /// Operator + `[` pending — waiting for second key to pick section motion.
78    OpSquareBracketOpen { op: Operator, count1: usize },
79    /// Operator + `]` pending — waiting for second key to pick section motion.
80    OpSquareBracketClose { op: Operator, count1: usize },
81    /// `s` / `S` in Normal mode with `motion_sneak=true` — waiting for
82    /// the first character of the two-char digraph.
83    /// `forward=true` → `s`; `forward=false` → `S` (backward).
84    SneakFirst { forward: bool, count: usize },
85    /// First sneak char captured; waiting for the second char to complete
86    /// the digraph and jump.
87    SneakSecond {
88        c1: char,
89        forward: bool,
90        count: usize,
91    },
92    /// Operator + `s` / `S` pending — waiting for the first char of the
93    /// two-char sneak digraph (e.g. `d` then `s` then `a` then `b` = `dsab`).
94    OpSneakFirst {
95        op: Operator,
96        count1: usize,
97        forward: bool,
98    },
99    /// Operator + sneak first char captured; waiting for the second char.
100    OpSneakSecond {
101        op: Operator,
102        count1: usize,
103        c1: char,
104        forward: bool,
105    },
106}
107
108// ─── Operator / Motion / TextObject ────────────────────────────────────────
109
110#[derive(Debug, Clone, Copy, PartialEq, Eq)]
111pub enum Operator {
112    Delete,
113    Change,
114    Yank,
115    /// `gU{motion}` — uppercase the range. Entered via the `g` prefix
116    /// in normal mode or `U` in visual mode.
117    Uppercase,
118    /// `gu{motion}` — lowercase the range. `u` in visual mode.
119    Lowercase,
120    /// `g~{motion}` — toggle case of the range. `~` in visual mode
121    /// (character at the cursor for the single-char `~` command stays
122    /// its own code path in normal mode).
123    ToggleCase,
124    /// `>{motion}` — indent the line range by `shiftwidth` spaces.
125    /// Always linewise, even when the motion is char-wise — mirrors
126    /// vim's behaviour where `>w` indents the current line, not the
127    /// word on it.
128    Indent,
129    /// `<{motion}` — outdent the line range (remove up to
130    /// `shiftwidth` leading spaces per line).
131    Outdent,
132    /// `zf{motion}` / `zf{textobj}` / Visual `zf` — create a closed
133    /// fold spanning the row range. Doesn't mutate the buffer text;
134    /// cursor restores to the operator's start position.
135    Fold,
136    /// `gq{motion}` — reflow the row range to `settings.textwidth`.
137    /// Greedy word-wrap: collapses each paragraph (blank-line-bounded
138    /// run) into space-separated words, then re-emits lines whose
139    /// width stays under `textwidth`. Always linewise, like indent.
140    Reflow,
141    /// `gw{motion}` — same reflow as `gq` but cursor stays at the
142    /// pre-reflow `(row, col)`. If the reflow shrinks the line so the
143    /// original col is past the new EOL, the col is clamped to the last
144    /// char of the line (vim's behaviour). Always linewise.
145    ReflowKeepCursor,
146    /// `={motion}` — auto-indent the line range using shiftwidth-based
147    /// bracket depth counting (v1 dumb reindent). Always linewise.
148    /// See `auto_indent_range` for the algorithm and its limitations.
149    AutoIndent,
150    /// `!{motion}` — filter the line range through an external shell command.
151    /// The range text is piped to the command's stdin; stdout replaces the
152    /// range in the buffer. Non-zero exit or spawn failure returns an error
153    /// to the caller without mutating the buffer.
154    Filter,
155    /// `gc{motion}` / `gcc` — toggle line comments on the row range.
156    /// Dispatched through `Editor::toggle_comment_range` rather than the
157    /// normal `run_operator_over_range` pipeline (same pattern as `Filter`).
158    Comment,
159    /// `g?{motion}` / `g??` / visual `g?` — ROT13 the range. Same operator
160    /// shape as the case ops; only the per-char transform differs.
161    Rot13,
162}
163
164#[derive(Debug, Clone, PartialEq, Eq)]
165pub enum Motion {
166    Left,
167    Right,
168    /// `<Space>` — right-motion that wraps to the next line at EOL (vim's
169    /// default `whichwrap=b,s`). Distinct from `Right`/`l` which never wrap.
170    SpaceFwd,
171    /// `<BS>` — left-motion that wraps to the previous line's last char at BOL
172    /// (`whichwrap=b`). Distinct from `Left`/`h` which never wrap.
173    BackspaceBack,
174    Up,
175    Down,
176    WordFwd,
177    BigWordFwd,
178    WordBack,
179    BigWordBack,
180    WordEnd,
181    BigWordEnd,
182    /// The word-end motion `cw` / `cW` runs instead of `w` / `W` when the
183    /// cursor is on a non-blank (`:h cw`). It is NOT `e` / `E`: vim calls
184    /// `end_word()` with its `stop` flag set, so a first iteration that
185    /// starts on the last character of a word does not move — `cw` there
186    /// changes just that character, where `ce` runs on to the next word's
187    /// end. `big` picks `cW` over `cw`.
188    ChangeWordEnd {
189        big: bool,
190    },
191    /// `ge` — backward word end.
192    WordEndBack,
193    /// `gE` — backward WORD end.
194    BigWordEndBack,
195    LineStart,
196    FirstNonBlank,
197    LineEnd,
198    FileTop,
199    FileBottom,
200    Find {
201        ch: char,
202        forward: bool,
203        till: bool,
204    },
205    FindRepeat {
206        reverse: bool,
207    },
208    MatchBracket,
209    /// `[(` / `])` / `[{` / `]}` — jump to the previous/next unmatched bracket
210    /// of the given kind. `open` is the open char (`(` or `{`); `forward` picks
211    /// the close (`)`/`}`) when true, the open when false.
212    UnmatchedBracket {
213        forward: bool,
214        open: char,
215    },
216    WordAtCursor {
217        forward: bool,
218        /// `*` / `#` use `\bword\b` boundaries; `g*` / `g#` drop them so
219        /// the search hits substrings (e.g. `foo` matches inside `foobar`).
220        whole_word: bool,
221    },
222    /// `n` / `N` — repeat the last `/` or `?` search.
223    SearchNext {
224        reverse: bool,
225    },
226    /// `H` — cursor to viewport top (plus `count - 1` rows down).
227    ViewportTop,
228    /// `M` — cursor to viewport middle.
229    ViewportMiddle,
230    /// `L` — cursor to viewport bottom (minus `count - 1` rows up).
231    ViewportBottom,
232    /// `g_` — last non-blank char on the line.
233    LastNonBlank,
234    /// `gM` — cursor to the middle char column of the current line
235    /// (`floor(chars / 2)`). Vim's variant ignoring screen wrap.
236    LineMiddle,
237    /// `gm` — cursor to the middle of the *screen* line: column
238    /// `min(viewport_width / 2, last_col)`. Differs from `gM` (char-middle).
239    ScreenLineMiddle,
240    /// `{` — previous paragraph (preceding blank line, or top).
241    ParagraphPrev,
242    /// `}` — next paragraph (following blank line, or bottom).
243    ParagraphNext,
244    /// `(` — previous sentence boundary.
245    SentencePrev,
246    /// `)` — next sentence boundary.
247    SentenceNext,
248    /// `gj` — `count` visual rows down (one screen segment per step
249    /// under `:set wrap`; falls back to `Down` otherwise).
250    ScreenDown,
251    /// `gk` — `count` visual rows up; mirror of [`Motion::ScreenDown`].
252    ScreenUp,
253    /// `[[` — backward to the previous `{` at column 0 (C section header).
254    /// Charwise exclusive; count-aware.
255    SectionBackward,
256    /// `]]` — forward to the next `{` at column 0. Charwise exclusive.
257    SectionForward,
258    /// `[]` — backward to the previous `}` at column 0 (C section end).
259    /// Charwise exclusive; count-aware.
260    SectionEndBackward,
261    /// `][` — forward to the next `}` at column 0. Charwise exclusive.
262    SectionEndForward,
263    /// `+` / `<CR>` — first non-blank of the next line. Linewise.
264    FirstNonBlankNextLine,
265    /// `-` — first non-blank of the previous line. Linewise.
266    FirstNonBlankPrevLine,
267    /// `_` — first non-blank of `count-1` lines down (count=1 = current line). Linewise.
268    FirstNonBlankLine,
269    /// `{count}|` — jump to column `count` on the current line (1-based;
270    /// no count or count=0 → column 1 → index 0). Clamped to line length.
271    GotoColumn,
272}
273
274#[derive(Debug, Clone, Copy, PartialEq, Eq)]
275pub enum TextObject {
276    Word {
277        big: bool,
278    },
279    Quote(char),
280    Bracket(char),
281    Paragraph,
282    /// `it` / `at` — XML/HTML-style tag pair. `inner = true` covers
283    /// content between `>` and `</`; `inner = false` covers the open
284    /// tag through the close tag inclusive.
285    XmlTag,
286    /// `is` / `as` — sentence: a run ending at `.`, `?`, or `!`
287    /// followed by whitespace or end-of-line. `inner = true` covers
288    /// the sentence text only; `inner = false` includes trailing
289    /// whitespace.
290    Sentence,
291}
292
293/// Classification determines how operators treat the range end.
294#[derive(Debug, Clone, Copy, PartialEq, Eq)]
295pub enum RangeKind {
296    /// Range end is exclusive (end column not included). Typical: h, l, w, 0, $.
297    Exclusive,
298    /// Range end is inclusive. Typical: e, f, t, %.
299    Inclusive,
300    /// Whole lines from top row to bottom row. Typical: j, k, gg, G.
301    Linewise,
302}
303
304// ─── Dot-repeat storage ────────────────────────────────────────────────────
305
306/// Information needed to replay a mutating change via `.`.
307#[derive(Debug, Clone)]
308pub enum LastChange {
309    /// Operator over a motion.
310    OpMotion {
311        op: Operator,
312        motion: Motion,
313        count: usize,
314        inserted: Option<String>,
315        /// The explicit register the original change used (`"adw`), if any.
316        /// See [`LastChange::LineOp::register`].
317        register: Option<char>,
318    },
319    /// Operator over a text-object.
320    OpTextObj {
321        op: Operator,
322        obj: TextObject,
323        inner: bool,
324        inserted: Option<String>,
325        /// The explicit register the original change used (`"adiw`), if any.
326        /// See [`LastChange::LineOp::register`].
327        register: Option<char>,
328    },
329    /// `dd`, `cc`, `yy` with a count.
330    LineOp {
331        op: Operator,
332        count: usize,
333        inserted: Option<String>,
334        /// The explicit register (`"add`, `"ayy`, ...) the original change
335        /// used, if any. `.` must reuse it (`:h redo-register`) rather than
336        /// falling back to the unnamed register.
337        register: Option<char>,
338    },
339    /// `x`, `X` with a count.
340    CharDel {
341        forward: bool,
342        count: usize,
343        /// The explicit register the original change used (`"ax`), if any.
344        /// See [`LastChange::LineOp::register`].
345        register: Option<char>,
346    },
347    /// `r<ch>` with a count.
348    ReplaceChar { ch: char, count: usize },
349    /// `~` with a count.
350    ToggleCase { count: usize },
351    /// `J` with a count.
352    JoinLine { count: usize },
353    /// `p` / `P` (and `gp`/`gP`, `]p`/`[p`) with a count.
354    Paste {
355        before: bool,
356        count: usize,
357        /// `gp` / `gP` — leave the cursor just after the pasted text.
358        cursor_after: bool,
359        /// `]p` / `[p` — reindent the pasted block to the current line.
360        reindent: bool,
361        /// The explicit register the original paste read (`"ap`), if any.
362        /// See [`LastChange::LineOp::register`].
363        register: Option<char>,
364    },
365    /// `D` (delete to EOL).
366    DeleteToEol {
367        inserted: Option<String>,
368        /// The explicit register the original delete wrote (`"aD`), if any.
369        /// See [`LastChange::LineOp::register`].
370        register: Option<char>,
371    },
372    /// `o` / `O` + the inserted text.
373    OpenLine { above: bool, inserted: String },
374    /// `i`/`I`/`a`/`A` + inserted text.
375    InsertAt {
376        entry: InsertEntry,
377        inserted: String,
378        count: usize,
379    },
380    /// `dgn` / `cgn` (and `gN` forms) — operate on the next search match.
381    /// `inserted` is filled on Esc for the `cgn` change form so `.` retypes it.
382    GnOp {
383        op: Operator,
384        forward: bool,
385        inserted: Option<String>,
386        /// The explicit register the original change used (`"acgn`), if any.
387        /// See [`LastChange::LineOp::register`].
388        register: Option<char>,
389    },
390    /// `R{text}<Esc>` — replace (overstrike) mode. `.` re-overtypes `text`.
391    ReplaceMode { text: String },
392    /// A visual-mode operator (`v`/`V` + `d`/`c`/`</>`/`~`/`u`/`U`/`?`).
393    /// vim (`:h v_.`) replays over a same-SIZE region anchored at the
394    /// current cursor rather than the original absolute range — `extent`
395    /// captures that size. `inserted` is filled on Esc for the `c` form so
396    /// `.` retypes it (same `AfterChange` patch site as `OpMotion` /
397    /// `OpTextObj` / `LineOp`).
398    ///
399    /// `d` / `c` / `~`/`u`/`U`/`g?` from Visual — charwise, linewise, AND
400    /// blockwise (`VisualExtent::Block`). Block `c` fills `inserted` at its
401    /// own `BlockChange` finish site (`comment.rs`), mirroring the charwise
402    /// `AfterChange` patch.
403    VisualOp {
404        op: Operator,
405        extent: VisualExtent,
406        inserted: Option<String>,
407        /// The explicit register the original change used (`vll"ad`), if
408        /// any. See [`LastChange::LineOp::register`].
409        register: Option<char>,
410    },
411    /// Charwise (`v`) / linewise (`V`) `r{ch}` — dot-repeat re-replaces a
412    /// same-SIZE region anchored at the cursor (`:h v_.`), mirroring
413    /// `VisualBlockReplace` for the block case. `r` has no `Operator`, so it
414    /// rides its own variant instead of `VisualOp`. `extent` is a
415    /// `VisualExtent::Char` or `VisualExtent::Line` captured from the live
416    /// selection.
417    VisualReplace { ch: char, extent: VisualExtent },
418    /// Visual-BLOCK `r{ch}` — dot-repeat re-replaces a same-size rectangle
419    /// anchored TOP-LEFT at the cursor. `r` has no `Operator`, so it rides
420    /// its own variant instead of `VisualOp`. `to_eol` preserves a `$`-ragged
421    /// right edge (`:h v_b_$`).
422    VisualBlockReplace {
423        ch: char,
424        rows: usize,
425        cols: usize,
426        to_eol: bool,
427    },
428    /// Visual-BLOCK `I` / `A` — dot-repeat re-inserts `text` at the block's
429    /// left (`append == false`) or right (`append == true`) edge over a
430    /// same-size rectangle anchored TOP-LEFT at the cursor. `cols` is the
431    /// block width (`A` appends `cols` columns past the cursor); `to_eol`
432    /// preserves a `$`-ragged right edge (`A` only, `:h v_b_$`).
433    VisualBlockInsert {
434        text: String,
435        rows: usize,
436        cols: usize,
437        to_eol: bool,
438        append: bool,
439    },
440}
441
442/// Size of a visual-mode selection, captured for `LastChange::VisualOp`
443/// dot-repeat (`:h v_.`). Vim's rule: characterwise replays over the same
444/// number of lines, with the same character width on the last line;
445/// linewise replays over the same number of lines.
446#[derive(Debug, Clone, Copy, PartialEq, Eq)]
447pub enum VisualExtent {
448    /// Charwise (`v`). `lines == 1`: `width` is the raw selected char count,
449    /// and replay selects exactly `width` chars starting at the cursor.
450    /// `lines > 1`: the first replay line runs from the cursor's column to
451    /// ITS OWN end of line, middle lines are taken whole, and the last line
452    /// takes its first `width` chars (measured from column 0, matching the
453    /// original selection's last-line char count).
454    Char { lines: usize, width: usize },
455    /// Linewise (`V`). Replay is exactly `[count]dd`-equivalent: `lines`
456    /// rows starting at the cursor's row.
457    Line { lines: usize },
458    /// Blockwise (`<C-v>`). Replay reconstructs a `rows` × `cols` rectangle
459    /// with its TOP-LEFT corner at the cursor (`:h v_.` for blocks), then
460    /// re-runs the operator. `to_eol` preserves a `$`-ragged right edge
461    /// (`:h v_b_$`) — every row then resolves its own EOL instead of the
462    /// fixed `cols` width.
463    Block {
464        rows: usize,
465        cols: usize,
466        to_eol: bool,
467    },
468}
469
470#[derive(Debug, Clone, Copy, PartialEq, Eq)]
471pub enum InsertEntry {
472    I,
473    A,
474    ShiftI,
475    ShiftA,
476}
477
478/// Tracks which kind of horizontal jump was last performed so `;` / `,`
479/// can dispatch to the correct repeat handler.
480///
481/// - `FindChar` — last horizontal motion was `f`/`F`/`t`/`T`; `;`/`,`
482///   repeats via `Motion::FindRepeat`.
483/// - `Sneak` — last horizontal motion was `s`/`S` sneak; `;`/`,` repeats
484///   via `apply_sneak` with the stored digraph.
485/// - `None` — no horizontal motion yet; `;`/`,` are no-ops for both.
486#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
487pub enum LastHorizontalMotion {
488    #[default]
489    None,
490    FindChar,
491    Sneak,
492}
493
494#[derive(Debug, Clone)]
495pub struct InsertSession {
496    pub count: usize,
497    /// Min/max row visited during this session. Widens on every key.
498    pub row_min: usize,
499    pub row_max: usize,
500    /// O(1) rope snapshot of the full buffer at session entry. Used to
501    /// diff the affected row window at finish without being fooled by
502    /// cursor navigation through rows the user never edited.
503    /// `ropey::Rope::clone` is Arc-clone — no byte copying.
504    pub before_rope: ropey::Rope,
505    pub reason: InsertReason,
506    /// (row, col) where the insert session began (char-indexed). Abbreviation
507    /// expansion uses `start_col` as `mincol` — only chars at or after this
508    /// column on `start_row` are eligible as part of the `lhs` match, so
509    /// pre-existing buffer text is never consumed by expansion.
510    pub start_row: usize,
511    pub start_col: usize,
512}
513
514#[derive(Debug, Clone)]
515pub enum InsertReason {
516    /// Plain entry via i/I/a/A — recorded as `InsertAt`.
517    Enter(InsertEntry),
518    /// Entry via `o`/`O` — records OpenLine on Esc.
519    Open { above: bool },
520    /// Entry via an operator's change side-effect. Retro-fills the
521    /// stored last-change's `inserted` field on Esc.
522    AfterChange,
523    /// Entry via `C` (delete to EOL + insert).
524    DeleteToEol,
525    /// Entry via an insert triggered during dot-replay — don't touch
526    /// last_change because the outer replay will restore it.
527    ReplayOnly,
528    /// `I` or `A` from VisualBlock: insert the typed text at `col` on
529    /// rows in `top..=bot`. `col` is the start column for `I`, the
530    /// one-past-block-end column for `A`.
531    ///
532    /// `pad` distinguishes the two vim behaviours at rows shorter than
533    /// `col` (`:h v_b_I` vs `:h v_b_A`): `A` pads short rows with spaces
534    /// so the appended text still lines up (`pad: true`); `I` skips rows
535    /// that don't reach `col` entirely — no padding, no insert on that
536    /// row (`pad: false`).
537    ///
538    /// `cursor_col` is where the cursor lands on Esc — the block's LEFT
539    /// edge for both `I` and `A` (verified against real nvim: `A`'s
540    /// cursor does NOT land at the append/typed position, `col`, once
541    /// the block is more than one column wide). For `I`, `cursor_col ==
542    /// col` (its insertion point already IS the left edge); for `A` they
543    /// differ whenever the block spans more than one column.
544    BlockEdge {
545        top: usize,
546        bot: usize,
547        col: usize,
548        pad: bool,
549        cursor_col: usize,
550        /// Top row's char count BEFORE the `A` pad was applied. Recorded at
551        /// construction so `finish_insert_session` can remove exactly the
552        /// pad's bytes (`pre_pad_len..col`) on an empty Esc — the pad itself
553        /// is never recorded as an undo step, so its range must be stashed
554        /// here rather than derived from the (already padded) live buffer.
555        pre_pad_len: usize,
556        /// Undo-stack depth recorded just before the caller's `push_undo` for
557        /// this block command. An empty block-`A` pushes a no-op undo
558        /// boundary; when it is still the most recent one (depth == this + 1
559        /// at Esc — nothing else pushed mid-session, and the push was not
560        /// suppressed by an enclosing undo group), `finish_insert_session`
561        /// consumes it so the no-op command leaves the undo tree untouched.
562        undo_depth_before: usize,
563    },
564    /// `c` from VisualBlock: block content deleted, then user types
565    /// replacement text replicated across all block rows on Esc. Cursor
566    /// advances to the last typed char after replication (unlike BlockEdge
567    /// which leaves cursor at the insertion column).
568    BlockChange { top: usize, bot: usize, col: usize },
569    /// `R` — Replace mode. Each typed char overwrites the cell under
570    /// the cursor instead of inserting; at end-of-line the session
571    /// falls through to insert (same as vim).
572    Replace,
573}
574
575/// Saved visual-mode anchor + cursor for `gv` (re-enters the last
576/// visual selection). `mode` carries which visual flavour to
577/// restore; `anchor` / `cursor` mean different things per flavour:
578///
579/// - `Visual`     — `anchor` is the char-wise visual anchor.
580/// - `VisualLine` — `anchor.0` is the `visual_line_anchor` row;
581///   `anchor.1` is unused.
582/// - `VisualBlock`— `anchor` is `block_anchor`, `block_vcol` is the
583///   sticky vcol that survives j/k clamping.
584#[derive(Debug, Clone, Copy)]
585pub struct LastVisual {
586    pub mode: Mode,
587    pub anchor: (usize, usize),
588    pub cursor: (usize, usize),
589    pub block_vcol: usize,
590}