diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:31:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:16:28 -0300 |
| commit | 2504b38647653db091aa7709afcea0dbe75f7a95 (patch) | |
| tree | 2fefb992a86d2432c00ab4b431f65b649421a0dd | |
| parent | 2aa1801dbad2a26348aef085d9dee8096f8d2eb3 (diff) | |
| download | pardes-2504b38647653db091aa7709afcea0dbe75f7a95.tar.gz pardes-2504b38647653db091aa7709afcea0dbe75f7a95.zip | |
normal, modal, File, edit: small ones: tryFind inlined (its clamp never bound), the smart-case haystack is allocLowerString, the two WordTargets nothing produces go, File.lineCount is modal.cursorLineCount's alias, and pasteRegister and ClipRequest share one Paste enum
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/File.zig | 4 | ||||
| -rw-r--r-- | src/edit.zig | 15 | ||||
| -rw-r--r-- | src/modal.zig | 11 | ||||
| -rw-r--r-- | src/normal.zig | 22 |
4 files changed, 16 insertions, 36 deletions
diff --git a/src/File.zig b/src/File.zig index ad76909d..43eccc49 100644 --- a/src/File.zig +++ b/src/File.zig @@ -589,9 +589,7 @@ test "the ASCII run in fitEnd cuts where the grapheme walk would" { } } -pub fn lineCount(content: []const u8) usize { - return std.mem.count(u8, content, "\n") + 1; -} +pub const lineCount = modal.cursorLineCount; // Content changes invalidate this lazily rebuilt byte-offset index. pub fn lineIndex(gpa: std.mem.Allocator, f: *State) ![]const usize { diff --git a/src/edit.zig b/src/edit.zig index a7449dcf..14060f45 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -73,16 +73,15 @@ fn selText(p: *Pardes, t: *Text) []const u8 { /// `p` / `P` / `R` from the register the command names: this range's value /// of it. The clipboard's is asked of the shell and pasted when it answers, /// once, at the primary. -pub fn pasteRegister(p: *Pardes, t: *Text, how: enum { after, before, replace }, count: usize) void { +/// Where a paste goes: after the selection, before it, or over it. +pub const Paste = enum { after, before, replace }; + +pub fn pasteRegister(p: *Pardes, t: *Text, how: Paste, count: usize) void { const name: u21 = if (p.register != 0) p.register else Registers.default; if (name == '+' or name == '*') { if (!normal.multiOnce(p)) return; const pane = t.pane() orelse return; - return clipRequest(p, p.paneIdOf(pane) orelse return, switch (how) { - .after => .after, - .before => .before, - .replace => .replace, - }); + return clipRequest(p, p.paneIdOf(pane) orelse return, how); } const y = registerValue(p, t, name) orelse return; switch (how) { @@ -96,10 +95,10 @@ pub fn pasteRegister(p: *Pardes, t: *Text, how: enum { after, before, replace }, pub const ClipRequest = struct { pane: usize, serial: u32, - mode: enum { after, before, replace }, + mode: Paste, }; -pub fn clipRequest(p: *Pardes, id: usize, mode: @FieldType(ClipRequest, "mode")) void { +pub fn clipRequest(p: *Pardes, id: usize, mode: Paste) void { const pane = p.panes[id] orelse return; p.clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode }; p.emit(.read_clipboard); diff --git a/src/modal.zig b/src/modal.zig index 8a611691..9ad30d13 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -1433,11 +1433,9 @@ pub const WordTarget = enum { next_word_start, next_word_end, prev_word_start, - prev_word_end, next_long_word_start, next_long_word_end, prev_long_word_start, - prev_long_word_end, }; // helix categorize_char: Eol is its OWN category, distinct from Whitespace — @@ -1473,9 +1471,9 @@ 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 => prev != next and (next == .eol or !isWordWhitespace(next)), + .next_word_start => 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_start => 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), }; } @@ -1529,10 +1527,7 @@ pub fn jumpWords(text: []const u8, cursor: usize, start: usize, end: usize, out: /// 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 = switch (target) { - .prev_word_start, .prev_word_end, .prev_long_word_start, .prev_long_word_end => true, - else => false, - }; + const is_prev = target == .prev_word_start or target == .prev_long_word_start; 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) diff --git a/src/normal.zig b/src/normal.zig index ee39531d..48ac636c 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -94,11 +94,7 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: m var hay_all = text; if (for (pat) |c| { if (std.ascii.isUpper(c)) break false; - } else true) { - const low = p.scratch.allocator().dupe(u8, text) catch return; - for (low) |*c| c.* = std.ascii.toLower(c.*); - hay_all = low; - } + } else true) hay_all = std.ascii.allocLowerString(p.scratch.allocator(), text) catch return; for (snap) |r| { const from = @min(r.anchor, r.head); const to = @min(@max(r.anchor, r.head), text.len); @@ -162,11 +158,7 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Di var hay = text; if (for (pat) |c| { if (std.ascii.isUpper(c)) break false; - } else true) { - const lower = p.scratch.allocator().dupe(u8, text) catch return; - for (lower) |*c| c.* = std.ascii.toLower(c.*); - hay = lower; - } + } else true) hay = std.ascii.allocLowerString(p.scratch.allocator(), text) catch return; for (0..count) |_| { var ranges: [Text.max_selections]modal.Selection = undefined; const got = t.ranges(text, 0, &ranges); @@ -175,9 +167,9 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Di const to = @max(old.anchor, old.head); var wrapped = false; const found = (if (direction == .forward) blk: { - if (tryFind(&re, hay, to, hay.len)) |h| break :blk h; + if (re.find(hay, to, hay.len)) |h| break :blk h; wrapped = true; - break :blk tryFind(&re, hay, 0, hay.len); + break :blk re.find(hay, 0, hay.len); } else blk: { if (lastMatch(&re, hay, 0, from)) |h| break :blk h; wrapped = true; @@ -203,15 +195,11 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, direction: modal.Normal.Di t.show(); } -fn tryFind(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { - return re.find(hay, @min(from, hay.len), to); -} - fn lastMatch(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match { var last: ?regexp.Regex.Match = null; var at = from; while (at <= to) { - const found = tryFind(re, hay, at, to) orelse break; + const found = re.find(hay, at, to) orelse break; last = found; at = if (found.end > found.start) found.end else modal.nextGrapheme(hay, found.end); if (at <= found.start) break; |
