diff options
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). |
