@@ -68,7 +68,6 @@ pub enum TextToolMessage {
6868 Abort ,
6969 WorkingColorChanged ,
7070 Overlays { context : OverlayContext } ,
71- TimerTick { tick : u64 } ,
7271
7372 // Tool-specific messages
7473 DragStart ,
@@ -436,7 +435,6 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Text
436435 CommitText ,
437436 Undo ,
438437 Redo ,
439- TimerTick ,
440438 DoubleClick ,
441439 TripleClick ,
442440 SelectAll ,
@@ -549,8 +547,6 @@ struct TextToolData {
549547 layer_dragging : Option < ResizingLayer > ,
550548 cursor_byte_offset : usize ,
551549 selection_start_byte_offset : Option < usize > ,
552- cursor_visible : bool ,
553- blink_tick : u64 ,
554550 dragging_to_select : bool ,
555551 history : Vec < TextToolHistoryState > ,
556552 history_index : usize ,
@@ -616,10 +612,7 @@ impl TextToolData {
616612 responses. add ( FrontendMessage :: UpdateTextEditingState { is_editing : editable } ) ;
617613 }
618614
619- fn reset_cursor_blink ( & mut self , responses : & mut VecDeque < Message > ) {
620- self . cursor_visible = true ;
621- self . blink_tick += 1 ;
622- spawn_blink_timer ( self . blink_tick , responses) ;
615+ fn schedule_cursor_draw ( & self , responses : & mut VecDeque < Message > ) {
623616 responses. add ( OverlaysMessage :: Draw ) ;
624617 responses. add ( TextToolMessage :: AutoPanCursor ) ;
625618 }
@@ -684,7 +677,7 @@ impl TextToolData {
684677 } else {
685678 self . cursor_byte_offset = self . new_text . len ( ) ;
686679 }
687- self . reset_cursor_blink ( responses) ;
680+ self . schedule_cursor_draw ( responses) ;
688681 Some ( ( ) )
689682 }
690683
@@ -745,7 +738,7 @@ impl TextToolData {
745738 self . editing_text = Some ( editing_text) ;
746739 self . cursor_byte_offset = 0 ;
747740 self . selection_start_byte_offset = None ;
748- self . reset_cursor_blink ( responses) ;
741+ self . schedule_cursor_draw ( responses) ;
749742
750743 self . history . clear ( ) ;
751744 self . history_index = 0 ;
@@ -864,14 +857,12 @@ impl Fsm for TextToolFsmState {
864857 }
865858 }
866859
867- if tool_data. cursor_visible {
868- let cursor_offset = tool_data. cursor_byte_offset . min ( tool_data. new_text . len ( ) ) ;
869- let [ top_left, bottom_right] = graphene_std:: text:: cursor_rect ( & tool_data. new_text , & font_resource, editing_text. typesetting , cursor_offset, 0.0 ) ;
860+ let cursor_offset = tool_data. cursor_byte_offset . min ( tool_data. new_text . len ( ) ) ;
861+ let [ top_left, bottom_right] = graphene_std:: text:: cursor_rect ( & tool_data. new_text , & font_resource, editing_text. typesetting , cursor_offset, 0.0 ) ;
870862
871- let cursor_start = layer_to_viewport. transform_point2 ( DVec2 :: new ( top_left. x , top_left. y ) ) ;
872- let cursor_end = layer_to_viewport. transform_point2 ( DVec2 :: new ( top_left. x , bottom_right. y ) ) ;
873- overlay_context. line ( cursor_start, cursor_end, Some ( "#000000" ) , Some ( 1.5 ) ) ;
874- }
863+ let cursor_start = layer_to_viewport. transform_point2 ( DVec2 :: new ( top_left. x , top_left. y ) ) ;
864+ let cursor_end = layer_to_viewport. transform_point2 ( DVec2 :: new ( top_left. x , bottom_right. y ) ) ;
865+ overlay_context. line ( cursor_start, cursor_end, Some ( "#000000" ) , Some ( 1. ) ) ;
875866 }
876867
877868 TextToolFsmState :: Editing
@@ -945,7 +936,7 @@ impl Fsm for TextToolFsmState {
945936 }
946937 tool_data. dragging_to_select = true ;
947938 tool_data. last_edit_type = TextEditType :: None ;
948- tool_data. reset_cursor_blink ( responses) ;
939+ tool_data. schedule_cursor_draw ( responses) ;
949940 return TextToolFsmState :: Editing ;
950941 }
951942
@@ -1068,7 +1059,7 @@ impl Fsm for TextToolFsmState {
10681059 }
10691060 tool_data. dragging_to_select = false ;
10701061 tool_data. selection_type = TextSelectionType :: Character ;
1071- tool_data. reset_cursor_blink ( responses) ;
1062+ tool_data. schedule_cursor_draw ( responses) ;
10721063 }
10731064 TextToolFsmState :: Editing
10741065 }
@@ -1210,7 +1201,7 @@ impl Fsm for TextToolFsmState {
12101201 tool_data. selection_type = TextSelectionType :: Word ;
12111202 tool_data. word_selection_origin = Some ( ( word_start, word_end) ) ;
12121203 tool_data. last_edit_type = TextEditType :: None ;
1213- tool_data. reset_cursor_blink ( responses) ;
1204+ tool_data. schedule_cursor_draw ( responses) ;
12141205 }
12151206 TextToolFsmState :: Editing
12161207 }
@@ -1224,7 +1215,7 @@ impl Fsm for TextToolFsmState {
12241215 tool_data. selection_type = TextSelectionType :: Paragraph ;
12251216 tool_data. word_selection_origin = Some ( ( line_start, line_end) ) ;
12261217 tool_data. last_edit_type = TextEditType :: None ;
1227- tool_data. reset_cursor_blink ( responses) ;
1218+ tool_data. schedule_cursor_draw ( responses) ;
12281219 }
12291220 TextToolFsmState :: Editing
12301221 }
@@ -1336,7 +1327,7 @@ impl Fsm for TextToolFsmState {
13361327 } ) ;
13371328 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
13381329 }
1339- tool_data. reset_cursor_blink ( responses) ;
1330+ tool_data. schedule_cursor_draw ( responses) ;
13401331 TextToolFsmState :: Editing
13411332 }
13421333 ( TextToolFsmState :: Editing , TextToolMessage :: BackspaceChar ) => {
@@ -1362,7 +1353,7 @@ impl Fsm for TextToolFsmState {
13621353 } ) ;
13631354 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
13641355 }
1365- tool_data. reset_cursor_blink ( responses) ;
1356+ tool_data. schedule_cursor_draw ( responses) ;
13661357 TextToolFsmState :: Editing
13671358 }
13681359 ( TextToolFsmState :: Editing , TextToolMessage :: DeleteChar ) => {
@@ -1386,7 +1377,7 @@ impl Fsm for TextToolFsmState {
13861377 } ) ;
13871378 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
13881379 }
1389- tool_data. reset_cursor_blink ( responses) ;
1380+ tool_data. schedule_cursor_draw ( responses) ;
13901381 TextToolFsmState :: Editing
13911382 }
13921383 ( TextToolFsmState :: Editing , TextToolMessage :: MoveCursorLeft { word, select } ) => {
@@ -1407,7 +1398,7 @@ impl Fsm for TextToolFsmState {
14071398 tool_data. cursor_byte_offset = prev;
14081399 }
14091400 tool_data. last_edit_type = TextEditType :: None ;
1410- tool_data. reset_cursor_blink ( responses) ;
1401+ tool_data. schedule_cursor_draw ( responses) ;
14111402 TextToolFsmState :: Editing
14121403 }
14131404 ( TextToolFsmState :: Editing , TextToolMessage :: MoveCursorRight { word, select } ) => {
@@ -1428,7 +1419,7 @@ impl Fsm for TextToolFsmState {
14281419 tool_data. cursor_byte_offset = offset + next_char;
14291420 }
14301421 tool_data. last_edit_type = TextEditType :: None ;
1431- tool_data. reset_cursor_blink ( responses) ;
1422+ tool_data. schedule_cursor_draw ( responses) ;
14321423 TextToolFsmState :: Editing
14331424 }
14341425 ( TextToolFsmState :: Editing , msg @ ( TextToolMessage :: MoveCursorUp { .. } | TextToolMessage :: MoveCursorDown { .. } ) ) => {
@@ -1458,7 +1449,7 @@ impl Fsm for TextToolFsmState {
14581449 tool_data. cursor_byte_offset = new_offset;
14591450 }
14601451 tool_data. last_edit_type = TextEditType :: None ;
1461- tool_data. reset_cursor_blink ( responses) ;
1452+ tool_data. schedule_cursor_draw ( responses) ;
14621453 TextToolFsmState :: Editing
14631454 }
14641455 ( TextToolFsmState :: Editing , TextToolMessage :: MoveCursorHome { select } ) => {
@@ -1471,7 +1462,7 @@ impl Fsm for TextToolFsmState {
14711462 let line_start = tool_data. new_text [ ..old_offset] . rfind ( '\n' ) . map ( |i| i + 1 ) . unwrap_or ( 0 ) ;
14721463 tool_data. cursor_byte_offset = line_start;
14731464 tool_data. last_edit_type = TextEditType :: None ;
1474- tool_data. reset_cursor_blink ( responses) ;
1465+ tool_data. schedule_cursor_draw ( responses) ;
14751466 TextToolFsmState :: Editing
14761467 }
14771468 ( TextToolFsmState :: Editing , TextToolMessage :: MoveCursorEnd { select } ) => {
@@ -1484,7 +1475,7 @@ impl Fsm for TextToolFsmState {
14841475 let line_end = tool_data. new_text [ old_offset..] . find ( '\n' ) . map ( |i| old_offset + i) . unwrap_or ( tool_data. new_text . len ( ) ) ;
14851476 tool_data. cursor_byte_offset = line_end;
14861477 tool_data. last_edit_type = TextEditType :: None ;
1487- tool_data. reset_cursor_blink ( responses) ;
1478+ tool_data. schedule_cursor_draw ( responses) ;
14881479 TextToolFsmState :: Editing
14891480 }
14901481 ( TextToolFsmState :: Editing , TextToolMessage :: MoveCursorTop { select } ) => {
@@ -1495,7 +1486,7 @@ impl Fsm for TextToolFsmState {
14951486 }
14961487 tool_data. cursor_byte_offset = 0 ;
14971488 tool_data. last_edit_type = TextEditType :: None ;
1498- tool_data. reset_cursor_blink ( responses) ;
1489+ tool_data. schedule_cursor_draw ( responses) ;
14991490 TextToolFsmState :: Editing
15001491 }
15011492 ( TextToolFsmState :: Editing , TextToolMessage :: MoveCursorBottom { select } ) => {
@@ -1506,14 +1497,14 @@ impl Fsm for TextToolFsmState {
15061497 }
15071498 tool_data. cursor_byte_offset = tool_data. new_text . len ( ) ;
15081499 tool_data. last_edit_type = TextEditType :: None ;
1509- tool_data. reset_cursor_blink ( responses) ;
1500+ tool_data. schedule_cursor_draw ( responses) ;
15101501 TextToolFsmState :: Editing
15111502 }
15121503 ( TextToolFsmState :: Editing , TextToolMessage :: SelectAll ) => {
15131504 tool_data. selection_start_byte_offset = Some ( 0 ) ;
15141505 tool_data. cursor_byte_offset = tool_data. new_text . len ( ) ;
15151506 tool_data. last_edit_type = TextEditType :: None ;
1516- tool_data. reset_cursor_blink ( responses) ;
1507+ tool_data. schedule_cursor_draw ( responses) ;
15171508 TextToolFsmState :: Editing
15181509 }
15191510 ( TextToolFsmState :: Editing , TextToolMessage :: Copy ) => {
@@ -1542,7 +1533,7 @@ impl Fsm for TextToolFsmState {
15421533 } ) ;
15431534 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
15441535 }
1545- tool_data. reset_cursor_blink ( responses) ;
1536+ tool_data. schedule_cursor_draw ( responses) ;
15461537 }
15471538 TextToolFsmState :: Editing
15481539 }
@@ -1564,7 +1555,7 @@ impl Fsm for TextToolFsmState {
15641555 } ) ;
15651556 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
15661557 }
1567- tool_data. reset_cursor_blink ( responses) ;
1558+ tool_data. schedule_cursor_draw ( responses) ;
15681559 TextToolFsmState :: Editing
15691560 }
15701561 ( TextToolFsmState :: Editing , TextToolMessage :: DeletePreviousWord ) => {
@@ -1596,7 +1587,7 @@ impl Fsm for TextToolFsmState {
15961587 } ) ;
15971588 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
15981589 }
1599- tool_data. reset_cursor_blink ( responses) ;
1590+ tool_data. schedule_cursor_draw ( responses) ;
16001591 TextToolFsmState :: Editing
16011592 }
16021593 ( TextToolFsmState :: Editing , TextToolMessage :: DeleteLine ) => {
@@ -1626,7 +1617,7 @@ impl Fsm for TextToolFsmState {
16261617 } ) ;
16271618 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
16281619 }
1629- tool_data. reset_cursor_blink ( responses) ;
1620+ tool_data. schedule_cursor_draw ( responses) ;
16301621 TextToolFsmState :: Editing
16311622 }
16321623 ( TextToolFsmState :: Editing , TextToolMessage :: InsertNewline ) => {
@@ -1647,7 +1638,7 @@ impl Fsm for TextToolFsmState {
16471638 } ) ;
16481639 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
16491640 }
1650- tool_data. reset_cursor_blink ( responses) ;
1641+ tool_data. schedule_cursor_draw ( responses) ;
16511642 TextToolFsmState :: Editing
16521643 }
16531644 ( TextToolFsmState :: Editing , TextToolMessage :: Undo ) => {
@@ -1666,7 +1657,7 @@ impl Fsm for TextToolFsmState {
16661657 } ) ;
16671658 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
16681659 }
1669- tool_data. reset_cursor_blink ( responses) ;
1660+ tool_data. schedule_cursor_draw ( responses) ;
16701661 }
16711662 tool_data. last_edit_type = TextEditType :: None ;
16721663 TextToolFsmState :: Editing
@@ -1686,7 +1677,7 @@ impl Fsm for TextToolFsmState {
16861677 } ) ;
16871678 responses. add ( NodeGraphMessage :: RunDocumentGraph ) ;
16881679 }
1689- tool_data. reset_cursor_blink ( responses) ;
1680+ tool_data. schedule_cursor_draw ( responses) ;
16901681 }
16911682 tool_data. last_edit_type = TextEditType :: None ;
16921683 TextToolFsmState :: Editing
@@ -1734,15 +1725,6 @@ impl Fsm for TextToolFsmState {
17341725 responses. add ( DocumentMessage :: EndTransaction ) ;
17351726 TextToolFsmState :: Ready
17361727 }
1737- ( TextToolFsmState :: Editing , TextToolMessage :: TimerTick { tick } ) => {
1738- if tick == tool_data. blink_tick {
1739- tool_data. cursor_visible = !tool_data. cursor_visible ;
1740- tool_data. blink_tick += 1 ;
1741- spawn_blink_timer ( tool_data. blink_tick , responses) ;
1742- responses. add ( OverlaysMessage :: Draw ) ;
1743- }
1744- TextToolFsmState :: Editing
1745- }
17461728 ( TextToolFsmState :: Editing , TextToolMessage :: AutoPanCursor ) => {
17471729 if let Some ( editing_text) = tool_data. editing_text . as_ref ( ) {
17481730 let font_resource = fonts. get_resource_or_queue_load ( & editing_text. font , responses) ;
@@ -1849,23 +1831,3 @@ impl Fsm for TextToolFsmState {
18491831 responses. add ( FrontendMessage :: UpdateMouseCursor { cursor } ) ;
18501832 }
18511833}
1852-
1853- fn spawn_blink_timer ( tick : u64 , responses : & mut VecDeque < Message > ) {
1854- responses. add ( async move {
1855- #[ cfg( target_family = "wasm" ) ]
1856- {
1857- let mut cb = |resolve : js_sys:: Function , _reject| {
1858- if let Some ( window) = web_sys:: window ( ) {
1859- let _ = window. set_timeout_with_callback_and_timeout_and_arguments_0 ( & resolve, 500 ) ;
1860- }
1861- } ;
1862- let promise = js_sys:: Promise :: new ( & mut cb) ;
1863- wasm_bindgen_futures:: JsFuture :: from ( promise) . await . unwrap ( ) ;
1864- }
1865- #[ cfg( not( target_family = "wasm" ) ) ]
1866- {
1867- tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 500 ) ) . await ;
1868- }
1869- Message :: Tool ( ToolMessage :: Text ( TextToolMessage :: TimerTick { tick } ) )
1870- } ) ;
1871- }
0 commit comments