diff --git a/package-lock.json b/package-lock.json index 6374ec770b..0af1d0cb1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3145,9 +3145,9 @@ "dev": true }, "node_modules/@codemirror/autocomplete": { - "version": "6.6.0", - "resolved": "git+ssh://git@github.com/overleaf/codemirror-autocomplete.git#cd13c2c15a6f89b207f7cc4523e38fd5ef0efc47", - "integrity": "sha512-Uf8Tv/wLUmPyxTwxrp/+t+f5sognQs+qHyQ+AvCFhS1wWa2Tw9+Ko/84EsPXQpYwTgN8xvejBCSHlRzubogHLA==", + "version": "6.6.1", + "resolved": "git+ssh://git@github.com/overleaf/codemirror-autocomplete.git#4514fd21c6c9219f5c23a6a675ad843bb7a5b2bd", + "integrity": "sha512-3xD9M0e5cw0XsC7mMfRy+vKcOup7Nno4J3r0aTvwWqsUlQYBzT0R3sBEn6y+gHdpIpuSEx+jKIGKiqBsWI8czg==", "license": "MIT", "dependencies": { "@codemirror/language": "^6.0.0", @@ -35165,7 +35165,7 @@ "@babel/preset-env": "^7.14.5", "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.16.0", - "@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#cd13c2c15a6f89b207f7cc4523e38fd5ef0efc47", + "@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#4514fd21c6c9219f5c23a6a675ad843bb7a5b2bd", "@codemirror/commands": "^6.2.3", "@codemirror/lang-markdown": "^6.1.1", "@codemirror/language": "^6.6.0", @@ -39926,9 +39926,9 @@ "dev": true }, "@codemirror/autocomplete": { - "version": "git+ssh://git@github.com/overleaf/codemirror-autocomplete.git#cd13c2c15a6f89b207f7cc4523e38fd5ef0efc47", - "integrity": "sha512-Uf8Tv/wLUmPyxTwxrp/+t+f5sognQs+qHyQ+AvCFhS1wWa2Tw9+Ko/84EsPXQpYwTgN8xvejBCSHlRzubogHLA==", - "from": "@codemirror/autocomplete@github:overleaf/codemirror-autocomplete#cd13c2c15a6f89b207f7cc4523e38fd5ef0efc47", + "version": "git+ssh://git@github.com/overleaf/codemirror-autocomplete.git#4514fd21c6c9219f5c23a6a675ad843bb7a5b2bd", + "integrity": "sha512-3xD9M0e5cw0XsC7mMfRy+vKcOup7Nno4J3r0aTvwWqsUlQYBzT0R3sBEn6y+gHdpIpuSEx+jKIGKiqBsWI8czg==", + "from": "@codemirror/autocomplete@github:overleaf/codemirror-autocomplete#4514fd21c6c9219f5c23a6a675ad843bb7a5b2bd", "requires": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", @@ -44845,7 +44845,7 @@ "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.16.0", "@babel/register": "^7.14.5", - "@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#cd13c2c15a6f89b207f7cc4523e38fd5ef0efc47", + "@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#4514fd21c6c9219f5c23a6a675ad843bb7a5b2bd", "@codemirror/commands": "^6.2.3", "@codemirror/lang-markdown": "^6.1.1", "@codemirror/language": "^6.6.0", diff --git a/services/web/frontend/js/features/source-editor/languages/latex/complete.ts b/services/web/frontend/js/features/source-editor/languages/latex/complete.ts index 76f8f46ba0..9bbdf5031a 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/complete.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/complete.ts @@ -338,16 +338,6 @@ const commandCompletionSource = (context: CompletionContext) => { buildAllCompletions(completions, context) - // ensure that there's only one completion for each label - const uniqueCommandCompletions = Array.from( - new Map( - [ - ...completions.commands, - ...customCommandCompletions(context, completions.commands), - ].map(completion => [completion.label, completion]) - ).values() - ) - // Unknown commands const prefixMatcher = /^\\[^{\s]*$/ const prefixMatch = matchBefore.text.match(prefixMatcher) @@ -356,7 +346,8 @@ const commandCompletionSource = (context: CompletionContext) => { from: matchBefore.from, validFor: prefixMatcher, options: [ - ...uniqueCommandCompletions, + ...completions.commands, + ...customCommandCompletions(context, completions.commands), ...customEnvironmentCompletions(context), ], } @@ -365,7 +356,10 @@ const commandCompletionSource = (context: CompletionContext) => { // anything else (no validFor) return { from: matchBefore.to, - options: uniqueCommandCompletions, + options: [ + ...completions.commands, + ...customCommandCompletions(context, completions.commands), + ], } } diff --git a/services/web/frontend/js/features/source-editor/languages/latex/completions/doc-commands.ts b/services/web/frontend/js/features/source-editor/languages/latex/completions/doc-commands.ts index 03c4b4a92b..a4556f9d7a 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/completions/doc-commands.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/completions/doc-commands.ts @@ -25,7 +25,7 @@ export function customCommandCompletions( output.push({ type: 'cmd', label: item.label, - boost: item.count - 10, + boost: Math.max(0, item.count - 10), apply: applySnippet(item.snippet), extend: extendOverUnpairedClosingBrace, }) diff --git a/services/web/frontend/js/features/source-editor/languages/latex/completions/snippets.ts b/services/web/frontend/js/features/source-editor/languages/latex/completions/snippets.ts index 6555711dda..c7cfb7c83b 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/completions/snippets.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/completions/snippets.ts @@ -12,7 +12,8 @@ export function buildSnippetCompletions(completions: Completions) { type: item.meta, label: item.caption, boost: item.score, - apply: applySnippet(item.snippet), + apply: + item.snippet === item.caption ? undefined : applySnippet(item.snippet), extend: extendOverUnpairedClosingBrace, }) } diff --git a/services/web/frontend/js/features/source-editor/languages/latex/index.ts b/services/web/frontend/js/features/source-editor/languages/latex/index.ts index 6a8c38d48d..b60a89ebd0 100644 --- a/services/web/frontend/js/features/source-editor/languages/latex/index.ts +++ b/services/web/frontend/js/features/source-editor/languages/latex/index.ts @@ -16,13 +16,14 @@ import { documentOutline } from './document-outline' import { LaTeXLanguage } from './latex-language' import { documentEnvironmentNames } from './document-environment-names' -const completionSources = importOverleafModules('sourceEditorCompletionSources') - .map((item: any) => item.import.default) - .concat( - argumentCompletionSources, - inCommandCompletionSource, - explicitCommandCompletionSource - ) as CompletionSource[] +const completionSources: CompletionSource[] = [ + ...argumentCompletionSources, + inCommandCompletionSource, + explicitCommandCompletionSource, + ...importOverleafModules('sourceEditorCompletionSources').map( + (item: any) => item.import.default + ), +] export const latex = () => { return new LanguageSupport(LaTeXLanguage, [ diff --git a/services/web/package.json b/services/web/package.json index 3f6f0fb9c2..6d56e9b052 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -71,7 +71,7 @@ "@babel/preset-env": "^7.14.5", "@babel/preset-react": "^7.14.5", "@babel/preset-typescript": "^7.16.0", - "@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#cd13c2c15a6f89b207f7cc4523e38fd5ef0efc47", + "@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#4514fd21c6c9219f5c23a6a675ad843bb7a5b2bd", "@codemirror/commands": "^6.2.3", "@codemirror/lang-markdown": "^6.1.1", "@codemirror/language": "^6.6.0",