From 3d45510cd675741a9671b2e109fa3855f09b8e53 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:59:28 +0300 Subject: [PATCH] M: Implement projection swap on ctrl + space --- .../frontend/src/components/RSInput/RSInput.tsx | 16 ++++++++++++++++ .../pages/ManualsPage/items/ui/HelpRSEditor.tsx | 2 +- rsconcept/frontend/src/utils/codemirror.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rsconcept/frontend/src/components/RSInput/RSInput.tsx b/rsconcept/frontend/src/components/RSInput/RSInput.tsx index e7a114d1..c49a72fe 100644 --- a/rsconcept/frontend/src/components/RSInput/RSInput.tsx +++ b/rsconcept/frontend/src/components/RSInput/RSInput.tsx @@ -116,6 +116,22 @@ const RSInput = forwardRef( 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)) { diff --git a/rsconcept/frontend/src/pages/ManualsPage/items/ui/HelpRSEditor.tsx b/rsconcept/frontend/src/pages/ManualsPage/items/ui/HelpRSEditor.tsx index 8f459513..c550639d 100644 --- a/rsconcept/frontend/src/pages/ManualsPage/items/ui/HelpRSEditor.tsx +++ b/rsconcept/frontend/src/pages/ManualsPage/items/ui/HelpRSEditor.tsx @@ -94,7 +94,7 @@ function HelpRSEditor() { отображение{' '} -
  • Ctrl + Пробел дополняет до незанятого имени
  • +
  • Ctrl + Пробел вставка незанятого имени / замена проекции
  • Термин и Текстовое определение

  • diff --git a/rsconcept/frontend/src/utils/codemirror.ts b/rsconcept/frontend/src/utils/codemirror.ts index 6c7b996b..88d180f3 100644 --- a/rsconcept/frontend/src/utils/codemirror.ts +++ b/rsconcept/frontend/src/utils/codemirror.ts @@ -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; }