Skip to content

Commit

Permalink
fix: move history keymaps to keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jan 18, 2021
1 parent 21ed62d commit 107062f
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/lib/defaultPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ const buildInputRules = (schema: Schema): Plugin => {
};

const getKeyboardShortcuts = (schema: Schema) => {
const historyKeyMap: Record<string, any> = {};

historyKeyMap['Mod-z'] = undo;
if (isMacOs) {
historyKeyMap['Shift-Mod-z'] = redo;
} else {
historyKeyMap['Mod-y'] = redo;
}

return [
keymap({
'Mod-b': toggleMark(schema.marks.strong),
Expand All @@ -95,29 +104,11 @@ const getKeyboardShortcuts = (schema: Schema) => {
'Mod-]': sinkListItem(schema.nodes.list_item),
Tab: sinkListItem(schema.nodes.list_item)
}),
keymap(baseKeymap)
keymap(baseKeymap),
keymap(historyKeyMap)
];
};

const getHistoryPlugins = (): Plugin[] => {
const plugins: Plugin[] = [];

const keyMappings: Record<string, any> = {};

keyMappings['Mod-z'] = undo;
if (isMacOs) {
keyMappings['Shift-Mod-z'] = redo;
} else {
keyMappings['Mod-y'] = redo;
}

plugins.push(history());
plugins.push(keymap(keyMappings));
plugins.push(keymap(keyMappings));

return plugins;
};

const getDefaultPlugins = (schema: Schema, options: Options) => {
const plugins: Plugin[] = [];

Expand All @@ -126,7 +117,7 @@ const getDefaultPlugins = (schema: Schema, options: Options) => {
}

if (options.history) {
plugins.push(...getHistoryPlugins());
plugins.push(history());
}

if (options.inputRules) {
Expand Down

0 comments on commit 107062f

Please sign in to comment.