word selection

This commit is contained in:
2025-11-22 15:33:28 -05:00
parent fc89826794
commit c24c517c60
3 changed files with 54 additions and 20 deletions

View File

@@ -5,7 +5,10 @@ use input::Input;
use iris::prelude::*;
use len_fns::*;
use render::Renderer;
use std::sync::Arc;
use std::{
sync::Arc,
time::{Duration, Instant},
};
use winit::{
dpi::{LogicalPosition, LogicalSize},
event::{Ime, WindowEvent},
@@ -30,6 +33,7 @@ pub struct Client {
focus: Option<WidgetId<TextEdit>>,
clipboard: Clipboard,
ime: usize,
last_click: Instant,
}
#[derive(Eq, PartialEq, Hash, Clone)]
@@ -50,10 +54,15 @@ impl WidgetAttr<TextEdit> for Selectable {
&id.clone(),
CursorSense::click_or_drag(),
move |client: &mut Client, data| {
client
.ui
.text(&id)
.select(data.cursor, data.size, data.sense.is_dragging());
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(),
recent,
);
if let Some(region) = client.ui.window_region(&id) {
client.window.set_ime_allowed(true);
client.window.set_ime_cursor_area(
@@ -249,16 +258,15 @@ impl Client {
focus: None,
clipboard: Clipboard::new().unwrap(),
ime: 0,
last_click: Instant::now(),
}
}
pub fn 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 {
@@ -266,6 +274,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 => {