From 3671eb9eafc19549bb94fe839e944e18707316e1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:13:36 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/modal.zig | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/modal.zig') 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). -- cgit v1.3