Skip to content

Commit

Permalink
fix: issue with source mod and double rendering (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed Apr 7, 2024
1 parent c08ee19 commit 6774389
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/@types/obsidian.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TAbstractFile, TFile, View, WorkspaceLeaf } from 'obsidian';
import { TAbstractFile, TFile, View, ViewState, WorkspaceLeaf } from 'obsidian';

interface InternalPlugin {
enabled: boolean;
Expand Down Expand Up @@ -82,10 +82,18 @@ interface DomChild {
containerEl: HTMLElement;
}

interface ExplorerViewState extends ViewState {
state: {
source: boolean; // true if source view is active
};
}

interface ExplorerView extends View {
fileItems: Record<string, FileItem>; // keyed by path
ready: boolean; // true if fileItems is populated
file?: TFile;
getViewState(): ExplorerViewState;
getMode(): 'source' | 'preview';
dom: { children: DomChild[]; changed: () => void };
}

Expand Down
8 changes: 8 additions & 0 deletions src/editor/live-preview/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@codemirror/state';
import IconFolderPlugin from '@app/main';
import emoji from '@app/emoji';
import { ExplorerViewState } from '@app/@types/obsidian';

export type PositionField = StateField<RangeSet<IconPosition>>;

Expand Down Expand Up @@ -54,6 +55,13 @@ export const buildPositionField = (plugin: IconFolderPlugin) => {
excludeTo: number,
updateRange: UpdateRangeFunc,
): void => {
const isSourceMode = (
plugin.app.workspace.getLeaf().getViewState() as ExplorerViewState
)?.state?.source;
if (isSourceMode) {
return;
}

const text = state.doc.sliceString(0, state.doc.length);
const identifier = plugin.getSettings().iconIdentifier;
const regex = new RegExp(
Expand Down

0 comments on commit 6774389

Please sign in to comment.