Skip to content

Commit

Permalink
e
Browse files Browse the repository at this point in the history
  • Loading branch information
winetree94 committed Dec 21, 2023
1 parent 24ad502 commit f09b6dd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/plugins/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './keymap';
export * from './core';
export * from './drop-cursor';
export * from './gap-cursor';
export * from './reset-mark';
22 changes: 18 additions & 4 deletions packages/core/src/plugins/keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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' &&
Expand All @@ -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(),
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/plugins/reset-mark.ts
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit f09b6dd

Please sign in to comment.