@@ -340,6 +340,36 @@ def __init__(self, flist=None, filename=None, key=None, root=None):
340340 self .askinteger = tkSimpleDialog .askinteger
341341 self .showerror = tkMessageBox .showerror
342342
343+ self ._highlight_workaround () # Fix selection tags on Windows
344+
345+ def _highlight_workaround (self ):
346+ # On Windows, Tk removes painting of the selection
347+ # tags which is different behavior than on Linux and Mac.
348+ # See issue14146 for more information.
349+ if not sys .platform .startswith ('win' ):
350+ return
351+
352+ text = self .text
353+ text .event_add ("<<Highlight-FocusOut>>" , "<FocusOut>" )
354+ text .event_add ("<<Highlight-FocusIn>>" , "<FocusIn>" )
355+ def highlight_fix (focus ):
356+ sel_range = text .tag_ranges ("sel" )
357+ if sel_range :
358+ if focus == 'out' :
359+ HILITE_CONFIG = idleConf .GetHighlight (
360+ idleConf .CurrentTheme (), 'hilite' )
361+ text .tag_config ("sel_fix" , HILITE_CONFIG )
362+ text .tag_raise ("sel_fix" )
363+ text .tag_add ("sel_fix" , * sel_range )
364+ elif focus == 'in' :
365+ text .tag_remove ("sel_fix" , "1.0" , "end" )
366+
367+ text .bind ("<<Highlight-FocusOut>>" ,
368+ lambda ev : highlight_fix ("out" ))
369+ text .bind ("<<Highlight-FocusIn>>" ,
370+ lambda ev : highlight_fix ("in" ))
371+
372+
343373 def _filename_to_unicode (self , filename ):
344374 """convert filename to unicode in order to display it in Tk"""
345375 if isinstance (filename , str ) or not filename :
0 commit comments