Skip to content

Commit

Permalink
Fix: Markdown viewer does get updated after replacement now.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisDiligens committed Jan 25, 2023
1 parent b9fe53b commit d4c2c03
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/cmPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ 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:
*/

// "Replace all"
if (replaceAll) {
// let content = cm.getRange(firstPos, lastPos);
let content = cm.getValue();

// Nothing found?
Expand All @@ -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);
Expand Down

0 comments on commit d4c2c03

Please sign in to comment.