From 96a5034714acbe49dc2ddd595158843166ecb7a3 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 10 Jul 2026 23:30:34 +0200 Subject: [PATCH] fix: Long code words can overflow comment bounds (#12961) * fix: Long code words can overflow comment bounds * Add to RevisionViewer --- app/scenes/Collection/components/Overview.tsx | 3 ++- app/scenes/Document/components/Editor.tsx | 6 +++++- app/scenes/Document/components/RevisionViewer.tsx | 2 ++ shared/editor/extensions/CodeWordBreak.ts | 12 ++++++++++++ shared/editor/marks/Code.ts | 2 -- shared/editor/nodes/CodeFence.ts | 2 +- .../CodeHighlightingPlugin.ts} | 0 7 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 shared/editor/extensions/CodeWordBreak.ts rename shared/editor/{extensions/CodeHighlighting.ts => plugins/CodeHighlightingPlugin.ts} (100%) diff --git a/app/scenes/Collection/components/Overview.tsx b/app/scenes/Collection/components/Overview.tsx index 09f991679f..6ec1e0b052 100644 --- a/app/scenes/Collection/components/Overview.tsx +++ b/app/scenes/Collection/components/Overview.tsx @@ -19,8 +19,9 @@ import useCurrentUser from "~/hooks/useCurrentUser"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; import type { Properties } from "~/types"; +import CodeWordBreak from "@shared/editor/extensions/CodeWordBreak"; -const extensions = withUIExtensions(richExtensions); +const extensions = [CodeWordBreak, ...withUIExtensions(richExtensions)]; type Props = { collection: Collection; diff --git a/app/scenes/Document/components/Editor.tsx b/app/scenes/Document/components/Editor.tsx index 553d62da3b..85ce6e8040 100644 --- a/app/scenes/Document/components/Editor.tsx +++ b/app/scenes/Document/components/Editor.tsx @@ -37,8 +37,12 @@ import DocumentTitle from "./DocumentTitle"; import { first } from "es-toolkit/compat"; import { getLangFor } from "~/utils/language"; import useShare from "@shared/hooks/useShare"; +import CodeWordBreak from "@shared/editor/extensions/CodeWordBreak"; -const extensions = withUIExtensions(withComments(richExtensions)); +const extensions = [ + CodeWordBreak, + ...withUIExtensions(withComments(richExtensions)), +]; type Props = Omit & { onChangeTitle: (title: string) => void; diff --git a/app/scenes/Document/components/RevisionViewer.tsx b/app/scenes/Document/components/RevisionViewer.tsx index aae572ac7a..d750f8e514 100644 --- a/app/scenes/Document/components/RevisionViewer.tsx +++ b/app/scenes/Document/components/RevisionViewer.tsx @@ -16,6 +16,7 @@ import useQuery from "~/hooks/useQuery"; import useStores from "~/hooks/useStores"; import { type Editor as TEditor } from "~/editor"; import { ChangesetHelper } from "@shared/editor/lib/ChangesetHelper"; +import CodeWordBreak from "@shared/editor/extensions/CodeWordBreak"; type Props = Omit & { /** The ID of the revision */ @@ -84,6 +85,7 @@ function RevisionViewer(props: Props, ref: React.Ref) { comparisonData ); return [ + CodeWordBreak, ...withComments(richExtensions), ...(showChanges && changeset?.changes ? [new Diff({ changes: changeset?.changes })] diff --git a/shared/editor/extensions/CodeWordBreak.ts b/shared/editor/extensions/CodeWordBreak.ts new file mode 100644 index 0000000000..cb2220e46c --- /dev/null +++ b/shared/editor/extensions/CodeWordBreak.ts @@ -0,0 +1,12 @@ +import { codeWordDecorations } from "../plugins/CodeWordDecorationsPlugin"; +import Extension from "../lib/Extension"; + +export default class CodeWordBreak extends Extension { + get name() { + return "codeWordBreak"; + } + + get plugins() { + return [codeWordDecorations()]; + } +} diff --git a/shared/editor/marks/Code.ts b/shared/editor/marks/Code.ts index 68ed70c1f7..5a3bf58a9e 100644 --- a/shared/editor/marks/Code.ts +++ b/shared/editor/marks/Code.ts @@ -13,7 +13,6 @@ import { markInputRuleForPattern } from "../lib/markInputRule"; import type { MarkdownSerializerState } from "../lib/markdown/serializer"; import { isInCode } from "../queries/isInCode"; import Mark from "./Mark"; -import { codeWordDecorations } from "../plugins/CodeWordDecorationsPlugin"; export default class Code extends Mark { get name() { @@ -110,7 +109,6 @@ export default class Code extends Mark { return [ codeCursorPlugin, - codeWordDecorations(), new Plugin({ props: { // Typing a character inside of two backticks will wrap the character diff --git a/shared/editor/nodes/CodeFence.ts b/shared/editor/nodes/CodeFence.ts index 972ffe7fd5..fc9043b93d 100644 --- a/shared/editor/nodes/CodeFence.ts +++ b/shared/editor/nodes/CodeFence.ts @@ -32,7 +32,7 @@ import { } from "../commands/codeFence"; import { selectAll } from "../commands/selectAll"; import toggleBlockType from "../commands/toggleBlockType"; -import { CodeHighlighting } from "../extensions/CodeHighlighting"; +import { CodeHighlighting } from "../plugins/CodeHighlightingPlugin"; import Mermaid, { pluginKey as mermaidPluginKey, type MermaidState, diff --git a/shared/editor/extensions/CodeHighlighting.ts b/shared/editor/plugins/CodeHighlightingPlugin.ts similarity index 100% rename from shared/editor/extensions/CodeHighlighting.ts rename to shared/editor/plugins/CodeHighlightingPlugin.ts