Skip to content

Commit

Permalink
Fix next line matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Baptiste Doderlein committed Mar 21, 2024
1 parent 014341f commit 33e8974
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/js/editor_change.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ let line_with_last = function (instance) {
return -1;
}

// From https://stackoverflow.com/questions/3115150/how-to-escape-regular-expression-special-characters-using-javascript
function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

/**
* Execute the last command in the editor
* @param {CodeMirror} instance - CodeMirror instance
Expand All @@ -347,7 +352,7 @@ let exec_last = function (instance) {
let command = clean_content(beforecur).slice(-1)[0];
let allAfter = clean_content(aftercur);
if (allAfter!=null && allAfter.length>0) {
let possibleNext = [...aftercur.matchAll(allAfter[0])];
let possibleNext = [...aftercur.matchAll(escapeRegExp(allAfter[0]))];
if (possibleNext.length>0) {
instance.setCursor(
instance.posFromIndex(possibleNext[0].index+beforecur.length+allAfter[0].length)
Expand Down

0 comments on commit 33e8974

Please sign in to comment.