summaryrefslogtreecommitdiff
path: root/src/normal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:31:19 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:16:28 -0300
commit2504b38647653db091aa7709afcea0dbe75f7a95 (patch)
tree2fefb992a86d2432c00ab4b431f65b649421a0dd /src/normal.zig
parent2aa1801dbad2a26348aef085d9dee8096f8d2eb3 (diff)
downloadpardes-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
Diffstat (limited to 'src/normal.zig')
-rw-r--r--src/normal.zig22
1 files changed, 5 insertions, 17 deletions
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;