@@ -501,12 +501,12 @@ def show_help_dialog(event):
501501 HtmlDialog ("Getting syntax colorization" , content ).Show ()
502502
503503 def store_position (self , force = False ):
504- _ = force
505504 if self .source_editor and self .datafile_controller :
506505 cur_pos = self .source_editor .GetCurrentPos ()
507506 if cur_pos > 0 : # Cheating because it always goes to zero
508507 self ._position = cur_pos
509- self .source_editor .GotoPos (self ._position )
508+ if force :
509+ self .source_editor .GotoPos (self ._position )
510510
511511 def set_editor_caret_position (self ):
512512 if not self .is_focused (): # DEBUG was typing text when at Grid Editor
@@ -587,9 +587,9 @@ def _show_search_results(self, position, txt):
587587
588588 def OnContentAssist (self , event ):
589589 _ = event
590- self ._showing_list = False
591- # if not self.is_focused():
592- # return
590+ if self ._showing_list :
591+ self ._showing_list = False # Avoid double calls
592+ return
593593 self .store_position ()
594594 selected = self .source_editor .get_selected_or_near_text ()
595595 sugs = [s .name for s in self ._suggestions .get_suggestions (
@@ -599,6 +599,8 @@ def OnContentAssist(self, event):
599599 self .source_editor .AutoCompSetSeparator (ord (';' ))
600600 self .source_editor .AutoCompShow (0 , ";" .join (sugs ))
601601 self ._showing_list = True
602+ else :
603+ self .source_editor .SetInsertionPoint (self ._position ) # We should know if list was canceled or value change
602604
603605 def open (self , data ):
604606 self .reset ()
@@ -1500,25 +1502,29 @@ def calc_margin_width(self):
15001502 def get_selected_or_near_text (self ):
15011503 # First get selected text
15021504 selected = self .GetSelectedText ()
1503- self .SetInsertionPoint (self .GetInsertionPoint () - len (selected ))
15041505 if selected :
1506+ self .SetInsertionPoint (self .GetSelectionStart ())
15051507 return selected
15061508 # Next get text on the left
1507- self .SetSelectionEnd ( self . GetInsertionPoint () )
1509+ cur_pos = self .GetInsertionPoint ()
15081510 self .WordLeftEndExtend ()
15091511 selected = self .GetSelectedText ()
1510- select = selected .strip ()
1511- self .SetInsertionPoint (self .GetInsertionPoint () + len (selected )
1512- - len (select ))
1512+ select = selected .lstrip ()
15131513 if select and len (select ) > 0 :
1514+ start_pos = cur_pos - len (select )
1515+ self .SetInsertionPoint (start_pos )
1516+ self .SetSelectionStart (start_pos )
1517+ self .SetSelectionEnd (cur_pos - len (select ))
15141518 return select
15151519 # Finally get text on the right
1516- self .SetSelectionStart (self .GetInsertionPoint ())
1520+ cur_pos = self .GetInsertionPoint ()
1521+ self .SetSelectionStart (cur_pos )
15171522 self .WordRightEndExtend ()
15181523 selected = self .GetSelectedText ()
15191524 select = selected .strip ()
1520- self .SetInsertionPoint (self .GetInsertionPoint () - len (select ))
15211525 if select and len (select ) > 0 :
1526+ cur_pos = self .GetInsertionPoint ()
1527+ self .SetInsertionPoint (cur_pos - len (select ))
15221528 return select
15231529
15241530
0 commit comments