From ebb6e49862f11e285cb1d367140a6a7b6d733ea0 Mon Sep 17 00:00:00 2001 From: Sergey Hayriyan Date: Sun, 2 Mar 2025 23:03:39 +0400 Subject: [PATCH] Smart replace --- main.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.ts b/main.ts index e85098e..ac2a474 100644 --- a/main.ts +++ b/main.ts @@ -247,12 +247,21 @@ class MathTypeSuggest extends EditorSuggest { if (!this.context) return; const editor = this.context.editor; + const lineContent = editor.getLine(this.context.start.line); - editor.replaceRange( - `$${value}$`, - this.context.start, - this.context.end - ); + if (!lineContent.startsWith("$") && !lineContent.endsWith("$")) { + editor.replaceRange( + `$${value}$`, + this.context.start, + this.context.end + ); + } else { + editor.replaceRange( + value, + this.context.start, + this.context.end + ); + } } }