diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:13:36 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:16:28 -0300 |
| commit | 3671eb9eafc19549bb94fe839e944e18707316e1 (patch) | |
| tree | b7220666204dc3df37d963a2b9884c84b9f714af /src/modal.zig | |
| parent | 71df23d63da76c6aedf91a2458d3057ed6da9a35 (diff) | |
| download | pardes-3671eb9eafc19549bb94fe839e944e18707316e1.tar.gz pardes-3671eb9eafc19549bb94fe839e944e18707316e1.zip | |
modal, edit: advanceBy takes insertedEnd's body (the last newline and a count, not a byte loop) and insertedEnd goes, and a typed run's end is computed once, for the splice and the cursor both
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.zig | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/src/modal.zig b/src/modal.zig index 71a9ddcb..0054afeb 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -1196,15 +1196,8 @@ pub fn pasteLineBelow(alloc: std.mem.Allocator, content: []const u8, row: usize, // the cursor position AFTER `text` inserted at `c` (one past its last char). pub fn advanceBy(c: Cursor, text: []const u8) Cursor { - var r = c.row; - var col = c.col; - for (text) |ch| { - if (ch == '\n') { - r += 1; - col = 0; - } else col += 1; - } - return .{ .row = r, .col = col }; + const nl = std.mem.lastIndexOfScalar(u8, text, '\n') orelse return .{ .row = c.row, .col = c.col + text.len }; + return .{ .row = c.row + std.mem.count(u8, text, "\n"), .col = text.len - nl - 1 }; } // replace the inclusive char range [a, b] with `text` (R replace-with-yank). |
