Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/prosemirror-codemark/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Plugin } from 'prosemirror-state';
import type { PluginSpec } from 'prosemirror-state';
import { Plugin, PluginKey } from 'prosemirror-state';
import { Decoration, DecorationSet } from 'prosemirror-view';
import type { CodemarkState, CursorMetaTr, Options } from './types';
import { getMarkType, pluginKey, safeResolve } from './utils';
import { createInputRule } from './inputRules';
import {
onArrowLeft,
onArrowRight,
Expand All @@ -13,6 +10,9 @@ import {
stepOutside,
stepOutsideNextTrAndPass,
} from './actions';
import { createInputRule } from './inputRules';
import type { CodemarkState, CursorMetaTr, Options } from './types';
import { getMarkType, safeResolve } from './utils';

function toDom(): Node {
const span = document.createElement('span');
Expand All @@ -21,8 +21,9 @@ function toDom(): Node {
}

export function getDecorationPlugin(opts?: Options) {
const pluginKey = opts?.pluginKey || new PluginKey('codemark');
const plugin: Plugin<CodemarkState> = new Plugin({
key: pluginKey,
key: typeof pluginKey === 'string' ? new PluginKey(pluginKey) : pluginKey,
appendTransaction: (trs, oldState, newState) => {
const prev = plugin.getState(oldState) as CodemarkState;
const meta = trs[0]?.getMeta(plugin) as CursorMetaTr | null;
Expand Down
2 changes: 2 additions & 0 deletions packages/prosemirror-codemark/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { PluginKey } from 'prosemirror-state';
import type { MarkType } from 'prosemirror-model';

export type Options = {
markType?: MarkType;
pluginKey?: string | PluginKey;
};

export type CodemarkState = {
Expand Down
3 changes: 0 additions & 3 deletions packages/prosemirror-codemark/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { MarkType, Node } from 'prosemirror-model';
import type { EditorState } from 'prosemirror-state';
import { PluginKey } from 'prosemirror-state';
import type { EditorView } from 'prosemirror-view';
import type { Options } from './types';

export const DEFAULT_ID = 'codemark';
export const MAX_MATCH = 100;
export const pluginKey = new PluginKey(DEFAULT_ID);

export function getMarkType(view: EditorView | EditorState, opts?: Options): MarkType {
if ('schema' in view) return opts?.markType ?? view.schema.marks.code;
Expand Down