Skip to content

Commit

Permalink
fix: toolbar disappears when switching between views (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgurney committed Oct 17, 2024
1 parent 5dc0e74 commit 1b3e372
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ export default class NoteToolbarPlugin extends Plugin {
settings: NoteToolbarSettings;
settingsManager: SettingsManager;

// track the last opened file, to reduce unneccessary re-renders
// track the last opened layout state, to reduce unneccessary re-renders
lastFileOpenedOnLayoutChange: TFile | null | undefined;
lastViewModeOnLayoutChange: MarkdownViewModeType | undefined;
// track the last used callout link, for the menu URI
lastCalloutLink: Element | null = null;
// track the plugins available, to help with rendering edge cases
Expand Down Expand Up @@ -201,11 +202,14 @@ export default class NoteToolbarPlugin extends Plugin {
let viewMode = currentView?.getMode();
debugLog('===== LAYOUT-CHANGE ===== ', currentView?.file?.name, currentView, viewMode);
// partial fix for Hover Editor bug where toolbar is redrawn if in Properties position (#14)
if (this.lastFileOpenedOnLayoutChange !== currentView?.file) {
this.lastFileOpenedOnLayoutChange = currentView?.file;
const fileChanged = this.lastFileOpenedOnLayoutChange !== currentView?.file;
const viewModeChanged = this.lastViewModeOnLayoutChange !== viewMode;
if (fileChanged || viewModeChanged) {
this.lastFileOpenedOnLayoutChange = fileChanged ? currentView?.file : this.lastFileOpenedOnLayoutChange;
this.lastViewModeOnLayoutChange = viewModeChanged ? viewMode : this.lastViewModeOnLayoutChange;
}
else {
return; // this isn't a new file, so do nothing
return; // no changes, so do nothing
}
// check for editing or reading mode
switch(viewMode) {
Expand Down

0 comments on commit 1b3e372

Please sign in to comment.