Skip to content

Commit

Permalink
🎨 Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelj committed Jan 2, 2024
1 parent c7e342c commit a179744
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions CodeMirror6/NodeLib/src/CmHorizontalRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ import type { DecorationSet } from '@codemirror/view'
import { buildWidget } from './lib/codemirror-kit'
import { isCursorInRange } from './CmHelpers'

const hrWidget = () => buildWidget({
eq: () => false,
toDOM: () => {
const hr = document.createElement('hr');
hr.setAttribute('aria-hidden', 'true');
return hr;
},
})


/**
* Return the horizontal rule Extension if the supplied parameter is true
Expand All @@ -25,8 +16,16 @@ export const dynamicHrExtension = (enabled: boolean = true): Extension => {
if (!enabled)
return []

const hrDecoration = () => Decoration.replace({
widget: hrWidget(),
const createHRDecorationWidget = () => Decoration.replace({
widget: buildWidget({
eq: () => false,
toDOM: () => {
const hr = document.createElement('hr')
hr.setAttribute('aria-hidden', 'true')
return hr
},
ignoreEvent: () => false,
}),
})

const decorate = (state: EditorState) => {
Expand All @@ -41,7 +40,7 @@ export const dynamicHrExtension = (enabled: boolean = true): Extension => {
const hrRegex = /^-{3,}$/

if (hrRegex.test(lineText)) {
widgets.push(hrDecoration().range(line.from, line.to))
widgets.push(createHRDecorationWidget().range(line.from, line.to))
}
}
},
Expand All @@ -52,12 +51,13 @@ export const dynamicHrExtension = (enabled: boolean = true): Extension => {
}

const viewPlugin = ViewPlugin.define(() => ({}), {})

const stateField = StateField.define<DecorationSet>({
create(state) {
return decorate(state)
},
update(_references, { state }) {
return decorate(state)
update(_references, transaction) {
return decorate(transaction.state)
},
provide(field) {
return EditorView.decorations.from(field)
Expand Down
2 changes: 1 addition & 1 deletion CodeMirror6/NodeLib/src/CmMentionsView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { markdownLanguage } from "@codemirror/lang-markdown";
import { markdownLanguage } from "@codemirror/lang-markdown"
import { EditorState, RangeSetBuilder, Extension } from '@codemirror/state'
import { EditorView, ViewPlugin, Decoration } from "@codemirror/view"
import { buildWidget } from "./lib/codemirror-kit"
Expand Down

0 comments on commit a179744

Please sign in to comment.