Use the editorLivePreviewField state field

This commit is contained in:
Benji Grant 2024-08-21 10:51:04 +10:00
parent f115da2d6d
commit f6ce7a3430
No known key found for this signature in database
GPG key ID: 669D43F2AB2F4F1B
2 changed files with 7 additions and 2 deletions

5
.changes/state-field.md Normal file
View file

@ -0,0 +1,5 @@
---
"obsidian-css-inlay-colors": patch:fix
---
Use the provided Obsidian state field to determine if the editor is in live preview mode

View file

@ -10,6 +10,7 @@ import {
} from '@codemirror/view'
import type { NodeProp } from '@lezer/common'
import { type Color, formatHex, parse } from 'culori'
import { editorLivePreviewField } from 'obsidian'
import { formatColor } from './formatColor'
export const inlayExtension = (colorPickerEnabled: boolean) => {
@ -92,8 +93,7 @@ class CSSColorInlayWidget extends WidgetType {
const createColorWidgets = (view: EditorView, colorPickerEnabled: boolean) => {
// Only create widgets in live preview mode
if (!view.dom.parentElement?.classList.contains('is-live-preview'))
return Decoration.none
if (!view.state.field(editorLivePreviewField)) return Decoration.none
const widgets: Range<Decoration>[] = []