Skip to content

Commit 06d51b9

Browse files
authored
feat: Multiline Search Support: line breaks \n (#5675)
* add: search/replace line break
1 parent f9c8ed2 commit 06d51b9

File tree

5 files changed

+427
-68
lines changed

5 files changed

+427
-68
lines changed

src/edit_session.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class EditSession {
193193

194194
/**
195195
* Get "widgetManager" from EditSession
196-
*
196+
*
197197
* @returns {LineWidgets} object
198198
*/
199199
get widgetManager() {
@@ -203,18 +203,18 @@ class EditSession {
203203

204204
if (this.$editor)
205205
widgetManager.attach(this.$editor);
206-
206+
207207
return widgetManager;
208208
}
209209

210210
/**
211211
* Set "widgetManager" in EditSession
212-
*
212+
*
213213
* @returns void
214214
*/
215215
set widgetManager(value) {
216216
Object.defineProperty(this, "widgetManager", {
217-
writable: true,
217+
writable: true,
218218
enumerable: true,
219219
configurable: true,
220220
value: value,
@@ -2751,4 +2751,3 @@ config.defineOptions(EditSession.prototype, "session", {
27512751
});
27522752

27532753
exports.EditSession = EditSession;
2754-

src/ext/searchbox.js

+20
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class SearchBox {
5151
this.element = div.firstChild;
5252

5353
this.setSession = this.setSession.bind(this);
54+
this.$onEditorInput = this.onEditorInput.bind(this);
5455

5556
this.$init();
5657
this.setEditor(editor);
@@ -72,6 +73,11 @@ class SearchBox {
7273
this.$syncOptions(true);
7374
}
7475

76+
// Auto update "updateCounter" and "ace_nomatch"
77+
onEditorInput() {
78+
this.find(false, false, true);
79+
}
80+
7581
/**
7682
* @param {HTMLElement} sb
7783
*/
@@ -219,6 +225,15 @@ class SearchBox {
219225
? editor.session.getTextRange(this.searchRange)
220226
: editor.getValue();
221227

228+
/**
229+
* Convert all line ending variations to Unix-style = \n
230+
* Windows (\r\n), MacOS Classic (\r), and Unix (\n)
231+
*/
232+
if (editor.$search.$isMultilineSearch(editor.getLastSearchOptions())) {
233+
value = value.replace(/\r\n|\r|\n/g, "\n");
234+
editor.session.doc.$autoNewLine = "\n";
235+
}
236+
222237
var offset = editor.session.doc.positionToIndex(editor.selection.anchor);
223238
if (this.searchRange)
224239
offset -= editor.session.doc.positionToIndex(this.searchRange.start);
@@ -279,6 +294,7 @@ class SearchBox {
279294
this.active = false;
280295
this.setSearchRange(null);
281296
this.editor.off("changeSession", this.setSession);
297+
this.editor.off("input", this.$onEditorInput);
282298

283299
this.element.style.display = "none";
284300
this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb);
@@ -292,9 +308,13 @@ class SearchBox {
292308
show(value, isReplace) {
293309
this.active = true;
294310
this.editor.on("changeSession", this.setSession);
311+
this.editor.on("input", this.$onEditorInput);
295312
this.element.style.display = "";
296313
this.replaceOption.checked = isReplace;
297314

315+
if (this.editor.$search.$options.regExp)
316+
value = lang.escapeRegExp(value);
317+
298318
if (value)
299319
this.searchInput.value = value;
300320

0 commit comments

Comments
 (0)