mirror of
https://github.com/gra0007/obsidian-css-inlay-colors.git
synced 2026-07-22 05:18:59 +00:00
Use tokenClassNodeProp to access the node type
This commit is contained in:
parent
a46567ca3f
commit
8679d8bc52
2 changed files with 15 additions and 2 deletions
5
.changes/node-type.md
Normal file
5
.changes/node-type.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"obsidian-css-inlay-colors": patch:fix
|
||||
---
|
||||
|
||||
Swap to a more robust method of determining the node type in live preview mode
|
||||
12
src/live.ts
12
src/live.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { syntaxTree } from '@codemirror/language'
|
||||
import { syntaxTree, tokenClassNodeProp } from '@codemirror/language'
|
||||
import type { Range } from '@codemirror/state'
|
||||
import {
|
||||
Decoration,
|
||||
|
|
@ -8,6 +8,7 @@ import {
|
|||
type ViewUpdate,
|
||||
WidgetType,
|
||||
} from '@codemirror/view'
|
||||
import type { NodeProp } from '@lezer/common'
|
||||
import { type Color, formatHex, parse } from 'culori'
|
||||
import { formatColor } from './formatColor'
|
||||
|
||||
|
|
@ -93,7 +94,9 @@ const createColorWidgets = (view: EditorView, colorPickerEnabled: boolean) => {
|
|||
from,
|
||||
to,
|
||||
enter: (node) => {
|
||||
if (node.name.includes('inline-code')) {
|
||||
if (
|
||||
node.type.prop(tokenClassNodeProp)?.split(' ').includes('inline-code')
|
||||
) {
|
||||
const text = view.state.sliceDoc(node.from, node.to)
|
||||
|
||||
// Not a valid color
|
||||
|
|
@ -123,3 +126,8 @@ const createColorWidgets = (view: EditorView, colorPickerEnabled: boolean) => {
|
|||
|
||||
return Decoration.set(widgets)
|
||||
}
|
||||
|
||||
// Codemirror does not correctly export a type for this constant, but it does exist
|
||||
declare module '@codemirror/language' {
|
||||
const tokenClassNodeProp: NodeProp<string>
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue