diff options
Diffstat (limited to 'src/mouse.zig')
| -rw-r--r-- | src/mouse.zig | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/mouse.zig b/src/mouse.zig index 6e8c1719..8e50478f 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -116,9 +116,9 @@ fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?s /// header's selection when it is on that; a sweep runs what it swept. fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { const v = p.view(); - const column = sweep.column(p) catch return; + const column = sweep.column(p) catch return; // error.Gone: its column closed under the sweep const t = if (column) |c| &v.col_tags[c] else &p.global_tag; - const text = edit.flatSurface(p, t) catch return; + const text = edit.flatSurface(p, t) catch |err| return p.reportError(v.active, "edit", err); const swept = sweep.span(text.len); const selected = if (swept.lo < swept.hi) text[swept.lo..swept.hi] else click: { const line = std.mem.count(u8, text[0..swept.lo], "\n"); @@ -130,7 +130,7 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void { const under = if (tagline.wordBoundsAtCol(bar, at)) |b| bar[b.lo..b.hi] else ""; break :click if (on) |sp| (if (at >= sp.lo and at < sp.hi) bar[sp.lo..sp.hi] else under) else under; }; - const word = p.scratch.allocator().dupe(u8, selected) catch return; + const word = p.scratch.allocator().dupe(u8, selected) catch |err| return p.reportError(v.active, "edit", err); tagline.exitHeader(p); // A column tag's command acts on that column, empty or not. p.exec_column = column; @@ -848,7 +848,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { // acme 1-2 / 1-3: the execute (Cut) or look (Paste) button // tapped while the select button holds a selection drag if (v.drag == .select and v.drag.select.button == config.select_button) { - chordCutPaste(p, m.button == config.exec_button); + chordCutPaste(p, m.button == config.exec_button) catch |err| p.reportError(v.active, "edit", err); return; } // acme 2-3 / 3-2: tapping the OTHER of execute/look during @@ -1124,7 +1124,7 @@ fn mirrorTtySelection(p: *Pardes, pane: *Pane) void { if (rows.len == 0) return; const forward = gesture.r1 > gesture.r0 or (gesture.r1 == gesture.r0 and gesture.c1 >= gesture.c0); const endpoint = rows[if (forward) rows.len - 1 else 0]; - const body = body_layer.bodyText(p.scratch.allocator(), pane) catch return; + const body = body_layer.bodyText(p.scratch.allocator(), pane) catch |err| return p.reportError(p.view().active, "select", err); const line = modal.lineSlice(body, @intCast(@max(0, endpoint.row - panes.terminal.gridOffset(pane)))); const byte = if (forward) modal.prevGrapheme(line, @min(endpoint.hi, line.len)) else endpoint.lo; pane.body.cur_row = pane.surfRow(endpoint.row); @@ -1159,7 +1159,7 @@ fn doubleClick(p: *Pardes, id: usize, t: *panes.Text, on_tag: bool, row: i32, co const c = prev orelse return; if (c.id != id or c.on_tag != on_tag or c.row != row or c.col != col or now - c.ms > 500) return; v.last_click = null; - const text = edit.flatSurface(p, t) catch return; + const text = edit.flatSurface(p, t) catch |err| return p.reportError(v.active, "edit", err); const q = modal.offsetAt(text, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) }); const r = edit.doubleClickRange(text, q); if (r[1] <= r[0]) return; @@ -1260,7 +1260,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { } return; } - if (dragged and s.anchor == null) edit.capturePointerSelection(p, pane, sel_slot) catch {}; + if (dragged and s.anchor == null) edit.capturePointerSelection(p, pane, sel_slot) catch |err| p.reportError(s.id, "select", err); if (dragged and pane.body.mode == .tty) mirrorTtySelection(p, pane); const body_vis = sl.r1 - @as(i32, pane.tag_rows); if (body_vis >= 0 and pane.body.mode != .tty) { @@ -1304,7 +1304,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { if (line >= 0) { pane.sel[b].state = .none; var buf: [48]u8 = undefined; - const target = std.fmt.bufPrint(&buf, "@p{d}:{d}", .{ pane.serial, @as(usize, @intCast(line)) + 1 }) catch return; + const target = std.fmt.bufPrint(&buf, "@p{d}:{d}", .{ pane.serial, @as(usize, @intCast(line)) + 1 }) catch unreachable; // 33 bytes at most exec.runBuiltin(p, config.look_cmd, s.id, "", target); return; } @@ -1357,7 +1357,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void { } } -fn chordCutPaste(p: *Pardes, cut: bool) void { +fn chordCutPaste(p: *Pardes, cut: bool) edit.Error!void { const s = &p.view().drag.select; const pane = p.panes[s.id] orelse return; if (@min(pane.sel[sel_slot].r0, pane.sel[sel_slot].r1) < pane.tag_rows) { @@ -1385,10 +1385,10 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { t.nsel = 0; } if (cut) { - if (t.vsel.active) edit.normalDelete(p, t, true); + if (t.vsel.active) try edit.normalDelete(p, t, true); } else if (t.vsel.active) { - edit.chordReplace(p, t); - } else edit.pasteText(p, t, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1); + try edit.chordReplace(p, t); + } else try edit.pasteText(p, t, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1); return; } if (pane.body.mode == .tty) { @@ -1439,9 +1439,9 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { pane.body.nsel = 0; } if (cut) { - if (pane.body.vsel.active) edit.normalDelete(p, &pane.body, true); + if (pane.body.vsel.active) try edit.normalDelete(p, &pane.body, true); } else if (pane.body.vsel.active) { - edit.chordReplace(p, &pane.body); + try edit.chordReplace(p, &pane.body); } else if (pane.file) |*f| { // bare cursor: splice the register in literally (no linewise // magic) so a paste right after a cut restores the text exactly @@ -1449,7 +1449,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { if (y.len == 0) return; const at = modal.Cursor{ .row = @intCast(@max(0, pane.body.cur_row)), .col = @intCast(@max(0, pane.body.cur_col)) }; edit.pushUndo(p, &pane.body); - const new = modal.insertAt(p.gpa, f.content, at, y) catch return; + const new = try modal.insertAt(p.gpa, f.content, at, y); panes.File.setContent(p, f, new); pane.body.vsel = .{ .active = modal.nextGrapheme(y, 0) < y.len, .row = @intCast(at.row), .col = @intCast(at.col), .explicit = false }; const end = modal.advanceBy(at, y); @@ -1464,7 +1464,7 @@ fn chordCutPaste(p: *Pardes, cut: bool) void { pane.body.cur_pinned = true; pane.body.sticky_col = -1; pane.ensureCursorVisible(); - } else edit.pasteText(p, &pane.body, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1); + } else try edit.pasteText(p, &pane.body, p.registers.text(p.gpa, pardes.Registers.default) orelse return, true, 1); } test "plain left click clears explicit modal selection" { |
