@@ -88,7 +88,8 @@ def read_language(content):
8888def obtain_language (existing , content ):
8989 try :
9090 set_lang = shared_memory .ShareableList (name = "language" )
91- except AttributeError : # Unittests fails here
91+ except Exception as e : # AttributeError: # Unittests fails here
92+ print (f"DEBUG: texteditor.py obtain_language EXCEPTION: { e } " )
9293 set_lang = []
9394 doc_lang = read_language (content )
9495 adoc_lang = []
@@ -384,6 +385,7 @@ def __init__(self, application):
384385 self ._tab = None
385386 self ._doc_language = None
386387 self ._save_flag = 0
388+ self .jump = True
387389 self .reformat = application .settings .get ('reformat' , False )
388390 self ._register_shortcuts ()
389391
@@ -443,6 +445,7 @@ def on_open(self, event):
443445 self ._open ()
444446
445447 def _open (self ):
448+ # print(f"DEBUG: texteditor.py TextEditorPlugin _open ENTER curpos={self._editor._position}")
446449 datafile_controller = self .tree .get_selected_datafile_controller ()
447450 if datafile_controller :
448451 self ._save_flag = 0
@@ -496,13 +499,16 @@ def _check_message(self, message: RideMessage) -> None:
496499 self ._save_flag = 2
497500 if self .is_focused () and self ._save_flag == 2 and isinstance (message , RideSaved ):
498501 self ._save_flag = 3
499- wx .CallAfter (self ._editor .mark_file_dirty , False )
502+ print (f"DEBUG: textedit.py TextEditorPlugin _check_message call undirty, { message } " )
503+ # wx.CallAfter(self._editor.mark_file_dirty, False)
504+ self ._editor .mark_file_dirty (False )
505+ self .tree ._data_undirty (message )
500506 # DEBUG: This is the unwanted chnge after saving but excluded in this block for performance
501507 # if self.is_focused() and self._save_flag == 3 and isinstance(message, RideDataChangedToDirty):
502508 # self._save_flag = 4
503509 # wx.CallAfter(self._editor.mark_file_dirty, False)
504510 if isinstance (message , RideBeforeSaving ):
505- self ._editor .is_saving = False
511+ # self._editor.is_saving = False
506512 # Reset counter for Workaround for remarked dirty with Ctrl-S
507513 self ._save_flag = 0
508514 self ._apply_txt_changes_to_model ()
@@ -511,7 +517,7 @@ def on_data_changed(self, message):
511517 """ This block is now inside try/except to avoid errors from unit test """
512518 try :
513519 if self .is_focused () and isinstance (message , RideDataChangedToDirty ):
514- # print("DEBUG: textedit OnDataChanged returning RideDataChangedToDirty")
520+ # print(f "DEBUG: textedit OnDataChanged returning RideDataChangedToDirty {self._save_flag=} ")
515521 return
516522 if self ._should_process_data_changed_message (message ):
517523 # print(f"DEBUG: textedit after _should_process_data_changed_message save_flag={self._save_flag}")
@@ -532,21 +538,29 @@ def _should_process_data_changed_message(message):
532538 # and not isinstance(message, RideDataChangedToDirty))
533539
534540 def on_tree_selection (self , message ):
541+ if not self .is_focused ():
542+ return
535543 # print(f"DEBUG: texteditor.py TextEditorPlugin on_tree_selection ENTER {message=} type={type(message.item)}")
536544 self ._editor .store_position ()
545+ # self.jump = True
537546 if self .is_focused ():
538547 next_datafile_controller = message .item and message .item .datafile_controller
539548 if self ._editor .datafile_controller == message .item .datafile_controller == next_datafile_controller :
540- # print(f"DEBUG: OnTreeSelection Same FILE item type={type(message.item)}")
549+ # print(f"DEBUG: OnTreeSelection Same FILE item type={type(message.item)}\n"
550+ # f"value of {self._save_flag=}")
541551 self ._editor .locate_tree_item (message .item )
552+ self .jump = True
542553 return
543554 if self ._editor .dirty and not self ._apply_txt_changes_to_model ():
544555 if self ._editor .datafile_controller != next_datafile_controller :
545556 self .tree .select_controller_node (self ._editor .datafile_controller )
546557 self ._editor .set_editor_caret_position ()
547558 return
548559 if next_datafile_controller :
560+ self .jump = True
549561 self ._open_data_for_controller (next_datafile_controller )
562+ # print(f"DEBUG: OnTreeSelection OTHER FILE item type={type(message.item)}\n"
563+ # f"value of {self._save_flag=}")
550564 wx .CallAfter (self ._editor .locate_tree_item , message .item )
551565 self ._set_read_only (message )
552566 self ._editor .set_editor_caret_position ()
@@ -588,7 +602,8 @@ def on_tab_change(self, message):
588602 self ._set_read_only (self ._editor .source_editor .readonly )
589603 except Exception as e : # DEBUG: When using only Text Editor exists error in message topic
590604 print (e )
591- wx .CallAfter (self ._editor .source_editor .on_style , None ) # DEBUG Text Edit, styles were not applied
605+ # wx.CallAfter(self._editor.source_editor.on_style, None) # DEBUG Text Edit, styles were not applied
606+ self ._editor .source_editor .on_style (None )
592607 self ._editor .Refresh ()
593608 elif message .oldtab == self .title :
594609 self ._editor .remove_and_store_state ()
@@ -600,8 +615,12 @@ def on_tab_changed(self, event):
600615 event .Skip ()
601616
602617 def _apply_txt_changes_to_model (self ):
603- self ._editor .is_saving = False
604- # print(f"DEBUG: textedit.py _apply_txt_changes_to_model CALL content_save lang={self._doc_language}")
618+ if not self .is_focused () and not self ._editor .dirty :
619+ return
620+ # self._editor.is_saving = False
621+ # self._editor.store_position()
622+ # print(f"DEBUG: textedit.py _apply_txt_changes_to_model CALL content_save lang={self._doc_language}"
623+ # f" curpos={self._editor._position}")
605624 if not self ._editor .content_save (lang = self ._doc_language ):
606625 return False
607626 self ._editor .reset ()
@@ -945,7 +964,7 @@ def __init__(self, plugin, parent, title, data_validator):
945964 self ._words_cache = set () # Actual cache of words to add to suggestions
946965 self ._stored_text = None
947966 self ._ctrl_action = None
948- self .is_saving = False # To avoid double calls to save
967+ # self.is_saving = False # To avoid double calls to save
949968 self .old_information_popup = None
950969 PUBLISHER .subscribe (self .on_settings_changed , RideSettingsChanged )
951970 PUBLISHER .subscribe (self .on_tab_change , RideNotebookTabChanging )
@@ -1068,7 +1087,7 @@ def set_editor_caret_position(self):
10681087 return
10691088 position = self ._position
10701089 self .source_editor .SetFocus ()
1071- # print(f"DEBUG: texteditor.py SourceEditor position={position}")
1090+ # print(f"DEBUG: texteditor.py SourceEditor set_editor_caret_position position={position}")
10721091 if position :
10731092 self .source_editor .SetCurrentPos (position )
10741093 self .source_editor .SetSelection (self .restore_start_pos , self .restore_end_pos )
@@ -1153,12 +1172,16 @@ def _show_search_results(self, position, txt):
11531172
11541173 def locate_tree_item (self , item ):
11551174 """ item is object received from message """
1175+ if not self .plugin .jump :
1176+ self .plugin .jump = True
1177+ return
11561178 from wx .stc import STC_FIND_REGEXP
11571179 search_end = len (self .source_editor .utf8_text )
11581180 section_start = 0
11591181 name_to_locate = r'^' + item .name + r'.*$'
11601182 position = self .source_editor .FindText (section_start , search_end , name_to_locate , STC_FIND_REGEXP )
1161- # print(f"DEBUG: TextEditor locate_tree_item name_to_locate={name_to_locate} position={position}")
1183+ # print(f"DEBUG: TextEditor locate_tree_item name_to_locate={name_to_locate} position={position}\n"
1184+ # f"curpos={self._position} {self.is_saving=}")
11621185 if position [0 ] != - 1 :
11631186 # DEBUG: Make colours configurable?
11641187 self .source_editor .SetSelBackground (True , Colour ('orange' ))
@@ -1320,7 +1343,7 @@ def open(self, data):
13201343 self .language = self ._data ._language
13211344 else :
13221345 self .language = ['en' ]
1323- # print(f"DEBUG: texteditor.py SourceEditor open ENTER language={self.language}")
1346+ # print(f"DEBUG: texteditor.py SourceEditor open ENTER language={self.language} curpos={self._position} ")
13241347 try :
13251348 if hasattr (self ._data , 'wrapper_data' ):
13261349 if isinstance (self ._data .wrapper_data , ResourceFileController ):
@@ -1492,14 +1515,15 @@ def reset(self):
14921515
14931516 def content_save (self , ** args ):
14941517 self .store_position ()
1495- if self . dirty and not self .is_saving :
1496- self .is_saving = True
1518+ # print(f"DEBUG: TextEditor.py SourceEditor content_save curpos={ self._position}")
1519+ if self .dirty :
14971520 # print(f"DEBUG: TextEditor.py SourceEditor content_save content={self.source_editor.utf8_text}\n"
14981521 # f"self.language={self.language} data={self._data}"
14991522 # f" calling validate_and_update with lang={args['lang']}")
1523+ self .plugin .jump = False
15001524 if not self ._data_validator .validate_and_update (self ._data , self .source_editor .utf8_text ,
15011525 lang = self .language ): # args['lang']
1502- self .is_saving = False
1526+ self .plugin . jump = True
15031527 return False
15041528 return True
15051529
@@ -1541,7 +1565,7 @@ def on_paste(self, event):
15411565 @staticmethod
15421566 def on_insert (event ):
15431567 __ = event
1544- print (f"DEBUG: TextEditor called on_insert event={ event } \n TO BE IMPLEMENTED" )
1568+ # print(f"DEBUG: TextEditor called on_insert event={event}\n TO BE IMPLEMENTED")
15451569 # self.insert_row()
15461570
15471571 @staticmethod
@@ -1768,6 +1792,7 @@ def on_key_down(self, event):
17681792 # This must be the last branch to activate actions before doc
17691793 # DEBUG: coords = self._get_screen_coordinates()
17701794 self .source_editor .show_kw_doc ()
1795+ self .mark_file_dirty (self .source_editor .GetModify ())
17711796 event .Skip ()
17721797
17731798 # These commands are duplicated by global actions
0 commit comments