Going thought the stuff listed here
But I still have an error - my codemirror state is not being created. I am using a lot of extensions when defining state - so my guess is this is where the error is.
I am guessing it could be one of these
Plugin fields no longer exist, and providing decorations from a view plugin now happens by providing a function to the EditorView.decorations facet. Same for atomic ranges and scroll margins — you must use a facet for them now.
HighlightStyles objects no longer directly act as editor extensions, but have to be wrapped with the syntaxHighlighting function first.
Any tips on how I can upgrade cleanly? I am kind of lost on what is going wrong.
I am using these extensions.
import { highlightSpecialChars, drawSelection, keymap, EditorView, rectangularSelection } from '@codemirror/view';
import { EditorState } from '@codemirror/state';
import { indentOnInput, bracketMatching, defaultHighlightStyle } from '@codemirror/language';
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
import { closeBrackets, closeBracketsKeymap } from '@codemirror/autocomplete';
const customSetup = [
/*@__PURE__*/highlightSpecialChars(),
/*@__PURE__*/history(),
/*@__PURE__*/drawSelection(),
EditorView.lineWrapping,
/*@__PURE__*/EditorState.allowMultipleSelections.of(true),
/*@__PURE__*/indentOnInput(),
defaultHighlightStyle.fallback,
/*@__PURE__*/bracketMatching(),
/*@__PURE__*/closeBrackets(),
/*@__PURE__*/rectangularSelection(),
/*@__PURE__*/keymap.of([
...closeBracketsKeymap,
...defaultKeymap,
...historyKeymap,
]),
];
export { customSetup };
I am also using the placeholder
extension with some changes to its logic.
class Placeholder extends WidgetType {
constructor(content) {
super();
this.content = content;
}
toDOM() {
const wrap = document.createElement('span');
wrap.className = 'cm-placeholder';
wrap.style.pointerEvents = 'none';
wrap.appendChild(typeof this.content === 'string' ? document.createTextNode(this.content) : this.content);
if (typeof this.content === 'string') {
wrap.setAttribute('aria-label', `placeholder ${this.content}`);
} else {
wrap.setAttribute('aria-hidden', 'true');
}
return wrap;
}
ignoreEvent() { return false; }
}
const customPlaceholder = (content) => {
return ViewPlugin.fromClass(class {
constructor(view) {
this.view = view;
this.placeholder = Decoration.set([Decoration.widget({ widget: new Placeholder(content), side: 1 }).range(0)]);
}
get decorations() {
const startPosOfActiveLine = 1; // gets start position of active line -
this.placeholder = Decoration.set([Decoration.widget({ widget: new Placeholder(content), side: 1 }).range(startPosOfActiveLine)]);
return true ? this.placeholder : Decoration.none;
}
}, { decorations: (v) => v.decorations });
};