Skip to content

Commit

Permalink
surface: selection region keeps up with selection scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
moni-dz committed Jan 22, 2025
1 parent 0c52491 commit d9e0481
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,6 @@ pub fn cursorPosCallback(
// Only send a message when outside the viewport and
// selection scrolling is not currently active.
if ((pos.y <= 1 or pos.y > max_y - 1) and !self.io_thread.scroll_active) {
// TODO: the selection region ideally should keep up with this
self.io.queueMessage(.{ .selection_scroll = true }, .locked);
}

Expand Down Expand Up @@ -3593,7 +3592,7 @@ fn dragLeftClickTriple(
try self.setSelection(sel);
}

fn dragLeftClickSingle(
pub fn dragLeftClickSingle(
self: *Surface,
drag_pin: terminal.Pin,
xpos: f64,
Expand Down
17 changes: 17 additions & 0 deletions src/termio/Thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,27 @@ fn selectionScrollCallback(
const cb = cb_ orelse return .disarm;
const surface = cb.io.surface_mailbox.surface;
const pos = try surface.rt_surface.getCursorPos();
const pos_vp = surface.posToViewport(pos.x, pos.y);
const screen = &cb.io.renderer_state.terminal.screen;
const delta: isize = if (pos.y < 0) -1 else 1;

try cb.io.terminal.scrollViewport(.{ .delta = delta });

// Always the case, but doesn't hurt to check
if (surface.mouse.left_click_count == 1) {
const pin = screen.pages.pin(.{
.viewport = .{
.x = pos_vp.x,
.y = pos_vp.y,
},
}) orelse {
if (comptime std.debug.runtime_safety) unreachable;
return .rearm;
};

surface.dragLeftClickSingle(pin, pos.x) catch {};
}

// Notify the renderer that it should repaint immediately after scrolling
cb.io.renderer_wakeup.notify() catch {};

Expand Down

0 comments on commit d9e0481

Please sign in to comment.