Jump to conversation
Unresolved conversations (3)
@personalizedrefrigerator personalizedrefrigerator Jan 19, 2024
Changes to `webpack.config.js` are copied from the upstream [`joplin-generator`](https://github.com/laurent22/joplin/blob/dev/packages/generator-joplin/generators/app/templates/webpack.config.js) package. These changes are required to prevent Webpack from duplicating CodeMirror 6 packages (which would cause the extension not to work because globals from one copy are not equal to globals from copy 2).
webpack.config.js
@personalizedrefrigerator personalizedrefrigerator Jan 19, 2024
The contents of `codeMirror5Plugin.ts` are mostly copied (and re-indented) from the original `src/QuickLinksPlugin.ts`.
src/contentScript/codeMirror5Plugin.ts
@personalizedrefrigerator personalizedrefrigerator Jan 19, 2024
## Possible issue Using `override` seems to mean that this won't work well with other CM6 autocompletion plugins (like the [CodeMirror 6 snippets](https://joplinapp.org/plugins/plugin/io.github.personalizedrefrigerator.snippets-and-autocomplete/?from-tab=all) plugin). For example, if another plugin enables code block autocompletion, this will disable it. ## Alternative 1 Here's an alternative: ```suggestion autocompletion(), EditorState.languageData.of(() => ([{ autocomplete: completeMarkdown }])), ``` By default, `autocompletion` gets completions from the [`languageData`](https://codemirror.net/docs/ref/#state.EditorState%5ElanguageData) defined at the cursor. For example, if the cursor is in a JavaScript code block, the user will get JavaScript completions. The above adds global language data that provides autocompletions from `completeMarkdown`. The issue with this is that `autocompletion()` enables completion from `languageData`, so users will also get completions in code blocks (which might not be desirable). **Example with the above change:** [Screen recording: Both code block suggestions and link suggestions are given](https://github.com/roman-r-m/joplin-plugin-quick-links/assets/46334387/cd356150-d9fe-4a2f-95aa-24f3f790e30a) The user may not want autocompletion within code blocks, however. ## Alternative 2 Add a setting ("show suggestions from other sources") to switch between the current implementation and alternative 1. The code might then look like this: ```suggestion useGlobalAutocompleteSetting ? [ autocompletion(), EditorState.languageData.of(() => ([{ autocomplete: completeMarkdown }])), ] : [ autocompletion({ override: [ completeMarkdown ], tooltipClass: () => 'quick-links-completions', }), ] ``` ##
src/contentScript/codeMirror6Plugin.ts
Resolved conversations (0)