@@ -11,7 +11,7 @@ import {
1111 WidgetType ,
1212} from "@codemirror/view" ;
1313import FrontmatterImagePlugin from "./main" ;
14- import { Pos , TFile } from "obsidian" ;
14+ import { Pos , TFile , editorLivePreviewField } from "obsidian" ;
1515import { getImageSrc , appendFrontmatterImage } from "./utils" ;
1616
1717export interface FrontmatterImageStateFieldValue {
@@ -22,11 +22,6 @@ export interface FrontmatterImageStateFieldValue {
2222export const frontmatterImageEditorExtension = (
2323 plugin : FrontmatterImagePlugin ,
2424) : StateField < FrontmatterImageStateFieldValue | undefined > => {
25- const isLivePreview = ( ) => {
26- const view = EditorView . findFromDOM ( document . body ) ;
27- return view ?. contentDOM . closest ( ".is-live-preview" ) !== null ;
28- } ;
29-
3025 const buildDecorationSet = (
3126 frontmatterPosition : Pos ,
3227 resolvedImageSrc ?: string ,
@@ -65,7 +60,8 @@ export const frontmatterImageEditorExtension = (
6560 ) : FrontmatterImageStateFieldValue | undefined => {
6661 if ( ! oldValue ) return ;
6762
68- if ( ! isLivePreview ( ) ) {
63+ const isLivePreview = transaction . state . field ( editorLivePreviewField ) ;
64+ if ( ! isLivePreview ) {
6965 return { ...oldValue , decorationSet : undefined } ;
7066 }
7167
0 commit comments