termio: clear selection

This commit is contained in:
Mitchell Hashimoto
2022-11-04 20:47:01 -07:00
parent f1d2df1a54
commit 1a7b9f7465
4 changed files with 39 additions and 9 deletions

View File

@ -810,7 +810,13 @@ fn charCallback(window: glfw.Window, codepoint: u21) void {
return; return;
} }
// Anytime is character is created, we have to clear the selection // Anytime a char is created, we have to clear the selection if there is one.
_ = win.io_thread.mailbox.push(.{
.clear_selection = {},
}, .{ .forever = {} });
// TODO: the stuff below goes away with IO thread
if (win.terminal.selection != null) { if (win.terminal.selection != null) {
win.terminal.selection = null; win.terminal.selection = null;
win.queueRender() catch |err| win.queueRender() catch |err|

View File

@ -188,6 +188,17 @@ pub fn resize(
} }
} }
pub fn clearSelection(self: *Exec) !void {
// We don't need a lock to read because nothing else can possibly write
// as we're looking at this.
if (self.terminal.selection != null) {
// We need to lock so we can write because other things might be reading.
self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock();
self.terminal.selection = null;
}
}
const ThreadData = struct { const ThreadData = struct {
/// Allocator used for the event data /// Allocator used for the event data
alloc: Allocator, alloc: Allocator,

View File

@ -150,15 +150,28 @@ fn drainMailbox(self: *Thread) !void {
// This holds the mailbox lock for the duration of the drain. The // This holds the mailbox lock for the duration of the drain. The
// expectation is that all our message handlers will be non-blocking // expectation is that all our message handlers will be non-blocking
// ENOUGH to not mess up throughput on producers. // ENOUGH to not mess up throughput on producers.
var drain = self.mailbox.drain(); var redraw: bool = false;
defer drain.deinit(); {
var drain = self.mailbox.drain();
defer drain.deinit();
while (drain.next()) |message| { while (drain.next()) |message| {
log.debug("mailbox message={}", .{message}); // If we have a message we always redraw
switch (message) { redraw = true;
.resize => |v| try self.impl.resize(v.grid_size, v.screen_size),
log.debug("mailbox message={}", .{message});
switch (message) {
.resize => |v| try self.impl.resize(v.grid_size, v.screen_size),
.clear_selection => try self.impl.clearSelection(),
}
} }
} }
// Trigger a redraw after we've drained so we don't waste cyces
// messaging a redraw.
if (redraw) {
try self.impl.renderer_wakeup.send();
}
} }
fn wakeupCallback(h: *libuv.Async) void { fn wakeupCallback(h: *libuv.Async) void {

View File

@ -9,8 +9,8 @@ pub const IO = union(enum) {
screen_size: renderer.ScreenSize, screen_size: renderer.ScreenSize,
}, },
// /// Clear the selection /// Clear the selection
// clear_selection: void, clear_selection: void,
// //
// /// Scroll the viewport // /// Scroll the viewport
// scroll_viewport: terminal.Terminal.ScrollViewport, // scroll_viewport: terminal.Terminal.ScrollViewport,