summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mouse.zig44
-rw-r--r--src/ninep/events.zig2
-rw-r--r--src/pardes.zig13
3 files changed, 16 insertions, 43 deletions
diff --git a/src/mouse.zig b/src/mouse.zig
index 02e3b6a5..1292c06f 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -28,7 +28,6 @@ const BOX_H = pardes.BOX_H;
const TAG_GAP = pardes.TAG_GAP;
const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
const Builtin = pardes.Builtin;
-const wordAtCol = pardes.wordAtCol;
const Mouse = pardes.Mouse;
const sel_slot = pardes.sel_slot;
const Pardes = pardes.Pardes;
@@ -134,7 +133,8 @@ fn headerSweepRun(p: *Pardes, sweep: HeaderSweep) void {
const at = swept.lo - start;
const focused = p.header_focus and p.header_column == column;
const on = if (focused) tagline.headerSelection(t, text, line) else null;
- break :click if (on) |sp| (if (at >= sp.lo and at < sp.hi) bar[sp.lo..sp.hi] else wordAtCol(bar, at)) else wordAtCol(bar, at);
+ const under = if (pardes.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;
tagline.exitHeader(p);
@@ -306,7 +306,7 @@ pub fn bodyHitForPane(p: *const Pardes, id: usize, supplied: Mouse.BodyHit, clam
mapped_hit.pixel_x = std.math.clamp(mapped_hit.pixel_x, x0, @max(x0, x1 - 0.001));
mapped_hit.pixel_y = std.math.clamp(mapped_hit.pixel_y, y0, @max(y0, y1 - 0.001));
}
- return p.reprojectBodyHit(mapped_hit);
+ return Layer.bodyAgain(mapped_hit);
}
fn bodyPlace(hit: ?Mouse.BodyHit, pane: *const Pane) ?Layer.Place {
@@ -612,22 +612,16 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
}
}
if (p.header_drag and m.button == config.select_button and (m.kind == .drag or m.kind == .release)) {
- const t = tagline.focusedHeader(p) orelse {
+ if (tagline.focusedHeader(p) == null) {
p.header_drag = false;
return;
- };
- const x = if (p.header_column) |c| p.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
- const text = edit.flatSurface(p, t) catch return;
- // `row` is the header's row on screen, `line` the line of its text
- // shown there.
- const base = if (p.header_column != null) p.topBarHeight() else 0;
- const row: u16 = @intCast(@min(mrow -| base, (if (p.header_column != null) p.columnBarHeight() else p.topBarHeight()) -| 1));
- const line: u16 = @intCast(@min(row + p.header_top, modal.lineCount(text) -| 1));
- const bar = modal.lineSlice(text, line);
- const at = @min(bar.len, panes.File.rawAtDisplay(bar, (Layer.columnAt(p, if (p.header_column != null) .column else .workspace, p.header_column orelse 0, p.pointer_tag_hit, p.header_drag, row) orelse (mcol -| x)) + p.header_scroll));
- // the anchor stays where the press put it
- t.cur_row = line;
- t.cur_col = @intCast(at);
+ }
+ // Held to the focused header's rows and text; the anchor stays
+ // where the press put it.
+ const point = headerPoint(p, p.header_column, mcol, mrow, true) orelse return;
+ const t = point.t;
+ t.cur_row = point.line;
+ t.cur_col = @intCast(point.at - modal.lineStartOffset(point.text, point.line));
t.vsel.active = t.vsel.row != t.cur_row or t.vsel.col != t.cur_col;
if (m.kind == .release) p.header_drag = false;
return;
@@ -902,7 +896,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
/// Index of the pane pair in column `c` whose seam (see seamRowOf) is screen
/// row `mrow`. Out-of-range columns simply have no seam.
-pub fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize {
+fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize {
if (c >= p.ncol) return null;
for (0..p.col_n[c] -| 1) |k| if (mrow == seamRowOf(p, c, k)) return k;
return null;
@@ -996,18 +990,6 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo
}
}
-fn reportGesture(
- p: *Pardes,
- id: usize,
- cmd: Builtin,
- text: []const u8,
- on_tag: bool,
- operand: exec.PointerOperand,
- chord_arg: ?[]const u8,
-) bool {
- return reportRange(p, id, cmd, text, on_tag, gestureRange(p, id, text, on_tag, operand), chord_arg);
-}
-
/// Whether a script reads pane `id`'s events, and so takes its looks and
/// execs: the 9P server's, the authority's alone (a replica has its
/// answer, `tape.authority`).
@@ -1122,7 +1104,7 @@ pub fn dispatchPointerBuiltin(
// A click that takes no text does nothing, and tells an event reader
// nothing, as acme's look3 and execute return on an empty expansion.
const operand = text orelse return;
- if (gesture) |g| if (reportGesture(p, id, cmd, operand, g.on_tag, g.operand, arg)) return;
+ if (gesture) |g| if (reportRange(p, id, cmd, operand, g.on_tag, gestureRange(p, id, operand, g.on_tag, g.operand), arg)) return;
// B2 anywhere on a query pane's line 1 is the line: run again, whatever
// word of it was clicked (Query.zig).
if (gesture) |g| if (!g.on_tag and g.operand.row == 0 and cmd == config.exec_cmd) if (p.panes[id]) |pane| if (pane.query) |q| {
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 1a0e9a86..088520e3 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -758,7 +758,7 @@ pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply {
// it takes it. One that came from a write to exec (`F`) was
// never a click, and runs as the command it was.
// The chorded exec a reader was told of runs with its argument
- // (mouse.reportGesture), when it is that range written back.
+ // (mouse.reportRange), when it is that range written back.
.body_exec, .tag_exec => {
const pf = &pane.fs;
// The two records that follow a chorded exec (its argument
diff --git a/src/pardes.zig b/src/pardes.zig
index f1a804fc..bd79741f 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -2637,6 +2637,8 @@ comptime {
const WordBounds = struct { lo: usize, hi: usize };
+/// The space-delimited word covering `col` in `str` (a header's click and
+/// hover), null on a space or past the end.
pub fn wordBoundsAtCol(str: []const u8, col: usize) ?WordBounds {
if (col >= str.len or str[col] == ' ') return null;
var lo: usize = col;
@@ -2646,12 +2648,6 @@ pub fn wordBoundsAtCol(str: []const u8, col: usize) ?WordBounds {
return .{ .lo = lo, .hi = hi };
}
-/// the whitespace-delimited word covering `col` in `str` (topbar dispatch)
-pub fn wordAtCol(str: []const u8, col: usize) []const u8 {
- const bounds = wordBoundsAtCol(str, col) orelse return "";
- return str[bounds.lo..bounds.hi];
-}
-
/// `a` IS `b` or lives under it — how Grep drops a pane's directory when
/// another pane's directory already covers it
pub fn pathUnder(a: []const u8, b: []const u8) bool {
@@ -7561,11 +7557,6 @@ pub const Pardes = struct {
return layer.capacity(p.row_metrics);
}
- /// A frontend's body hit, resolved on the place it carries.
- pub fn reprojectBodyHit(_: *const Pardes, body_hit: Mouse.BodyHit) ?Mouse.BodyHit {
- return Layer.bodyAgain(body_hit);
- }
-
// ---- render: build the canonical surface (draw.zig) ----
pub const render = draw.render;