Skip to content

Commit

Permalink
fix: replace line breaks
Browse files Browse the repository at this point in the history
replace:
- `\n` with `{empty}`
- `\n{2}` with `\n`
- `\n+` with `\n`
  • Loading branch information
sekedus committed Nov 16, 2024
1 parent 2c5dbeb commit 02bc602
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/ext/searchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SearchBox {
? editor.session.getTextRange(this.searchRange)
: editor.getValue();

if (editor.$search.$isMultilineSearch(editor.$search.$options))
if (editor.$search.$isMultilineSearch(editor.getLastSearchOptions()))
value = value.replace(/\r\n|\r|\n/g, "\n");

var offset = editor.session.doc.positionToIndex(editor.selection.anchor);
Expand Down Expand Up @@ -260,17 +260,24 @@ class SearchBox {
}
replace() {
if (!this.editor.getReadOnly())
this.editor.replace(this.replaceInput.value);
this.editor.replace(this.replaceMultiline(this.replaceInput.value));
}
replaceAndFindNext() {
if (!this.editor.getReadOnly()) {
this.editor.replace(this.replaceInput.value);
this.editor.replace(this.replaceMultiline(this.replaceInput.value));
this.findNext();
}
}
replaceAll() {
if (!this.editor.getReadOnly())
this.editor.replaceAll(this.replaceInput.value);
this.editor.replaceAll(this.replaceMultiline(this.replaceInput.value));
}
replaceMultiline(text) {
if (this.editor.$search.$isMultilineSearch(this.editor.getLastSearchOptions())) {
return text.replace(/\\n/g, '\n');
} else {
return text;
}
}

hide() {
Expand Down
2 changes: 1 addition & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Search {
input = input.replace(/\r\n|\r|\n/g, "\n");

var match = re.exec(input);
if (!match || match[0].length != input.length)
if (!match || (!this.$isMultilineSearch(options) && match[0].length != input.length))
return null;
if (!options.regExp) {
replacement = replacement.replace(/\$/g, "$$$$");
Expand Down

0 comments on commit 02bc602

Please sign in to comment.