From 036046734e61da2e6b6c89d3002ea9228935d3fb Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Sun, 13 Aug 2023 21:57:05 +0300 Subject: [PATCH] Fix selection after insert --- rsconcept/frontend/src/components/RSInput/textEditing.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rsconcept/frontend/src/components/RSInput/textEditing.ts b/rsconcept/frontend/src/components/RSInput/textEditing.ts index 8e90fa04..acb0fe5d 100644 --- a/rsconcept/frontend/src/components/RSInput/textEditing.ts +++ b/rsconcept/frontend/src/components/RSInput/textEditing.ts @@ -68,6 +68,7 @@ export class TextWrapper { } insertToken(tokenID: TokenID): boolean { + const hasSelection = this.ref.view.state.selection.main.from !== this.ref.view.state.selection.main.to switch (tokenID) { case TokenID.NT_DECLARATIVE_EXPR: this.envelopeWith('D{ξ∈X1 | P1[ξ]', '}'); return true; case TokenID.NT_IMPERATIVE_EXPR: this.envelopeWith('I{(σ, γ) | σ:∈X1; γ:=F1[σ]; P1[σ, γ]', '}'); return true; @@ -84,7 +85,7 @@ export class TextWrapper { this.envelopeWith('(', ')'); this.ref.view.dispatch({ selection: { - anchor: this.ref.view.state.selection.main.from + 1, + anchor: hasSelection ? this.ref.view.state.selection.main.to: this.ref.view.state.selection.main.from + 1, } }); return true; @@ -93,15 +94,14 @@ export class TextWrapper { this.envelopeWith('[', ']'); this.ref.view.dispatch({ selection: { - anchor: this.ref.view.state.selection.main.from + 1, + anchor: hasSelection ? this.ref.view.state.selection.main.to: this.ref.view.state.selection.main.from + 1, } }); return true; } case TokenID.BOOLEAN: { const selStart = this.ref.view.state.selection.main.from; - if (selStart !== this.ref.view.state.selection.main.to && - this.ref.view.state.sliceDoc(selStart, selStart + 1) === 'ℬ') { + if (hasSelection && this.ref.view.state.sliceDoc(selStart, selStart + 1) === 'ℬ') { this.envelopeWith('ℬ', ''); } else { this.envelopeWith('ℬ(', ')');