mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 00:02:11 +00:00
Only exclude the current command from autocompletion (#14367)
GitOrigin-RevId: 1f1dc0f2c3bcd19b12e06ec56d2d82181b0b5c6d
This commit is contained in:
parent
fbb0ab210e
commit
06aa92d0fd
2 changed files with 23 additions and 4 deletions
|
@ -2,6 +2,7 @@ import { applySnippet, extendOverUnpairedClosingBrace } from './apply'
|
|||
import { Completion, CompletionContext } from '@codemirror/autocomplete'
|
||||
import { documentCommands } from '../document-commands'
|
||||
import { Command } from '../../../utils/tree-operations/commands'
|
||||
import { syntaxTree } from '@codemirror/language'
|
||||
|
||||
const commandNameFromLabel = (label: string): string | undefined =>
|
||||
label.match(/^\\\w+/)?.[0]
|
||||
|
@ -36,9 +37,8 @@ export function customCommandCompletions(
|
|||
}
|
||||
|
||||
const countCommandUsage = (context: CompletionContext) => {
|
||||
const { doc } = context.state
|
||||
|
||||
const excludeLineNumber = doc.lineAt(context.pos).number
|
||||
const tree = syntaxTree(context.state)
|
||||
const currentNode = tree.resolveInner(context.pos, -1)
|
||||
|
||||
const result = new Map<
|
||||
string,
|
||||
|
@ -51,7 +51,7 @@ const countCommandUsage = (context: CompletionContext) => {
|
|||
}
|
||||
|
||||
for (const command of commandListProjection.items) {
|
||||
if (command.line === excludeLineNumber) {
|
||||
if (command.from === currentNode.from) {
|
||||
continue
|
||||
}
|
||||
const label = buildLabel(command)
|
||||
|
|
|
@ -1064,4 +1064,23 @@ describe('autocomplete', { scrollBehavior: false }, function () {
|
|||
cy.findAllByRole('option').contains('sometext.txt').click()
|
||||
activeEditorLine().should('have.text', '\\input{sometext.txt}')
|
||||
})
|
||||
|
||||
it('excludes the current command from completions', function () {
|
||||
const scope = mockScope(mockDocContent(''))
|
||||
|
||||
cy.mount(
|
||||
<Container>
|
||||
<EditorProviders scope={scope}>
|
||||
<CodeMirrorEditor />
|
||||
</EditorProviders>
|
||||
</Container>
|
||||
)
|
||||
|
||||
cy.get('.cm-line').eq(21).type('\\fff \\ff')
|
||||
|
||||
cy.findAllByRole('listbox').should('have.length', 1)
|
||||
cy.findAllByRole('option').contains('\\fff').click()
|
||||
|
||||
cy.get('.cm-line').eq(21).should('have.text', '\\fff \\fff')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue