@@ -609,7 +609,10 @@ def _apply_txt_changes_to_model(self):
609609 return True
610610
611611 def is_focused (self ):
612- return self .notebook .current_page_title == self .title
612+ try :
613+ return self .notebook .current_page_title == self .title
614+ except AttributeError :
615+ return self ._editor .is_focused ()
613616
614617
615618class DummyController (WithStepsController ):
@@ -1223,8 +1226,12 @@ def on_content_assist(self, event):
12231226 """
12241227 self .store_position ()
12251228 selected = self .source_editor .get_selected_or_near_text ()
1226- print (f"DEBUG: texteditor.py SourceEditor SELECTION selected = { selected } is type={ type (selected )} " )
1229+ # print(f"DEBUG: texteditor.py SourceEditor SELECTION selected = {selected} is type={type(selected)}")
12271230 self .set_editor_caret_position ()
1231+ # Next is for the unit tests when the did not used open to get data:
1232+ if not self ._suggestions :
1233+ self ._controller_for_context = DummyController (self ._data .wrapper_data , self ._data .wrapper_data )
1234+ self ._suggestions = SuggestionSource (self .plugin , self ._controller_for_context )
12281235 self ._suggestions .update_from_local (self .words_cache (self .source_editor .GetLineCount ()), self .language )
12291236 sugs = set ()
12301237 if selected :
@@ -1239,7 +1246,7 @@ def on_content_assist(self, event):
12391246 else :
12401247 found .append (s )
12411248 sugs .update (found )
1242- print (f"DEBUG: texteditor.py SourceEditor on_content_assist FIRST SUGGESTION suggestions = { sugs } \n " )
1249+ # print(f"DEBUG: texteditor.py SourceEditor on_content_assist FIRST SUGGESTION suggestions = {sugs}\n")
12431250 # DEBUG: Here, if sugs is still [], then we can get all words from line and repeat suggestions
12441251 # In another evolution, we can use database of words by frequency (considering future by project db)
12451252 sel = [s for s in selected ] if selected else ['' ]
@@ -1249,7 +1256,7 @@ def on_content_assist(self, event):
12491256 # if sel[0] == '':
12501257 # The case when we call Ctl+Space in empty line o always add suggestions
12511258 # for start in sel:
1252- print (f"DEBUG: texteditor.py SourceEditor on_content_assist selection = { sel } " )
1259+ # print(f"DEBUG: texteditor.py SourceEditor on_content_assist selection = {sel}")
12531260 if sel [0 ] == '' :
12541261 found = []
12551262 for s in self ._suggestions .get_suggestions ('' ):
@@ -1277,15 +1284,15 @@ def on_content_assist(self, event):
12771284 else :
12781285 found .append (s )
12791286 sugs .update (found )
1280- print (f"DEBUG: texteditor.py SourceEditor on_content_assist VARIABLES SEARCH selection = { sel } \n "
1281- f"sugs={ sugs } " )
1287+ # print(f"DEBUG: texteditor.py SourceEditor on_content_assist VARIABLES SEARCH selection = {sel}\n"
1288+ # f"sugs={sugs}")
12821289 if len (sugs ) > 0 :
12831290 # sugs = [s for s in sugs if s != '']
12841291 if '' in sugs :
12851292 sugs .remove ('' )
12861293 suggestions = ";" .join (sorted (sugs ))
1287- print (f"DEBUG: texteditor.py SourceEditor on_content_assist BEFORE SHOW LIST suggestions = { suggestions } \n "
1288- f" size={ len (suggestions )} cache size={ len (self ._words_cache )} " )
1294+ # print(f"DEBUG: texteditor.py SourceEditor on_content_assist BEFORE SHOW LIST suggestions = {suggestions}\n"
1295+ # f" size={len(suggestions)} cache size={len(self._words_cache)}")
12891296 if len (suggestions ) > 0 : # Consider using contentassist as in Grid Editor
12901297 self .source_editor .AutoCompSetDropRestOfWord (False )
12911298 self .source_editor .AutoCompSetFillUps ('=' )
@@ -1307,17 +1314,24 @@ def on_content_assist(self, event):
13071314 def open (self , data ):
13081315 self .reset ()
13091316 self ._data = data
1310- if self ._data ._doc_language is not None and len (self ._data ._doc_language ) > 0 :
1317+ if hasattr ( self . _data , '_doc_language' ) and self ._data ._doc_language is not None and len (self ._data ._doc_language ) > 0 :
13111318 self .language = self ._data ._doc_language
1319+ elif hasattr (self ._data , '_language' ) and self ._data ._language is not None and len (self ._data ._language ) > 0 :
1320+ self .language = self ._data ._language
13121321 else :
13131322 self .language = ['en' ]
13141323 # print(f"DEBUG: texteditor.py SourceEditor open ENTER language={self.language}")
13151324 try :
1316- if isinstance (self ._data .wrapper_data , ResourceFileController ):
1317- self ._controller_for_context = DummyController (self ._data .wrapper_data , self ._data .wrapper_data )
1318- self ._suggestions = SuggestionSource (self .plugin , self ._controller_for_context )
1325+ if hasattr (self ._data , 'wrapper_data' ):
1326+ if isinstance (self ._data .wrapper_data , ResourceFileController ):
1327+ self ._controller_for_context = DummyController (self ._data .wrapper_data , self ._data .wrapper_data )
1328+ else :
1329+ self ._controller_for_context = self ._data .wrapper_data .tests [0 ]
1330+ elif isinstance (self ._data , ResourceFileController ):
1331+ self ._controller_for_context = self ._data
13191332 else :
1320- self ._suggestions = SuggestionSource (self .plugin , self ._data .wrapper_data .tests [0 ])
1333+ self ._controller_for_context = self ._data .tests [0 ]
1334+ self ._suggestions = SuggestionSource (self .plugin , self ._controller_for_context )
13211335 except IndexError : # It is a new project, no content yet
13221336 self ._controller_for_context = DummyController (self ._data .wrapper_data , self ._data .wrapper_data )
13231337 self ._suggestions = SuggestionSource (self .plugin , self ._controller_for_context )
@@ -1330,7 +1344,8 @@ def open(self, data):
13301344 self ._create_editor_text_control (text = self ._stored_text , language = self .language )
13311345 else :
13321346 self .source_editor .set_language (self .language )
1333- self .source_editor .set_text (self ._data .content )
1347+ if hasattr (self ._data , 'content' ): # Special case for unit test
1348+ self .source_editor .set_text (self ._data .content )
13341349 self .set_editor_caret_position ()
13351350 self ._words_cache .clear ()
13361351 self ._suggestions .update_from_local (self .words_cache (self .source_editor .GetLineCount ()), self .language )
@@ -1472,7 +1487,7 @@ def write_ident(self):
14721487 self .source_editor .WriteText (spaces )
14731488
14741489 def reset (self ):
1475- if self ._data and not self ._data .wrapper_data .is_dirty :
1490+ if self ._data and ( hasattr ( self . _data , 'wrapper_data' ) and not self ._data .wrapper_data .is_dirty ) :
14761491 self .mark_file_dirty (False )
14771492
14781493 def content_save (self , ** args ):
0 commit comments