diff --git a/crates/ui-egui/src/canvas/text_host.rs b/crates/ui-egui/src/canvas/text_host.rs index 8c61890d4..2a713e5fc 100644 --- a/crates/ui-egui/src/canvas/text_host.rs +++ b/crates/ui-egui/src/canvas/text_host.rs @@ -2,7 +2,7 @@ use std::ops::Range; use craft::behavior::{MotionMode, kurbo::Point}; use craft::text::ui::editor::{ - CaretAffinity, CaretLine, CaretStop, ClickRuns, EditKind, EditorComposition, EditorEnd, HostLine, HostRun, TextEditor, TextEditorHost, + CaretAffinity, CaretLine, CaretStop, ClickRuns, EditKind, EditorComposition, EditorEnd, HostLine, HostRun, TabKeys, TextEditor, TextEditorHost, TextEditorOutput, TextReplacement, TextSelection, }; use craft::ui::canvas::CanvasSpace; @@ -293,22 +293,8 @@ impl TextEditorHost for EngineTextHost<'_> { props.vert.unwrap_or(TextDir::Horizontal) != TextDir::Horizontal } - /// Tab in a cell goes to the next cell, at a paragraph start or over a range it changes the list level; Shift+Tab - /// elsewhere types a tab as Tab does. - fn tab(&mut self, selection: TextSelection, back: bool) -> Option { - self.select(selection); - match self.session.text_tab(back) { - Ok(true) => self.adopt_selection(), - Ok(false) if back => { - let replaced = self.replace(selection.range(), "\t", EditKind::Typed)?; - Some(replaced.selection) - } - Ok(false) => None, - Err(error) => { - self.error = Some(error.to_string()); - Some(selection) - } - } + fn tab_keys(&mut self) -> Option<&mut dyn TabKeys> { + Some(self) } fn caret_stop(&mut self, offset: usize, stop: CaretStop, forward: bool) -> Option { @@ -347,6 +333,26 @@ impl TextEditorHost for EngineTextHost<'_> { } } +impl TabKeys for EngineTextHost<'_> { + /// Tab in a cell goes to the next cell, at a paragraph start or over a range it changes the list level; Shift+Tab + /// elsewhere types a tab as Tab does. + fn tab(&mut self, selection: TextSelection, back: bool) -> Option { + self.select(selection); + match self.session.text_tab(back) { + Ok(true) => self.adopt_selection(), + Ok(false) if back => { + let replaced = self.replace(selection.range(), "\t", EditKind::Typed)?; + Some(replaced.selection) + } + Ok(false) => None, + Err(error) => { + self.error = Some(error.to_string()); + Some(selection) + } + } + } +} + fn layout_affinity(affinity: CaretAffinity) -> Affinity { if affinity == CaretAffinity::Upstream { Affinity::Upstream } else { Affinity::Downstream } }