From 746f4e415021257d275c847c578d181dbe90276e Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 17 Apr 2023 22:26:36 -0400 Subject: [PATCH] fix: Allow strikethrough of inline code (#5207 * fix: Allow strikethrough of inline code * Remove unneccessary change --- shared/editor/lib/ExtensionManager.ts | 37 ++++++++++++++++++--------- shared/editor/marks/Code.ts | 13 +++++++--- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/shared/editor/lib/ExtensionManager.ts b/shared/editor/lib/ExtensionManager.ts index 9f73c1226..06e7546df 100644 --- a/shared/editor/lib/ExtensionManager.ts +++ b/shared/editor/lib/ExtensionManager.ts @@ -52,6 +52,31 @@ export default class ExtensionManager { ); } + get marks() { + const marks = this.extensions + .filter((extension) => extension.type === "mark") + .reduce( + (marks, mark: Mark) => ({ + ...marks, + [mark.name]: mark.schema, + }), + {} + ); + + for (const i in marks) { + if (marks[i].excludes) { + // We must filter marks from the excludes list that are not defined + // in the schema for the current editor. + marks[i].excludes = marks[i].excludes + .split(" ") + .filter((m: string) => Object.keys(marks).includes(m)) + .join(" "); + } + } + + return marks; + } + serializer() { const nodes = this.extensions .filter((extension) => extension.type === "node") @@ -104,18 +129,6 @@ export default class ExtensionManager { return new MarkdownParser(schema, makeRules({ rules, plugins }), tokens); } - get marks() { - return this.extensions - .filter((extension) => extension.type === "mark") - .reduce( - (marks, { name, schema }: Mark) => ({ - ...marks, - [name]: schema, - }), - {} - ); - } - get plugins() { return this.extensions .filter((extension) => "plugins" in extension) diff --git a/shared/editor/marks/Code.ts b/shared/editor/marks/Code.ts index 662399b3c..ed9dac321 100644 --- a/shared/editor/marks/Code.ts +++ b/shared/editor/marks/Code.ts @@ -4,8 +4,10 @@ import { MarkType, Node as ProsemirrorNode, Mark as ProsemirrorMark, + Slice, } from "prosemirror-model"; import { Plugin } from "prosemirror-state"; +import { EditorView } from "prosemirror-view"; import moveLeft from "../commands/moveLeft"; import moveRight from "../commands/moveRight"; import markInputRule from "../lib/markInputRule"; @@ -40,7 +42,7 @@ export default class Code extends Mark { get schema(): MarkSpec { return { - excludes: "_", + excludes: "comment mention link placeholder highlight em strong", parseDOM: [{ tag: "code.inline", preserveWhitespace: true }], toDOM: () => ["code", { class: "inline", spellCheck: "false" }], }; @@ -66,7 +68,12 @@ export default class Code extends Mark { props: { // Typing a character inside of two backticks will wrap the character // in an inline code mark. - handleTextInput: (view, from: number, to: number, text: string) => { + handleTextInput: ( + view: EditorView, + from: number, + to: number, + text: string + ) => { const { state } = view; // Prevent access out of document bounds @@ -99,7 +106,7 @@ export default class Code extends Mark { // Pasting a character inside of two backticks will wrap the character // in an inline code mark. - handlePaste: (view, _event, slice) => { + handlePaste: (view: EditorView, _event: Event, slice: Slice) => { const { state } = view; const { from, to } = state.selection;