diff --git a/packages/core/src/plugins/core.ts b/packages/core/src/plugins/core.ts index 11e3fc18..85e6d036 100644 --- a/packages/core/src/plugins/core.ts +++ b/packages/core/src/plugins/core.ts @@ -4,12 +4,14 @@ import { edimHistoryPlugins } from './history'; import { edimVirtualCursorPlugins } from './virtual-cursor'; import { edimDropCursorPlugins } from './drop-cursor'; import { edimGapCursorPlugins } from './gap-cursor'; +import { edimResetMarkPlugins } from './reset-mark'; export const edimCorePlugins = (): PMPlugin[] => { return [ ...edimBasicKeymapPlugins(), ...edimHistoryPlugins(), ...edimVirtualCursorPlugins(), + ...edimResetMarkPlugins(), ...edimDropCursorPlugins(), ...edimGapCursorPlugins(), ]; diff --git a/packages/core/src/plugins/index.ts b/packages/core/src/plugins/index.ts index a55b3fde..53dca7f9 100644 --- a/packages/core/src/plugins/index.ts +++ b/packages/core/src/plugins/index.ts @@ -5,3 +5,4 @@ export * from './keymap'; export * from './core'; export * from './drop-cursor'; export * from './gap-cursor'; +export * from './reset-mark'; diff --git a/packages/core/src/plugins/keymap.ts b/packages/core/src/plugins/keymap.ts index 23fdffb2..b104cf24 100644 --- a/packages/core/src/plugins/keymap.ts +++ b/packages/core/src/plugins/keymap.ts @@ -5,6 +5,17 @@ import { clearMarks } from '../commands'; export const edimBasicKeymapPlugins = (): Plugin[] => { return [ + keymap({ + Backspace: (state, dispatch) => { + const selection = state.selection; + + if (!selection.empty || selection.from !== selection.to) { + return false; + } + + return false; + }, + }), keymap({ /** * Switch to the default node of the Schema when the first node is empty. @@ -31,6 +42,8 @@ export const edimBasicKeymapPlugins = (): Plugin[] => { return false; } + let tr = state.tr.setStoredMarks([]); + const firstNodeFromSchema = Object.values(state.schema.nodes).find( (type) => type.spec.group === 'block' && @@ -42,18 +55,19 @@ export const edimBasicKeymapPlugins = (): Plugin[] => { } if (firstNodeFromSchema === firstNode.type) { - return false; + dispatch?.(tr); + return true; } const newNode = firstNodeFromSchema.createAndFill(); if (!newNode) { - return false; + dispatch?.(tr); + return true; } - const tr = state.tr.setNodeMarkup(0, firstNodeFromSchema); + tr = tr.setNodeMarkup(0, firstNodeFromSchema); dispatch?.(tr); - return true; }, 'Mod-\\': clearMarks(), diff --git a/packages/core/src/plugins/reset-mark.ts b/packages/core/src/plugins/reset-mark.ts new file mode 100644 index 00000000..4f0cb160 --- /dev/null +++ b/packages/core/src/plugins/reset-mark.ts @@ -0,0 +1,19 @@ +import { Plugin as PMPlugin } from 'prosemirror-state'; + +export const edimResetMarkPlugins = (): PMPlugin[] => { + const plugins: PMPlugin[] = [ + new PMPlugin({ + // props: { + // handleKeyDown: (view, event) => { + // if (event.key !== 'Backspace') { + // return false; + // } + // console.log('backspace'); + // return false; + // }, + // }, + }), + ]; + + return plugins; +};