mirror of
https://github.com/signynt/virtual-content.git
synced 2026-07-22 12:40:27 +00:00
commit
b4fd8ec8ec
1 changed files with 31 additions and 3 deletions
34
main.ts
34
main.ts
|
|
@ -335,6 +335,8 @@ export default class VirtualFooterPlugin extends Plugin {
|
|||
private lastSeparateTabContents: Map<string, { content: string, sourcePath: string }> = new Map();
|
||||
private lastHoveredLink: HTMLElement | null = null;
|
||||
private popoverObserver: MutationObserver | null = null;
|
||||
/** Track the last processed file to avoid redundant refreshes on layout-change */
|
||||
private lastProcessedFile: string | null = null;
|
||||
|
||||
/**
|
||||
* Called when the plugin is loaded.
|
||||
|
|
@ -373,17 +375,40 @@ export default class VirtualFooterPlugin extends Plugin {
|
|||
// Define event handlers
|
||||
const handleViewUpdate = () => {
|
||||
// Always trigger an update if the layout is ready.
|
||||
// Used for file-open and layout-change.
|
||||
// Used for file-open.
|
||||
if (this.initialLayoutReadyProcessed) {
|
||||
this.handleActiveViewChange();
|
||||
}
|
||||
};
|
||||
|
||||
const handleLayoutChange = () => {
|
||||
// Only trigger if layout is ready
|
||||
if (!this.initialLayoutReadyProcessed) return;
|
||||
|
||||
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
const currentFile = activeView?.file?.path ?? null;
|
||||
|
||||
// Only refresh if the active file has actually changed
|
||||
if (currentFile !== this.lastProcessedFile) {
|
||||
this.handleActiveViewChange();
|
||||
} else {
|
||||
// console.log(`[VirtualFooter] layout-change Skipped: file not changed (${currentFile})`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFocusChange = () => {
|
||||
// This is the "focus change" or "switching files" part, conditional on the setting.
|
||||
// Used for active-leaf-change.
|
||||
if (this.settings.refreshOnFileOpen && this.initialLayoutReadyProcessed) {
|
||||
this.handleActiveViewChange();
|
||||
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
|
||||
const currentFile = activeView?.file?.path ?? null;
|
||||
|
||||
// Only refresh if the active file has actually changed
|
||||
if (currentFile !== this.lastProcessedFile) {
|
||||
this.handleActiveViewChange();
|
||||
} else {
|
||||
// console.log(`[VirtualFooter] active-leaf-change Skipped: file not changed (${currentFile})`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -392,7 +417,7 @@ export default class VirtualFooterPlugin extends Plugin {
|
|||
this.app.workspace.on('file-open', handleViewUpdate)
|
||||
);
|
||||
this.registerEvent(
|
||||
this.app.workspace.on('layout-change', handleViewUpdate)
|
||||
this.app.workspace.on('layout-change', handleLayoutChange)
|
||||
);
|
||||
this.registerEvent(
|
||||
this.app.workspace.on('active-leaf-change', handleFocusChange)
|
||||
|
|
@ -886,6 +911,9 @@ export default class VirtualFooterPlugin extends Plugin {
|
|||
* @param view The MarkdownView to process.
|
||||
*/
|
||||
private async _processView(view: MarkdownView | null): Promise<void> {
|
||||
if (view?.file) {
|
||||
this.lastProcessedFile = view.file.path;
|
||||
}
|
||||
if (!view || !view.file) {
|
||||
// If 'refresh on focus' is off, we clear the sidebar when focus is lost from a markdown file.
|
||||
// If it's on, we only clear the sidebar if the last markdown file has been closed,
|
||||
|
|
|
|||
Loading…
Reference in a new issue