diff options
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/look.zig b/src/look.zig index 4ee5a638..39f7420e 100644 --- a/src/look.zig +++ b/src/look.zig @@ -934,6 +934,12 @@ fn noteLookHover(p: *Pardes, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_h if (p.look_hover_wait) |waiting| if (waiting.col == col and waiting.row == row and waiting.pane == id and waiting.serial == pane.serial and mouse.sameBodyCell(waiting.body_hit, body_hit) and tag_layer.sameCell(waiting.tag_hit, tag_hit)) return; + // Found nothing to open here a moment ago: the pointer resting on it + // does not start another wait (and another frame) every frame. + if (p.look_hover_refused) |refused| + if (refused.col == col and refused.row == row and refused.pane == id and refused.serial == pane.serial and mouse.sameBodyCell(refused.body_hit, body_hit) and tag_layer.sameCell(refused.tag_hit, tag_hit)) return; + p.look_hover_refused = null; + cancelLookHover(p); p.look_hover_wait = .{ .col = col, .row = row, .pane = id, .serial = pane.serial, .body_hit = body_hit, .tag_hit = tag_hit }; } @@ -958,8 +964,10 @@ pub fn advanceLookHover(p: *Pardes) void { if (waiting.frames < delay) return; const pane = p.panes[waiting.pane] orelse return cancelLookHover(p); if (pane.serial != waiting.serial) return cancelLookHover(p); - const pointed = edit.pointerTextSelection(p, waiting.pane, waiting.col, waiting.row, waiting.body_hit, waiting.tag_hit) orelse + const pointed = edit.pointerTextSelection(p, waiting.pane, waiting.col, waiting.row, waiting.body_hit, waiting.tag_hit) orelse { + p.look_hover_refused = waiting.*; return cancelLookHover(p); + }; if (comptime pdf_enabled) if (!pointed.on_tag and panes.Pdf.paneNativeReady(p, pane)) { const probe = panes.Pdf.probeAt(p, pane, waiting.col, waiting.row) orelse return cancelLookHover(p); @@ -976,7 +984,10 @@ pub fn advanceLookHover(p: *Pardes) void { return; }; const operand = exec.pointerOperand(p, pane, pointed.sel); - if (operand.text == null or operand.text.?.len == 0) return cancelLookHover(p); + if (operand.text == null or operand.text.?.len == 0) { + p.look_hover_refused = waiting.*; + return cancelLookHover(p); + } var preview = operand.preview; if (preview) |*sel| sel.state = .done; p.look_hover_preview = .{ @@ -1727,3 +1738,21 @@ test "Look ignores missing and out of bounds pane addresses" { try std.testing.expect(pane.body.vsel.active); // a miss changes nothing, the selection included } } + +test "a pointer resting where a look-hover found nothing does not wake the core every frame" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); + defer p.deinit(); + _ = try p.setTestFile(" \n" ** 30); + p.sync(); + const r = p.rects[p.active]; + // Resting on blanks in the body: a wait, then nothing to open. + p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = r.x + 20, .row = r.y + 5 } }); + var frames: usize = 0; + while (p.nextWake() != null and frames < 20) : (frames += 1) { + p.update(.tick); + // What a shell's present does after every frame. + p.acknowledgePanelPresentation(&.{}); + } + try std.testing.expect(frames < 20); + try std.testing.expect(p.look_hover_wait == null and p.look_hover_preview == null); +} |
