summaryrefslogtreecommitdiff
path: root/src/edit.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:56:32 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commitd78fa4f9d90437dac60d9150e3a6eca868895856 (patch)
tree69e8cb2f47960307bc39296b76fc3b6fdd64a647 /src/edit.zig
parent34a80c9f9b81b64d095a1d5123ae74a52bef4749 (diff)
downloadpardes-d78fa4f9d90437dac60d9150e3a6eca868895856.tar.gz
pardes-d78fa4f9d90437dac60d9150e3a6eca868895856.zip
idioms #18, std.Io's names and fewer forms: the core's path functions are std.Io.Dir.path's and max_path_bytes std.Io.Dir's (std.fs's are deprecated aliases), pinOf takes the *const PageList it is always given, normal's @hasDecl guard goes (@field says the same), deleteSelection returns edit.Error, and a Look miss too long for its buffer is said cut where it said `no match`
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/edit.zig')
-rw-r--r--src/edit.zig22
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)) {