Only show "Jump to command definition" for right-click on command name (#36191)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
GitOrigin-RevId: 05811783a327fb641f6c677eaa1efeb8a87668fc
This commit is contained in:
Alf Eaton
2026-09-17 11:50:57 +00:00
committed by Copybot
co-authored by Claude Fable 5
parent 1681343782
commit 10f10ca95f
3 changed files with 76 additions and 24 deletions
@@ -0,0 +1,47 @@
import { LanguageSupport } from '@codemirror/language'
import { EditorState } from '@codemirror/state'
import { expect } from 'chai'
import { commandNameAtPos } from '@/features/source-editor/utils/command-definitions/command-name-at-pos'
import { LaTeXLanguage } from '@/features/source-editor/languages/latex/latex-language'
const latex = new LanguageSupport(LaTeXLanguage)
const makeState = (doc: string): EditorState =>
EditorState.create({ doc, extensions: [latex] })
describe('commandNameAtPos', function () {
it('resolves the command name when the position is on the command', function () {
const doc = 'before \\mycmd{arg} after'
const state = makeState(doc)
const from = doc.indexOf('\\mycmd')
expect(commandNameAtPos(state, from)).to.equal('\\mycmd')
expect(commandNameAtPos(state, from + 3)).to.equal('\\mycmd')
})
it('resolves a known command name', function () {
const doc = 'some \\textbf{bold} text'
const state = makeState(doc)
expect(commandNameAtPos(state, doc.indexOf('\\textbf'))).to.equal(
'\\textbf'
)
})
it('returns null for a control symbol', function () {
const doc = 'linebreak \\\\ and \\% percent'
const state = makeState(doc)
expect(commandNameAtPos(state, doc.indexOf('\\\\'))).to.equal(null)
expect(commandNameAtPos(state, doc.indexOf('\\%'))).to.equal(null)
})
it('returns null on plain text', function () {
const doc = 'plain text \\mycmd{arg}'
const state = makeState(doc)
expect(commandNameAtPos(state, 0)).to.equal(null)
})
it("returns null inside a command's argument", function () {
const doc = '\\mycmd{argument}'
const state = makeState(doc)
expect(commandNameAtPos(state, doc.indexOf('argument') + 3)).to.equal(null)
})
})