From d40340cd42fa07255146388fb1ad05fd6e7759b8 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 22 Nov 2026 05:55:54 +0000 Subject: [PATCH] text: the editor's I-beam request in its own function (cognitive complexity) --- crates/text/src/ui/editor.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/text/src/ui/editor.rs b/crates/text/src/ui/editor.rs index d15863e95..eeb07900d 100644 --- a/crates/text/src/ui/editor.rs +++ b/crates/text/src/ui/editor.rs @@ -445,6 +445,14 @@ fn char_at(lines: &[HostLine], pos: TextPos) -> usize { line.chars.start + line.text[..byte].chars().count() } +/// 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. +fn show_i_beam(cx: &mut Cx<'_, TextEditor<'_>>, phase: &PressPhase, vertical: bool) { + if !matches!(phase, PressPhase::Idle) { + cx.cursor(if vertical { CursorIcon::VerticalText } else { CursorIcon::Text }, CursorPriority::Hover); + } +} + /// The clipboard's text when the pass's input asks to paste and the clipboard has it ready. fn pasted_text(cx: &mut Cx<'_, TextEditor<'_>>, inputs: &[EditorInput]) -> Option> { if !inputs.iter().any(|input| matches!(input, EditorInput::Edit(EditCommand::Paste))) { @@ -620,11 +628,7 @@ impl Component for TextEditor<'_> { if let Some(text) = copied { cx.clipboard().put(&[ClipItem::Text(text.into())]); } - // 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); - } + show_i_beam(cx, &press.phase, vertical); if done.changed { cx.propose(selection); } else if selection != before {