diff options
Diffstat (limited to 'src/edit.zig')
| -rw-r--r-- | src/edit.zig | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/edit.zig b/src/edit.zig index a7b9bb7a..d4795c94 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -28,8 +28,7 @@ const sel_slot = pardes.sel_slot; const Effect = pardes.Effect; const Pardes = pardes.Pardes; const Registers = pardes.Registers; -/// What an edit fails with, memory or a terminal's rows not read -/// (terminal.shellRows); the key that ran it says so (`edit: out of memory`). +/// An edit's failure, memory or a terminal's rows not read, said by its key. pub const Error = error{ OutOfMemory, WriteFailed, UnknownPoint }; /// Write `text` as this range's value of the register the running command @@ -1092,7 +1091,7 @@ pub fn normalDelete(p: *Pardes, t: *Text, yank: bool) Error!void { t.vsel.active = false; return; }; - const new = deleteSelection(p, t, eb) orelse return; + const new = try deleteSelection(p, t, eb); setEditText(p, t, new); t.cur_row = b.lo_row; t.cur_col = b.lo_col; @@ -1203,7 +1202,7 @@ pub fn normalChange(p: *Pardes, t: *Text) Error!void { } setYank(p, try vselText(p, t)); pushUndo(p, t); - const new = deleteSelection(p, t, eb) orelse return; + const new = try deleteSelection(p, t, eb); setEditText(p, t, new); t.cur_row = b.lo_row; t.cur_col = b.lo_col; @@ -1224,14 +1223,10 @@ pub fn normalChange(p: *Pardes, t: *Text) Error!void { t.normal.clear(); } -/// `eb` without the primary range, or null (the selection dropped) when -/// there is no memory for it. -fn deleteSelection(p: *Pardes, t: *Text, eb: panes.EditText) ?[]u8 { +/// `eb` without the primary range. +fn deleteSelection(p: *Pardes, t: *Text, eb: panes.EditText) Error![]u8 { const r = t.primaryRange(eb.text, eb.row0); - return modal.spliceAlloc(p.gpa, eb.text, @min(r.anchor, r.head), @max(r.anchor, r.head), "") catch { - t.vsel.active = false; - return null; - }; + return modal.spliceAlloc(p.gpa, eb.text, @min(r.anchor, r.head), @max(r.anchor, r.head), ""); } /// the rows an op's selection spans, absolute (what editText must cover) @@ -1279,8 +1274,7 @@ pub fn normalReplaceChar(p: *Pardes, t: *Text, ch: u21) Error!void { var at = lo; while (at < hi) : (graphemes += 1) at = modal.nextGrapheme(eb.text, at); var encoded: [4]u8 = undefined; - if (!std.unicode.utf8ValidCodepoint(ch)) return; // a surrogate half types nothing - const encoded_len = std.unicode.utf8Encode(ch, &encoded) catch unreachable; // a valid code point, checked above + const encoded_len = std.unicode.utf8Encode(ch, &encoded) catch return; // a surrogate half types nothing const rep = try p.scratch.allocator().alloc(u8, graphemes * encoded_len); for (0..graphemes) |i| @memcpy(rep[i * encoded_len ..][0..encoded_len], encoded[0..encoded_len]); pushUndo(p, t); @@ -1609,7 +1603,7 @@ pub fn normalToggleComment(p: *Pardes, t: *Text) Error!void { next = @max(next, end); } const file = if (t.what != .body) null else if (t.pane()) |pane| pane.file else null; - const ext = if (file) |f| std.fs.path.extension(f.path) else ""; + const ext = if (file) |f| std.Io.Dir.path.extension(f.path) else ""; var token: []const u8 = config.comment_token_default; lang: for (config.comment_tokens) |row| { for (row.exts) |e| if (std.ascii.eqlIgnoreCase(ext, e)) { |
