1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Engine-level types relocated from `hjkl-engine` so that [`crate::Content`]
//! can own per-buffer engine state (undo stack, change log, pending edits,
//! fold ops) without requiring `hjkl-buffer` to depend on `hjkl-engine`.
//!
//! `hjkl-engine` re-exports these via `pub use hjkl_buffer::{...}` so all
//! existing call sites continue to compile without change.
use Range;
// ── Pos ───────────────────────────────────────────────────────────────────
/// Grapheme-indexed position. `line` is zero-based row; `col` is zero-based
/// grapheme column within that line.
///
/// Note that `col` counts graphemes, not bytes or chars. Motions and
/// rendering both honor grapheme boundaries.
// ── EngineEdit ────────────────────────────────────────────────────────────
/// A pending or applied edit. Multi-cursor edits fan out to `Vec<EngineEdit>`
/// ordered in **reverse byte offset** so each entry's positions remain valid
/// after the prior entry applies.
///
/// Named `EngineEdit` here to avoid collision with [`crate::Edit`] (the
/// buffer-level edit enum). `hjkl-engine` re-exports this as
/// `pub use hjkl_buffer::EngineEdit as Edit`.
// ── ContentEdit ───────────────────────────────────────────────────────────
/// Engine-native representation of a single buffer mutation in the
/// shape tree-sitter's `InputEdit` consumes. Emitted by
/// `hjkl_engine::Editor::mutate_edit` and drained by hosts via
/// `hjkl_engine::Editor::take_content_edits` so the syntax layer can fan
/// edits into a retained tree without the engine taking a tree-sitter
/// dependency.
///
/// Positions are `(row, col_byte)` — byte offsets within the row, not
/// char counts. Multi-row inserts/deletes set `new_end_position.0` /
/// `old_end_position.0` to the relevant row delta. Conversion to
/// `tree_sitter::InputEdit` is mechanical (see `apps/hjkl/src/syntax.rs`).
// ── FoldOp ────────────────────────────────────────────────────────────────
/// A fold operation dispatched by the engine's `z…` keystrokes, `:fold*` ex
/// commands, and the edit-pipeline's "edits inside a fold open it"
/// invalidation.
///
/// `FoldOp` is engine-canonical (per the design doc's resolved
/// question 8.2): hosts don't invent their own fold-op enums. Each
/// host that exposes folds embeds a `FoldOp` variant in its `Intent`
/// enum (or simply observes the engine's pending-fold-op queue via
/// `hjkl_engine::Editor::take_fold_ops`).
///
/// Row indices are zero-based and match the row coordinate space used
/// by [`crate::Buffer`]'s fold methods.