Răsfoiți Sursa

add key bindings for blockquote, bullet list, numbered list, link, bold, italic, strikethrough, and code formatting

WNomunomu 9 luni în urmă
părinte
comite
001f49bafd

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/insert-blockquote.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertPrefix } from '../insert-prefix';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useInsertBlockquoteKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertPrefix = useInsertPrefix(view);
+
+  const insertBlockquoteCommand = generateAddMarkdownSymbolCommand(insertPrefix, '>');
+
+  const insertBlockquoteKeyBinding = { key: 'mod-shift-9', run: insertBlockquoteCommand };
+
+  return insertBlockquoteKeyBinding;
+};

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/insert-bullet-list.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertPrefix } from '../insert-prefix';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useInsertBulletListKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertPrefix = useInsertPrefix(view);
+
+  const insertBulletListCommand = generateAddMarkdownSymbolCommand(insertPrefix, '-');
+
+  const insertBulletListKeyBinding = { key: 'mod-shift-8', run: insertBulletListCommand };
+
+  return insertBulletListKeyBinding;
+};

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/insert-link.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertMarkdownElements } from '../insert-markdown-elements';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useInsertLinkKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertMarkdownElements = useInsertMarkdownElements(view);
+
+  const InsertLinkCommand = generateAddMarkdownSymbolCommand(insertMarkdownElements, '[', ']()');
+
+  const InsertLinkKeyBinding = { key: 'mod-shift-u', run: InsertLinkCommand };
+
+  return InsertLinkKeyBinding;
+};

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/insert-numbered-list.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertPrefix } from '../insert-prefix';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useInsertNumberedKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertPrefix = useInsertPrefix(view);
+
+  const insertNumberedCommand = generateAddMarkdownSymbolCommand(insertPrefix, '1.');
+
+  const insertNumberedKeyBinding = { key: 'mod-shift-7', run: insertNumberedCommand };
+
+  return insertNumberedKeyBinding;
+};

+ 24 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/make-text-bold.ts

@@ -0,0 +1,24 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertMarkdownElements } from '../insert-markdown-elements';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+import type { KeyMapMode } from 'src/consts';
+
+
+export const useMakeTextBoldKeyBinding = (view?: EditorView, keyMapName?: KeyMapMode): KeyBinding => {
+
+  const insertMarkdownElements = useInsertMarkdownElements(view);
+
+  let makeTextBoldKeyBinding: KeyBinding;
+  switch (keyMapName) {
+    case 'vim':
+      makeTextBoldKeyBinding = { key: 'mod-shift-b', run: generateAddMarkdownSymbolCommand(insertMarkdownElements, '**', '**') };
+      break;
+    default:
+      makeTextBoldKeyBinding = { key: 'mod-b', run: generateAddMarkdownSymbolCommand(insertMarkdownElements, '**', '**') };
+  }
+
+  return makeTextBoldKeyBinding;
+};

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/make-text-code.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertMarkdownElements } from '../insert-markdown-elements';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useMakeTextCodeKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertMarkdownElements = useInsertMarkdownElements(view);
+
+  const makeTextCodeCommand = generateAddMarkdownSymbolCommand(insertMarkdownElements, '`', '`');
+
+  const makeTextCodeKeyBinding = { key: 'mod-shift-c', run: makeTextCodeCommand };
+
+  return makeTextCodeKeyBinding;
+};

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/make-text-italic.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertMarkdownElements } from '../insert-markdown-elements';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useMakeTextItalicKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertMarkdownElements = useInsertMarkdownElements(view);
+
+  const makeTextItalicCommand = generateAddMarkdownSymbolCommand(insertMarkdownElements, '*', '*');
+
+  const makeTextItalicKeyBinding = { key: 'mod-shift-i', run: makeTextItalicCommand };
+
+  return makeTextItalicKeyBinding;
+};

+ 17 - 0
packages/editor/src/client/services/use-codemirror-editor/utils/editor-shortcuts/make-text-strikethrough.ts

@@ -0,0 +1,17 @@
+import type { EditorView, KeyBinding } from '@codemirror/view';
+
+import { useInsertMarkdownElements } from '../insert-markdown-elements';
+
+import { generateAddMarkdownSymbolCommand } from './generate-add-markdown-symbol-command';
+
+
+export const useMakeTextStrikethroughKeyBinding = (view?: EditorView): KeyBinding => {
+
+  const insertMarkdownElements = useInsertMarkdownElements(view);
+
+  const makeTextStrikethroughCommand = generateAddMarkdownSymbolCommand(insertMarkdownElements, '~~', '~~');
+
+  const makeTextStrikethroughKeyBinding = { key: 'mod-shift-x', run: makeTextStrikethroughCommand };
+
+  return makeTextStrikethroughKeyBinding;
+};