From f09b6dd3e55bd557f8318b06ed203945905cc2c7 Mon Sep 17 00:00:00 2001 From: winetree94 Date: Thu, 21 Dec 2023 21:40:30 +0900 Subject: [PATCH] e --- packages/core/src/plugins/core.ts | 2 ++ packages/core/src/plugins/index.ts | 1 + packages/core/src/plugins/keymap.ts | 22 ++++++++++++++++++---- packages/core/src/plugins/reset-mark.ts | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 packages/core/src/plugins/reset-mark.ts 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; +};