@@ -556,19 +556,22 @@ def redo(Event=None):
556556
557557 setSaveStatus (False , current_tab )
558558
559- def updatePreview (Event = None ):
559+ def updatePreview (Event = None , override = False ):
560560 current_tab = getCurrentTab ()
561561 if current_tab == - 1 :
562- return None
563-
564- try :
565- # Update the preview
566- frame .load_html (markdown (textboxes [current_tab ].get ("1.0" , tk .END )))
567- except :
568- # Only update it if it's markdown or none
569- if file_extensions [current_tab ] == "md" :
570- # If the preview window was opened manually
571- previewWindowCreation ()
562+ try :
563+ frame .load_html (markdown ("" ))
564+ except :
565+ return None
566+ else :
567+ try :
568+ # Update the preview
569+ frame .load_html (markdown (textboxes [current_tab ].get ("1.0" , tk .END )))
570+ except :
571+ # Only update it if it's markdown or none
572+ if file_extensions [current_tab ] == "md" and not override :
573+ # If the preview window was opened manually
574+ previewWindowCreation ()
572575
573576def trackChanges (Event = None , override = False ):
574577 global prev_key
@@ -606,7 +609,7 @@ def trackChanges(Event=None, override=False):
606609 file_histories [current_tab ][current_versions [current_tab ]] = file_histories [current_tab ][current_versions [current_tab ]][:- 1 ]
607610
608611 # Update the preview
609- updatePreview ()
612+ updatePreview (override = True )
610613
611614def cut (Event = None ):
612615 current_tab = getCurrentTab ()
@@ -921,6 +924,8 @@ def addNewTab(Event=None):
921924 tab_panes .select (tab_panes .tabs ()[- 1 ])
922925 textboxes [- 1 ].focus ()
923926
927+ updatePreview ()
928+
924929 return "break"
925930
926931def closeCurrentTab (Event = None ):
@@ -947,6 +952,8 @@ def closeCurrentTab(Event=None):
947952 file_format_tag_nums .pop (current_tab )
948953 saved .pop (current_tab )
949954
955+ updatePreview ()
956+
950957def getCurrentTab () -> int :
951958 try :
952959 return tab_panes .index ("current" )
@@ -970,6 +977,7 @@ Window Items
970977tab_panes = ttk .Notebook (root , cursor = "hand2" , padding = 5 )
971978tab_panes .pack (side = tk .TOP , fill = tk .BOTH , expand = 1 )
972979tab_panes .enable_traversal ()
980+ tab_panes .bind ("<<NotebookTabChanged>>" , updatePreview ) # https://stackoverflow.com/a/44092163
973981
974982# Create the first tab
975983addNewTab ()
@@ -1083,21 +1091,21 @@ editmenu.add_command(label="Edit Preferences", command=openPreferences)
10831091textfontmenu .add_command (label = "Arial" )
10841092
10851093textsizemenu .add_command (label = "Increase Font Size" , accelerator = "Ctrl+Shift++" , command = increaseFont )
1086- root .bind_all ("<Control-+>" , increaseFont )
1094+ tab_panes .bind_all ("<Control-+>" , increaseFont )
10871095
10881096textsizemenu .add_command (label = "Decrease Font Size" , accelerator = "Ctrl+Shift+-" , command = decreaseFont )
1089- root .bind_all ("<Control-_>" , decreaseFont )
1097+ tab_panes .bind_all ("<Control-_>" , decreaseFont )
10901098
10911099formatmenu .add_command (label = "Text Colour" , command = changeTextColour )
10921100
10931101textstylemenu .add_command (label = "Normal" , accelerator = "Alt+N" , command = changeToNormal )
1094- root .bind_all ("<Alt-n>" , changeToNormal )
1102+ tab_panes .bind_all ("<Alt-n>" , changeToNormal )
10951103
10961104textstylemenu .add_command (label = "Bold" , accelerator = "Ctrl+B" , command = changeToBold )
1097- root .bind_all ("<Control-b>" , changeToBold )
1105+ tab_panes .bind_all ("<Control-b>" , changeToBold )
10981106
10991107textstylemenu .add_command (label = "Italic" , accelerator = "Ctrl+I" , command = changeToItalic )
1100- root .bind ("<Control-i>" , changeToItalic )
1108+ tab_panes .bind ("<Control-i>" , changeToItalic )
11011109
11021110if update :
11031111 helpmenu .add_command (label = "Update Encryptext" , command = updateMenu )
0 commit comments