@@ -20,10 +20,12 @@ use std::sync::{Arc, Weak};
2020
2121use tracing:: instrument;
2222
23- use super :: { EditableText , ImeHandlerRef , Movement , Selection , TextLayout , TextStorage } ;
23+ use super :: {
24+ EditableText , ImeHandlerRef , ImeInvalidation , InputHandler , Movement , Selection , TextAction ,
25+ TextLayout , TextStorage ,
26+ } ;
2427use crate :: kurbo:: { Line , Point , Rect , Vec2 } ;
2528use crate :: piet:: TextLayout as _;
26- use crate :: shell:: text:: { Action as ImeAction , Event as ImeUpdate , InputHandler } ;
2729use crate :: widget:: prelude:: * ;
2830use crate :: { text, theme, Cursor , Env , Modifiers , Selector , TextAlignment , UpdateCtx } ;
2931
@@ -83,9 +85,9 @@ pub struct EditSession<T> {
8385 external_text_change : Option < T > ,
8486 external_selection_change : Option < Selection > ,
8587 external_scroll_to : Option < bool > ,
86- external_action : Option < ImeAction > ,
88+ external_action : Option < TextAction > ,
8789 /// A flag set in `update` if the text has changed from a non-IME source.
88- pending_ime_invalidation : Option < ImeUpdate > ,
90+ pending_ime_invalidation : Option < ImeInvalidation > ,
8991 /// If `true`, the component will send the [`TextComponent::RETURN`]
9092 /// notification when the user enters a newline.
9193 pub send_notification_on_return : bool ,
@@ -283,12 +285,12 @@ impl<T: TextStorage + EditableText> Widget<T> for TextComponent<T> {
283285 self . borrow_mut ( ) . layout . set_text ( data. clone ( ) ) ;
284286 self . borrow_mut ( ) . layout . rebuild_if_needed ( ctx. text ( ) , env) ;
285287 self . borrow_mut ( )
286- . update_pending_invalidation ( ImeUpdate :: Reset ) ;
288+ . update_pending_invalidation ( ImeInvalidation :: Reset ) ;
287289 }
288290 self . borrow_mut ( )
289291 . do_mouse_down ( mouse. pos , mouse. mods , mouse. count ) ;
290292 self . borrow_mut ( )
291- . update_pending_invalidation ( ImeUpdate :: SelectionChanged ) ;
293+ . update_pending_invalidation ( ImeInvalidation :: SelectionChanged ) ;
292294 ctx. request_update ( ) ;
293295 ctx. request_paint ( ) ;
294296 }
@@ -299,7 +301,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextComponent<T> {
299301 self . borrow_mut ( ) . do_drag ( mouse. pos ) ;
300302 if self . borrow ( ) . selection ( ) != pre_sel {
301303 self . borrow_mut ( )
302- . update_pending_invalidation ( ImeUpdate :: SelectionChanged ) ;
304+ . update_pending_invalidation ( ImeInvalidation :: SelectionChanged ) ;
303305 ctx. request_update ( ) ;
304306 ctx. request_paint ( ) ;
305307 }
@@ -324,12 +326,14 @@ impl<T: TextStorage + EditableText> Widget<T> for TextComponent<T> {
324326 }
325327 if let Some ( action) = action {
326328 match action {
327- ImeAction :: Cancel => ctx. submit_notification ( TextComponent :: CANCEL ) ,
328- ImeAction :: InsertNewLine { .. } => {
329+ TextAction :: Cancel => ctx. submit_notification ( TextComponent :: CANCEL ) ,
330+ TextAction :: InsertNewLine { .. } => {
329331 ctx. submit_notification ( TextComponent :: RETURN )
330332 }
331- ImeAction :: InsertTab { .. } => ctx. submit_notification ( TextComponent :: TAB ) ,
332- ImeAction :: InsertBacktab => ctx. submit_notification ( TextComponent :: BACKTAB ) ,
333+ TextAction :: InsertTab { .. } => ctx. submit_notification ( TextComponent :: TAB ) ,
334+ TextAction :: InsertBacktab => {
335+ ctx. submit_notification ( TextComponent :: BACKTAB )
336+ }
333337 _ => tracing:: warn!( "unexepcted external action '{:?}'" , action) ,
334338 } ;
335339 }
@@ -372,7 +376,7 @@ impl<T: TextStorage + EditableText> Widget<T> for TextComponent<T> {
372376 let new_origin = ctx. window_origin ( ) ;
373377 if prev_origin != new_origin {
374378 self . borrow_mut ( ) . origin = ctx. window_origin ( ) ;
375- ctx. invalidate_text_input ( ImeUpdate :: LayoutChanged ) ;
379+ ctx. invalidate_text_input ( ImeInvalidation :: LayoutChanged ) ;
376380 }
377381 }
378382 }
@@ -477,11 +481,11 @@ impl<T> EditSession<T> {
477481 /// invalidte the platform's IME state, by passing it to
478482 /// [`EventCtx::invalidate_text_input`].
479483 #[ must_use]
480- pub fn set_selection ( & mut self , selection : Selection ) -> Option < ImeUpdate > {
484+ pub fn set_selection ( & mut self , selection : Selection ) -> Option < ImeInvalidation > {
481485 if selection != self . selection {
482486 self . selection = selection;
483- self . update_pending_invalidation ( ImeUpdate :: SelectionChanged ) ;
484- Some ( ImeUpdate :: SelectionChanged )
487+ self . update_pending_invalidation ( ImeInvalidation :: SelectionChanged ) ;
488+ Some ( ImeInvalidation :: SelectionChanged )
485489 } else {
486490 None
487491 }
@@ -508,7 +512,7 @@ impl<T> EditSession<T> {
508512 /// Returns any invalidation action that should be passed to the platform.
509513 ///
510514 /// The user of this component *must* check this after calling `update`.
511- pub fn pending_ime_invalidation ( & mut self ) -> Option < ImeUpdate > {
515+ pub fn pending_ime_invalidation ( & mut self ) -> Option < ImeInvalidation > {
512516 self . pending_ime_invalidation . take ( )
513517 }
514518
@@ -524,20 +528,22 @@ impl<T> EditSession<T> {
524528 self . external_scroll_to . take ( )
525529 }
526530
527- fn take_external_action ( & mut self ) -> Option < ImeAction > {
531+ fn take_external_action ( & mut self ) -> Option < TextAction > {
528532 self . external_action . take ( )
529533 }
530534
531535 // we don't want to replace a more aggressive invalidation with a less aggressive one.
532- fn update_pending_invalidation ( & mut self , new_invalidation : ImeUpdate ) {
536+ fn update_pending_invalidation ( & mut self , new_invalidation : ImeInvalidation ) {
533537 self . pending_ime_invalidation = match self . pending_ime_invalidation . take ( ) {
534538 None => Some ( new_invalidation) ,
535539 Some ( prev) => match ( prev, new_invalidation) {
536- ( ImeUpdate :: SelectionChanged , ImeUpdate :: SelectionChanged ) => {
537- ImeUpdate :: SelectionChanged
540+ ( ImeInvalidation :: SelectionChanged , ImeInvalidation :: SelectionChanged ) => {
541+ ImeInvalidation :: SelectionChanged
542+ }
543+ ( ImeInvalidation :: LayoutChanged , ImeInvalidation :: LayoutChanged ) => {
544+ ImeInvalidation :: LayoutChanged
538545 }
539- ( ImeUpdate :: LayoutChanged , ImeUpdate :: LayoutChanged ) => ImeUpdate :: LayoutChanged ,
540- _ => ImeUpdate :: Reset ,
546+ _ => ImeInvalidation :: Reset ,
541547 }
542548 . into ( ) ,
543549 }
@@ -558,12 +564,12 @@ impl<T: TextStorage + EditableText> EditSession<T> {
558564 /// The caller is responsible for notifying the platform of the change in
559565 /// text state, by calling [`EventCtx::invalidate_text_input`].
560566 #[ must_use]
561- pub fn insert_text ( & mut self , data : & mut T , new_text : & str ) -> ImeUpdate {
567+ pub fn insert_text ( & mut self , data : & mut T , new_text : & str ) -> ImeInvalidation {
562568 let new_cursor_pos = self . selection . min ( ) + new_text. len ( ) ;
563569 data. edit ( self . selection . range ( ) , new_text) ;
564570 self . selection = Selection :: caret ( new_cursor_pos) ;
565571 self . scroll_to_selection_end ( true ) ;
566- ImeUpdate :: Reset
572+ ImeInvalidation :: Reset
567573 }
568574
569575 /// Sets the clipboard to the contents of the current selection.
@@ -588,23 +594,23 @@ impl<T: TextStorage + EditableText> EditSession<T> {
588594 self . external_scroll_to = Some ( after_edit) ;
589595 }
590596
591- fn do_action ( & mut self , buffer : & mut T , action : ImeAction ) {
597+ fn do_action ( & mut self , buffer : & mut T , action : TextAction ) {
592598 match action {
593- ImeAction :: Move ( movement) => {
599+ TextAction :: Move ( movement) => {
594600 let sel = text:: movement ( movement, self . selection , & self . layout , false ) ;
595601 self . external_selection_change = Some ( sel) ;
596602 self . scroll_to_selection_end ( false ) ;
597603 }
598- ImeAction :: MoveSelecting ( movement) => {
604+ TextAction :: MoveSelecting ( movement) => {
599605 let sel = text:: movement ( movement, self . selection , & self . layout , true ) ;
600606 self . external_selection_change = Some ( sel) ;
601607 self . scroll_to_selection_end ( false ) ;
602608 }
603- ImeAction :: SelectAll => {
609+ TextAction :: SelectAll => {
604610 let len = buffer. len ( ) ;
605611 self . external_selection_change = Some ( Selection :: new ( 0 , len) ) ;
606612 }
607- ImeAction :: SelectWord => {
613+ TextAction :: SelectWord => {
608614 if self . selection . is_caret ( ) {
609615 let range =
610616 text:: movement:: word_range_for_pos ( buffer. as_str ( ) , self . selection . active ) ;
@@ -615,17 +621,17 @@ impl<T: TextStorage + EditableText> EditSession<T> {
615621 // is not a caret (and may span multiple words)
616622 }
617623 // This requires us to have access to the layout, which might be stale?
618- ImeAction :: SelectLine => ( ) ,
624+ TextAction :: SelectLine => ( ) ,
619625 // this assumes our internal selection is consistent with the buffer?
620- ImeAction :: SelectParagraph => {
626+ TextAction :: SelectParagraph => {
621627 if !self . selection . is_caret ( ) || buffer. len ( ) < self . selection . active {
622628 return ;
623629 }
624630 let prev = buffer. preceding_line_break ( self . selection . active ) ;
625631 let next = buffer. next_line_break ( self . selection . active ) ;
626632 self . external_selection_change = Some ( Selection :: new ( prev, next) ) ;
627633 }
628- ImeAction :: Delete ( movement) if self . selection . is_caret ( ) => {
634+ TextAction :: Delete ( movement) if self . selection . is_caret ( ) => {
629635 if movement == Movement :: Grapheme ( druid_shell:: text:: Direction :: Upstream ) {
630636 self . backspace ( buffer) ;
631637 } else {
@@ -634,17 +640,17 @@ impl<T: TextStorage + EditableText> EditSession<T> {
634640 self . ime_insert_text ( buffer, "" )
635641 }
636642 }
637- ImeAction :: Delete ( _) => self . ime_insert_text ( buffer, "" ) ,
638- ImeAction :: DecomposingBackspace => {
643+ TextAction :: Delete ( _) => self . ime_insert_text ( buffer, "" ) ,
644+ TextAction :: DecomposingBackspace => {
639645 tracing:: warn!( "Decomposing Backspace is not implemented" ) ;
640646 self . backspace ( buffer) ;
641647 }
642- //ImeAction ::UppercaseSelection
643- //| ImeAction ::LowercaseSelection
644- //| ImeAction ::TitlecaseSelection => {
648+ //TextAction ::UppercaseSelection
649+ //| TextAction ::LowercaseSelection
650+ //| TextAction ::TitlecaseSelection => {
645651 //tracing::warn!("IME transformations are not implemented");
646652 //}
647- ImeAction :: InsertNewLine {
653+ TextAction :: InsertNewLine {
648654 newline_type,
649655 ignore_hotkey,
650656 } => {
@@ -654,21 +660,21 @@ impl<T: TextStorage + EditableText> EditSession<T> {
654660 self . ime_insert_text ( buffer, & newline_type. to_string ( ) ) ;
655661 }
656662 }
657- ImeAction :: InsertTab { ignore_hotkey } => {
663+ TextAction :: InsertTab { ignore_hotkey } => {
658664 if ignore_hotkey || self . accepts_tabs {
659665 self . ime_insert_text ( buffer, "\t " ) ;
660666 } else if !ignore_hotkey {
661667 self . external_action = Some ( action) ;
662668 }
663669 }
664- ImeAction :: InsertBacktab => {
670+ TextAction :: InsertBacktab => {
665671 if !self . accepts_tabs {
666672 self . external_action = Some ( action) ;
667673 }
668674 }
669- ImeAction :: InsertSingleQuoteIgnoringSmartQuotes => self . ime_insert_text ( buffer, "'" ) ,
670- ImeAction :: InsertDoubleQuoteIgnoringSmartQuotes => self . ime_insert_text ( buffer, "\" " ) ,
671- ImeAction :: Cancel if self . send_notification_on_cancel => {
675+ TextAction :: InsertSingleQuoteIgnoringSmartQuotes => self . ime_insert_text ( buffer, "'" ) ,
676+ TextAction :: InsertDoubleQuoteIgnoringSmartQuotes => self . ime_insert_text ( buffer, "\" " ) ,
677+ TextAction :: Cancel if self . send_notification_on_cancel => {
672678 self . external_action = Some ( action)
673679 }
674680 other => tracing:: warn!( "unhandled IME action {:?}" , other) ,
@@ -793,7 +799,7 @@ impl<T: TextStorage + EditableText> EditSession<T> {
793799 . map ( |t| !t. same ( new_data) )
794800 . unwrap_or ( true )
795801 {
796- self . update_pending_invalidation ( ImeUpdate :: Reset ) ;
802+ self . update_pending_invalidation ( ImeInvalidation :: Reset ) ;
797803 self . layout . set_text ( new_data. clone ( ) ) ;
798804 }
799805 if self . layout . needs_rebuild_after_update ( ctx) {
@@ -802,7 +808,7 @@ impl<T: TextStorage + EditableText> EditSession<T> {
802808 let new_sel = self . selection . constrained ( new_data. as_str ( ) ) ;
803809 if new_sel != self . selection {
804810 self . selection = new_sel;
805- self . update_pending_invalidation ( ImeUpdate :: SelectionChanged ) ;
811+ self . update_pending_invalidation ( ImeInvalidation :: SelectionChanged ) ;
806812 }
807813 self . layout . rebuild_if_needed ( ctx. text ( ) , env) ;
808814 }
@@ -888,7 +894,7 @@ impl<T: TextStorage + EditableText> InputHandler for EditSessionHandle<T> {
888894 . map ( |rect| rect + origin. to_vec2 ( ) )
889895 }
890896
891- fn handle_action ( & mut self , action : ImeAction ) {
897+ fn handle_action ( & mut self , action : TextAction ) {
892898 self . inner . borrow_mut ( ) . do_action ( & mut self . text , action) ;
893899 let text_changed = self
894900 . inner
0 commit comments