From e49f8de1ea39d308b4b00cc25ab859988aa94031 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 22 Nov 2026 05:48:54 +0000 Subject: [PATCH] text: show the editor's I-beam only over its text and during its own press The text editor requested the I-beam every pass of an open session, wherever the pointer was. At hover priority it beat the canvas tool's cursor and showed over panels, the options bar and the rest of the UI. It now asks only while its press is not idle: the pointer is over the editor or its own press is held. --- crates/text/src/ui/editor.rs | 6 +++++- crates/text/tests/it/editor.rs | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/text/src/ui/editor.rs b/crates/text/src/ui/editor.rs index 8d8a85a0e..d15863e95 100644 --- a/crates/text/src/ui/editor.rs +++ b/crates/text/src/ui/editor.rs @@ -620,7 +620,11 @@ impl Component for TextEditor<'_> { if let Some(text) = copied { cx.clipboard().put(&[ClipItem::Text(text.into())]); } - cx.cursor(if vertical { CursorIcon::VerticalText } else { CursorIcon::Text }, CursorPriority::Hover); + // The I-beam is the editor's over its text and while its own press is held; elsewhere the canvas's tool or the + // rest of the UI sets the pointer. + if !matches!(press.phase, PressPhase::Idle) { + cx.cursor(if vertical { CursorIcon::VerticalText } else { CursorIcon::Text }, CursorPriority::Hover); + } if done.changed { cx.propose(selection); } else if selection != before { diff --git a/crates/text/tests/it/editor.rs b/crates/text/tests/it/editor.rs index 7abc5e213..ef7e1ee25 100644 --- a/crates/text/tests/it/editor.rs +++ b/crates/text/tests/it/editor.rs @@ -210,6 +210,25 @@ fn a_secondary_click_on_the_text_reports_a_context_click_and_starts_no_drag() { assert_eq!(editor.commits.get() + editor.cancels.get(), 0, "the session stays open"); } +/// The I-beam is the editor's only over its text and while its own press is held: elsewhere the pointer is the +/// canvas's or the rest of the UI's. +#[trial] +fn the_i_beam_shows_over_the_text_and_during_its_drag_but_not_elsewhere() { + let mut editor = session("abc def", None); + editor.focus(); + let i_beam = Some(craft_behavior::Cursor::System(craft_behavior::CursorIcon::Text)); + let cursor = |editor: &Session| craft_ui::runtime::cursor::current(editor.fixture.ctx()); + let (on_text, away) = (pos2(40.0, 10.0), pos2(300.0, 300.0)); + editor.fixture.frame(vec![pointer::moved(on_text)]).settle(); + assert_eq!(cursor(&editor), i_beam, "over the text"); + editor.fixture.frame(vec![pointer::moved(away)]).settle(); + assert_ne!(cursor(&editor), i_beam, "away from the text, with the session open"); + editor.fixture.frame(vec![pointer::moved(on_text)]).frame(vec![pointer::press(on_text)]).frame(vec![pointer::moved(away)]); + assert_eq!(cursor(&editor), i_beam, "a drag that leaves the text keeps it"); + editor.fixture.frame(vec![pointer::release(away)]).settle(); + assert_ne!(cursor(&editor), i_beam, "after the release"); +} + fn preedit(text: &str) -> Event { Event::Ime(ImeEvent::Preedit { text: text.to_owned(), active_range_chars: None }) }