Skip to content

Commit

Permalink
Merge pull request #17 from personalizedrefrigerator/pr/fix-cm6-confl…
Browse files Browse the repository at this point in the history
…icts

CodeMirror 6 editor: Fix Quick Links conflict with other autocomplete plugins
  • Loading branch information
roman-r-m committed Mar 5, 2024
2 parents 97ab5db + 856412f commit 4e8ab4b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/contentScript/codeMirror6Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type * as CodeMirrorStateType from '@codemirror/state';

import type { CompletionContext, CompletionResult, Completion } from '@codemirror/autocomplete';
import type { EditorView } from '@codemirror/view';
import type { Extension } from '@codemirror/state';

import { PluginContext } from './types';

Expand Down Expand Up @@ -95,10 +96,22 @@ export default function codeMirror6Plugin(pluginContext: PluginContext, CodeMirr
};
};

let extension: Extension;

if (CodeMirror.joplinExtensions) {
extension = CodeMirror.joplinExtensions.completionSource(completeMarkdown);
} else {
// The override field doesn't work if there are multiple
// plugins that try to use autocomplete. As such, only use it
// if the Joplin autocomplete extension isn't available.
extension = autocompletion({
override: [ completeMarkdown ],
});
}

CodeMirror.addExtension([
extension,
autocompletion({
activateOnTyping: true,
override: [ completeMarkdown ],
tooltipClass: () => 'quick-links-completions',
}),
]);
Expand Down

0 comments on commit 4e8ab4b

Please sign in to comment.