diff options
Diffstat (limited to 'core/mouse.zig')
| -rw-r--r-- | core/mouse.zig | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/core/mouse.zig b/core/mouse.zig index dc730923..f628bbc3 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -337,8 +337,13 @@ fn programMouse(p: *Pardes, m: Mouse) bool { const bytes = panes.Term.mouse(pane.terminal.?, &pane.term_mouse, &buf, .motion, null, mods, cell.col, cell.row, false); if (bytes.len > 0) p.emitWrite(id, bytes); // Under 1003 the move is the program's; below that pardes - // hovers as ever. - return panes.Term.modes(pane.terminal).all_motion; + // hovers as ever. A link (OSC 8) is pardes's under any mode + // (B3 looks at its URI): over one pardes hovers too, so its + // label shows what a look takes; off it, the hover goes. + if (!panes.Term.modes(pane.terminal).all_motion) return false; + if (panes.Term.link(pane.terminal.?, @as(i32, @intCast(pane.termTop())) + cell.row, @intCast(cell.col), false) != null) return false; + look.invalidateLookHover(p, id); + return true; }, } } @@ -2299,3 +2304,37 @@ test "the act step and the rows under the mouse (UX DESIGN O2): B2 on an act's w try std.testing.expect(pardes.Pick.live(p) == pk); try std.testing.expect(std.mem.endsWith(u8, p.registers.text(p.gpa, pardes.Registers.default).?, "one.zig:2\n")); } + +test "under any-event tracking (1003) a move over a link (OSC 8) is pardes's hover too, so its label shows what B3 looks at; off it the hover goes, every move the program's" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .cols = 60, .rows = 16, .tty_only = true }); + defer p.deinit(); + var frame = std.heap.ArenaAllocator.init(gpa); + defer frame.deinit(); + _ = try p.render(frame.allocator()); + var out: [4096]u8 = undefined; + const pane = p.panes[0].?; + try std.testing.expectEqual(.tty, pane.body.mode); + // codex's modes, then `see ` and a link labelled `the docs` on the grid's first row. + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006hsee \x1b]8;;https://ziglang.org\x1b\\the docs\x1b]8;;\x1b\\ here" } }); + _ = pardes.test_api.ptyBytes(p, 0, &out); + const r = p.view().rects[0]; + const x0 = r.x + config.GUTTER; + const y = p.bodyTop(pane, r); + const hoverAt = struct { + fn f(pp: *Pardes, o: []u8, c: u16, rw: u16) ![]const u8 { + pp.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = c, .row = rw } }); + const heard = pardes.test_api.ptyBytes(pp, 0, o); + for (0..config.look_preview_delay_frames) |_| pp.update(.tick); + return heard; + } + }.f; + try std.testing.expectEqualStrings("\x1b[<35;7;1M", try hoverAt(p, &out, x0 + 6, y)); + const shown = (p.look_hover_preview orelse return error.NoHoverOverTheLink).sel.?; + try std.testing.expectEqual(@as(i32, 4), shown.c0); + try std.testing.expectEqual(@as(i32, 11), shown.c1); + // Off it: the program's move alone, pardes's hover gone, none started. + try std.testing.expectEqualStrings("\x1b[<35;2;1M", try hoverAt(p, &out, x0 + 1, y)); + try std.testing.expect(p.look_hover_preview == null and p.look_hover_wait == null); +} |
