From d4c2c03b6792a42bba45eb1c5827862b2eb26c19 Mon Sep 17 00:00:00 2001 From: FelisDiligens <47528453+FelisDiligens@users.noreply.github.com> Date: Wed, 25 Jan 2023 08:27:16 +0000 Subject: [PATCH] Fix: Markdown viewer does get updated after replacement now. --- src/cmPlugin.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cmPlugin.ts b/src/cmPlugin.ts index 7037aec..4e48352 100644 --- a/src/cmPlugin.ts +++ b/src/cmPlugin.ts @@ -78,9 +78,10 @@ module.exports = { // Get editor and cursor: - let cm: Editor = this; - let cursor = cm.getCursor(); - let lastPos = {line: cm.lastLine(), ch: cm.getLine(cm.lastLine()).length}; + let cm: Editor = this; + let cursor: Position = cm.getCursor(); + let firstPos: Position = {line: 0, ch: 0}; + let lastPos: Position = {line: cm.lastLine(), ch: cm.getLine(cm.lastLine()).length}; /* * Search and replace: @@ -88,6 +89,7 @@ module.exports = { // "Replace all" if (replaceAll) { + // let content = cm.getRange(firstPos, lastPos); let content = cm.getValue(); // Nothing found? @@ -101,7 +103,10 @@ module.exports = { } content = content.replace(regexPattern, preparedReplacement); - cm.setValue(content); + + // Using replaceRange, because otherwise the Markdown viewer does not get updated: + // cm.setValue(content); + cm.replaceRange(content, firstPos, lastPos); // Set previous cursor position: cm.setCursor(cursor);