fix(mtext): keep arrows in editor

Route captured arrows to the MText caret only while the hidden command input retains focus.\n\nRefs #655
This commit is contained in:
Hakan Seven 2026-08-20 17:13:09 +03:00
commit 76ad642d0c
3 changed files with 22 additions and 4 deletions

View file

@ -1972,9 +1972,9 @@ pub enum Message {
}, },
/// A widget captured Up/Down; resolve it only if the command input owns /// A widget captured Up/Down; resolve it only if the command input owns
/// keyboard focus. /// keyboard focus.
CommandLineArrowProbe { direction: ArrowKey }, CommandLineArrowProbe { direction: ArrowKey, extend_selection: bool },
/// Result of the command-input focus query for a captured Up/Down key. /// Result of the command-input focus query for a captured Up/Down key.
CommandLineArrowResolved { direction: ArrowKey, focused: bool }, CommandLineArrowResolved { direction: ArrowKey, focused: bool, extend_selection: bool },
/// Toggle the dropdown listing the full command-line history. /// Toggle the dropdown listing the full command-line history.
CommandHistoryToggle, CommandHistoryToggle,
/// Grab/move/release the expanded history panel's top resize edge. /// Grab/move/release the expanded history panel's top resize edge.

View file

@ -1559,20 +1559,37 @@ impl OpenCADStudio {
)) ))
} }
Message::CommandLineArrowProbe { direction } => { Message::CommandLineArrowProbe {
direction,
extend_selection,
} => {
iced::widget::operation::is_focused(iced::widget::Id::new( iced::widget::operation::is_focused(iced::widget::Id::new(
crate::ui::command_line::CMD_INPUT_ID, crate::ui::command_line::CMD_INPUT_ID,
)) ))
.map(move |focused| Message::CommandLineArrowResolved { .map(move |focused| Message::CommandLineArrowResolved {
direction, direction,
focused, focused,
extend_selection,
}) })
} }
Message::CommandLineArrowResolved { direction, focused } => { Message::CommandLineArrowResolved {
direction,
focused,
extend_selection,
} => {
if !focused { if !focused {
return Task::none(); return Task::none();
} }
// The editor inherits arrows captured by the focused command line.
if self.mtext_editor.is_some() {
match direction {
ArrowKey::Up => self.mtext_caret_move_vertical(1, extend_selection),
ArrowKey::Down => self.mtext_caret_move_vertical(-1, extend_selection),
ArrowKey::Left | ArrowKey::Right => {}
}
return Task::none();
}
match direction { match direction {
ArrowKey::Up => self.update(Message::CommandHistoryPrev), ArrowKey::Up => self.update(Message::CommandHistoryPrev),
ArrowKey::Down => self.update(Message::CommandHistoryNext), ArrowKey::Down => self.update(Message::CommandHistoryNext),

View file

@ -2266,6 +2266,7 @@ impl OpenCADStudio {
{ {
return Some(Message::CommandLineArrowProbe { return Some(Message::CommandLineArrowProbe {
direction: arrow?, direction: arrow?,
extend_selection: modifiers.shift(),
}); });
} }
// A focused web text field needs the browser clipboard; // A focused web text field needs the browser clipboard;