From 4faa1b601a3bb589f1c478fda486f7871ee55a2b Mon Sep 17 00:00:00 2001 From: shadow cat Date: Sat, 22 Nov 2025 15:33:36 -0500 Subject: [PATCH] word selection --- iris | 2 +- src/bin/client/main.rs | 15 ++++++++++----- src/bin/client/ui/misc.rs | 7 ++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/iris b/iris index fc89826..c24c517 160000 --- a/iris +++ b/iris @@ -1 +1 @@ -Subproject commit fc8982679440995d4609f67ee7e01bada2eb9027 +Subproject commit c24c517c60cdb677daf09541366b90d2b8be92aa diff --git a/src/bin/client/main.rs b/src/bin/client/main.rs index f571703..1ce49bb 100644 --- a/src/bin/client/main.rs +++ b/src/bin/client/main.rs @@ -15,7 +15,7 @@ use openworm::{ rsc::DataDir, }; use render::Renderer; -use std::sync::Arc; +use std::{sync::Arc, time::Instant}; use winit::{ event::{Ime, WindowEvent}, event_loop::{ActiveEventLoop, EventLoopProxy}, @@ -53,6 +53,7 @@ pub struct Client { handle: AppHandle, error: Option>, ime: usize, + last_click: Instant, } impl Client { @@ -79,6 +80,7 @@ impl Client { clipboard: Clipboard::new().unwrap(), error: None, ime: 0, + last_click: Instant::now(), }; ui::init(&mut s); s @@ -118,10 +120,8 @@ impl Client { pub fn window_event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) { let input_changed = self.input.event(&event); let cursor_state = self.cursor_state().clone(); - if let Some(focus) = &self.focus - && cursor_state.buttons.left.is_start() - { - self.ui.text(focus).deselect(); + let old = self.focus.clone(); + if cursor_state.buttons.left.is_start() { self.focus = None; } if input_changed { @@ -129,6 +129,11 @@ impl Client { self.run_sensors(&cursor_state, window_size); self.ui.run_sensors(&cursor_state, window_size); } + if old != self.focus + && let Some(old) = old + { + self.ui.text(&old).deselect(); + } match event { WindowEvent::CloseRequested => event_loop.exit(), WindowEvent::RedrawRequested => { diff --git a/src/bin/client/ui/misc.rs b/src/bin/client/ui/misc.rs index daf438b..542ded1 100644 --- a/src/bin/client/ui/misc.rs +++ b/src/bin/client/ui/misc.rs @@ -1,3 +1,5 @@ +use std::time::{Duration, Instant}; + use super::*; pub fn error(ui: &mut Ui, msg: &str) -> WidgetId { @@ -49,10 +51,13 @@ impl WidgetAttr for Selectable { } fn select(id: WidgetId, client: &mut Client, data: CursorData) { + let now = Instant::now(); + let recent = (now - client.last_click) < Duration::from_millis(300); + client.last_click = now; client .ui .text(&id) - .select(data.cursor, data.size, data.sense.is_dragging()); + .select(data.cursor, data.size, data.sense.is_dragging(), recent); if let Some(region) = client.ui.window_region(&id) { client.handle.window.set_ime_allowed(true); client.handle.window.set_ime_cursor_area(