summaryrefslogtreecommitdiff
path: root/src/modal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:02:01 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:16:28 -0300
commit4423bc2f88fe2e88202056d6a11f759b4b143b74 (patch)
tree2e19a95e97a38088a288444b0e298251fe911506 /src/modal.zig
parentadc8a50289f17ba15867f6d8e45844f57ee1aaa8 (diff)
downloadpardes-4423bc2f88fe2e88202056d6a11f759b4b143b74.tar.gz
pardes-4423bc2f88fe2e88202056d6a11f759b4b143b74.zip
modal, selection_pipe, syntax, sam_edit: helpers used once are inlined where they are used (consumeCount, clampLineCol, codepointAtCursor, isWordBoundary, wmIsPrev, tokenStopped, dropDiffPieces, Exec.text), and moveWord's doc comment goes back above moveWord
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/modal.zig')
-rw-r--r--src/modal.zig52
1 files changed, 14 insertions, 38 deletions
diff --git a/src/modal.zig b/src/modal.zig
index 7e10a877..e123d468 100644
--- a/src/modal.zig
+++ b/src/modal.zig
@@ -412,12 +412,6 @@ pub const Normal = struct {
return .{ .action = value };
}
- fn consumeCount(state: *State) Counted {
- const count = state.count;
- state.count = 0;
- return .{ .count = @max(1, count), .explicit = count != 0 };
- }
-
fn armPrefix(state: *State, prefix: Prefix, saved_count: u32) Result {
state.prefix = prefix;
state.count = saved_count;
@@ -448,7 +442,8 @@ pub const Normal = struct {
return .pending;
}
- const counted = consumeCount(state);
+ const counted: Counted = .{ .count = @max(1, state.count), .explicit = state.count != 0 };
+ state.count = 0;
const count = counted.count;
switch (state.prefix) {
@@ -846,22 +841,11 @@ pub fn charRight(lines: []const []const u8, c: Cursor) Cursor {
return .{ .row = c.row, .col = if (c.col < last) @min(nextGrapheme(lines[c.row], c.col), last) else last };
}
-fn clampLineCol(line: []const u8, col: usize) usize {
- if (line.len == 0) return 0;
- const last = prevGrapheme(line, line.len);
- return graphemeStart(line, @min(col, last));
-}
-
-// the character the cursor sits on; line terminators / EOF read as '\n'.
-fn codepointAtCursor(lines: []const []const u8, c: Cursor) u21 {
- if (c.row >= lines.len) return '\n';
- const line = lines[c.row];
- if (c.col >= line.len) return '\n';
- return codepointAt(line, graphemeStart(line, c.col));
-}
-
+// the ASCII character the cursor sits on, 0 for any other; line terminators
+// and EOF read as '\n'.
fn charAt(lines: []const []const u8, c: Cursor) u8 {
- const cp = codepointAtCursor(lines, c);
+ if (c.row >= lines.len or c.col >= lines[c.row].len) return '\n';
+ const cp = codepointAt(lines[c.row], graphemeStart(lines[c.row], c.col));
return if (cp <= 0x7f) @intCast(cp) else 0;
}
@@ -949,7 +933,7 @@ pub fn clampToChar(lines: []const []const u8, c: Cursor) Cursor {
}
const llen = lineLenOf(lines, c.row);
if (llen == 0) return .{ .row = c.row, .col = 0 };
- return .{ .row = c.row, .col = clampLineCol(lines[c.row], c.col) };
+ return .{ .row = c.row, .col = graphemeStart(lines[c.row], @min(c.col, prevGrapheme(lines[c.row], llen))) };
}
pub fn lineCount(content: []const u8) usize {
@@ -1494,10 +1478,6 @@ fn isWordWhitespace(c: WordClass) bool { // Rust char::is_whitespace (includes l
return c == .ws or c == .eol;
}
-fn isWordBoundary(a: WordClass, b: WordClass) bool {
- return a != b;
-}
-
fn isLongWordBoundary(a: WordClass, b: WordClass) bool {
if ((a == .word and b == .punct) or (a == .punct and b == .word)) return false;
return a != b;
@@ -1505,21 +1485,13 @@ fn isLongWordBoundary(a: WordClass, b: WordClass) bool {
fn reachedWordTarget(target: WordTarget, prev: WordClass, next: WordClass) bool {
return switch (target) {
- .next_word_start, .prev_word_end => isWordBoundary(prev, next) and (next == .eol or !isWordWhitespace(next)),
- .next_word_end, .prev_word_start => isWordBoundary(prev, next) and (!isWordWhitespace(prev) or next == .eol),
+ .next_word_start, .prev_word_end => prev != next and (next == .eol or !isWordWhitespace(next)),
+ .next_word_end, .prev_word_start => prev != next and (!isWordWhitespace(prev) or next == .eol),
.next_long_word_start, .prev_long_word_end => isLongWordBoundary(prev, next) and (next == .eol or !isWordWhitespace(next)),
.next_long_word_end, .prev_long_word_start => isLongWordBoundary(prev, next) and (!isWordWhitespace(prev) or next == .eol),
};
}
-fn wmIsPrev(t: WordTarget) bool {
- return switch (t) {
- .prev_word_start, .prev_word_end, .prev_long_word_start, .prev_long_word_end => true,
- else => false,
- };
-}
-
-/// w/b/e/W/B/E: helix word_move — each step selects the traversed span.
/// helix jump_to_word's candidates: the words of two or more word
/// characters between `start` and `end`, nearest the cursor first, taking one
/// forward and one back in turn, each over its word pointing the way it was
@@ -1567,8 +1539,12 @@ pub fn jumpWords(text: []const u8, cursor: usize, start: usize, end: usize, out:
return n;
}
+/// w/b/e/W/B/E: helix word_move — each step selects the traversed span.
pub fn moveWord(text: []const u8, r0: Selection, count: usize, target: WordTarget) Selection {
- const is_prev = wmIsPrev(target);
+ const is_prev = switch (target) {
+ .prev_word_start, .prev_word_end, .prev_long_word_start, .prev_long_word_end => true,
+ else => false,
+ };
if ((is_prev and r0.head == 0) or (!is_prev and r0.head == text.len)) return r0;
// block-cursor prep: collapse to the 1-wide cell at the head, pointing
// in the motion direction (the anchor of the input is irrelevant)