M: Implement projection swap on ctrl + space
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run

This commit is contained in:
Ivan 2024-09-06 15:59:28 +03:00
parent 31fb5b82ef
commit 3d45510cd6
3 changed files with 21 additions and 1 deletions

View File

@ -116,6 +116,22 @@ const RSInput = forwardRef<ReactCodeMirrorRef, RSInputProps>(
if (!selection.empty || !schema) {
return;
}
const wordRange = text.getWord(selection.from);
if (wordRange) {
const word = text.getText(wordRange.from, wordRange.to);
if (word.length > 2 && (word.startsWith('Pr') || word.startsWith('pr'))) {
text.setSelection(wordRange.from, wordRange.from + 2);
if (word.startsWith('Pr')) {
text.replaceWith('pr');
} else {
text.replaceWith('Pr');
}
event.preventDefault();
event.stopPropagation();
return;
}
}
const hint = text.getText(selection.from - 1, selection.from);
const type = guessCstType(hint);
if (hint === getCstTypePrefix(type)) {

View File

@ -94,7 +94,7 @@ function HelpRSEditor() {
<IconTree className='inline-icon' /> отображение{' '}
<LinkTopic text='дерева разбора' topic={HelpTopic.UI_FORMULA_TREE} />
</li>
<li>Ctrl + Пробел дополняет до незанятого имени</li>
<li>Ctrl + Пробел вставка незанятого имени / замена проекции</li>
<h2>Термин и Текстовое определение</h2>
<li>

View File

@ -357,6 +357,10 @@ export class CodeMirrorWrapper {
return this.ref.view.state.doc.sliceString(from, to);
}
getWord(position: number): SelectionRange | null {
return this.ref.view.state.wordAt(position);
}
getSelection(): SelectionRange {
return this.ref.view.state.selection.main;
}