@@ -662,6 +662,9 @@ def notify_style_update(self) -> None:
662662 self ._line_cache .clear ()
663663 super ().notify_style_update ()
664664
665+ def update_suggestion (self ) -> None :
666+ """An hook to update suggestions."""
667+
665668 def check_consume_key (self , key : str , character : str | None = None ) -> bool :
666669 """Check if the widget may consume the given key.
667670
@@ -1074,6 +1077,7 @@ def load_text(self, text: str) -> None:
10741077 self .history .clear ()
10751078 self ._set_document (text , self .language )
10761079 self .post_message (self .Changed (self ).set_sender (self ))
1080+ self .update_suggestion ()
10771081
10781082 def _on_resize (self ) -> None :
10791083 self ._rewrap_and_refresh_virtual_size ()
@@ -1534,7 +1538,10 @@ def edit(self, edit: Edit) -> EditResult:
15341538 Data relating to the edit that may be useful. The data returned
15351539 may be different depending on the edit performed.
15361540 """
1537- self .suggestion = ""
1541+ if self .suggestion .startswith (edit .text ):
1542+ self .suggestion = self .suggestion [len (edit .text ) :]
1543+ else :
1544+ self .suggestion = ""
15381545 old_gutter_width = self .gutter_width
15391546 result = edit .do (self )
15401547 self .history .record (edit )
@@ -1551,8 +1558,11 @@ def edit(self, edit: Edit) -> EditResult:
15511558
15521559 self ._refresh_size ()
15531560 edit .after (self )
1561+
15541562 self ._build_highlight_map ()
15551563 self .post_message (self .Changed (self ))
1564+ self .update_suggestion ()
1565+
15561566 return result
15571567
15581568 def undo (self ) -> None :
@@ -1616,6 +1626,7 @@ def _undo_batch(self, edits: Sequence[Edit]) -> None:
16161626 edit .after (self )
16171627 self ._build_highlight_map ()
16181628 self .post_message (self .Changed (self ))
1629+ self .update_suggestion ()
16191630
16201631 def _redo_batch (self , edits : Sequence [Edit ]) -> None :
16211632 """Redo a batch of Edits in order.
@@ -1664,6 +1675,7 @@ def _redo_batch(self, edits: Sequence[Edit]) -> None:
16641675 edit .after (self )
16651676 self ._build_highlight_map ()
16661677 self .post_message (self .Changed (self ))
1678+ self .update_suggestion ()
16671679
16681680 async def _on_key (self , event : events .Key ) -> None :
16691681 """Handle key presses which correspond to document inserts."""
0 commit comments