diff --git a/.eslintignore b/.eslintignore index c2862b719..8c8e96a37 100644 --- a/.eslintignore +++ b/.eslintignore @@ -505,6 +505,7 @@ packages/editor/CodeMirror/editorCommands/editorCommands.js packages/editor/CodeMirror/editorCommands/supportsCommand.js packages/editor/CodeMirror/editorCommands/swapLine.js packages/editor/CodeMirror/getScrollFraction.js +packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.js packages/editor/CodeMirror/markdown/computeSelectionFormatting.js packages/editor/CodeMirror/markdown/decoratorExtension.js packages/editor/CodeMirror/markdown/markdownCommands.bulletedVsChecklist.test.js diff --git a/.gitignore b/.gitignore index f983f2af5..ab9bdef23 100644 --- a/.gitignore +++ b/.gitignore @@ -491,6 +491,7 @@ packages/editor/CodeMirror/editorCommands/editorCommands.js packages/editor/CodeMirror/editorCommands/supportsCommand.js packages/editor/CodeMirror/editorCommands/swapLine.js packages/editor/CodeMirror/getScrollFraction.js +packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.js packages/editor/CodeMirror/markdown/computeSelectionFormatting.js packages/editor/CodeMirror/markdown/decoratorExtension.js packages/editor/CodeMirror/markdown/markdownCommands.bulletedVsChecklist.test.js diff --git a/packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.ts b/packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.ts new file mode 100644 index 000000000..09c6c332b --- /dev/null +++ b/packages/editor/CodeMirror/markdown/computeSelectionFormatting.test.ts @@ -0,0 +1,21 @@ +import { EditorSelection } from '@codemirror/state'; +import createTestEditor from '../testUtil/createTestEditor'; +import computeSelectionFormatting from './computeSelectionFormatting'; + + +describe('computeSelectionFormatting', () => { + // The below tests rely on CodeMirror to correctly parse the document, which + // can be buggy (and fail very rarely). + jest.retryTimes(2); + + it('should correctly compute formatting for partial links', async () => { + // Start with the selection midway through the link + const editor = await createTestEditor('A [partial link]', EditorSelection.cursor(4), ['Link']); + + const formatting = computeSelectionFormatting(editor.state, false); + expect(formatting.linkData).toMatchObject({ + linkText: null, + linkURL: null, + }); + }); +}); diff --git a/packages/editor/CodeMirror/markdown/computeSelectionFormatting.ts b/packages/editor/CodeMirror/markdown/computeSelectionFormatting.ts index bfd7c7430..85fbd3cc4 100644 --- a/packages/editor/CodeMirror/markdown/computeSelectionFormatting.ts +++ b/packages/editor/CodeMirror/markdown/computeSelectionFormatting.ts @@ -20,7 +20,10 @@ const computeSelectionFormatting = (state: EditorState, globalSpellcheck: boolea }; } - return null; + return { + linkText: null, + linkURL: null, + }; }; // Find nodes that overlap/are within the selected region