Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Multiline Search Support: line breaks \n #5675

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/edit_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class EditSession {

/**
* Get "widgetManager" from EditSession
*
*
* @returns {LineWidgets} object
*/
get widgetManager() {
Expand All @@ -202,18 +202,18 @@ class EditSession {

if (this.$editor)
widgetManager.attach(this.$editor);

return widgetManager;
}

/**
* Set "widgetManager" in EditSession
*
*
* @returns void
*/
set widgetManager(value) {
Object.defineProperty(this, "widgetManager", {
writable: true,
writable: true,
enumerable: true,
configurable: true,
value: value,
Expand Down Expand Up @@ -2747,4 +2747,3 @@ config.defineOptions(EditSession.prototype, "session", {
});

exports.EditSession = EditSession;

4 changes: 4 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@

// Update cursor because tab characters can influence the cursor position.
this.$cursorChange();

// Updates "updateCounter" and "ace_nomatch" in the search box
if (this.searchBox && this.searchBox.active === true)
this.searchBox.find(false, false, true);

Check warning on line 623 in src/editor.js

View check run for this annotation

Codecov / codecov/patch

src/editor.js#L623

Added line #L623 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this to an input event handler in searchbox, something like editor.on('input', this.$onEditorInput) and remove the listener when deactivating. onDocumentChange can be called multiple times during one edit, and input event debounces that with a timeout.
Also in one of tests add a scenario of changing editor value, e.g.

editor.insert("searchedText") 
setTimeout(function() {
 // verify that search counter have been updated
}, 50)

to prevent coverlay complaining about untested lines

}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/ext/searchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ class SearchBox {
? editor.session.getTextRange(this.searchRange)
: editor.getValue();

/**
* Convert all line ending variations to Unix-style = \n
* Windows (\r\n), MacOS Classic (\r), and Unix (\n)
*/
if (editor.$search.$isMultilineSearch(editor.getLastSearchOptions())) {
value = value.replace(/\r\n|\r|\n/g, "\n");
nlujjawal marked this conversation as resolved.
Show resolved Hide resolved
editor.session.doc.$autoNewLine = "\n";
}

var offset = editor.session.doc.positionToIndex(editor.selection.anchor);
if (this.searchRange)
offset -= editor.session.doc.positionToIndex(this.searchRange.start);
Expand Down Expand Up @@ -290,6 +299,9 @@ class SearchBox {
this.element.style.display = "";
this.replaceOption.checked = isReplace;

if (this.editor.$search.$options.regExp)
value = lang.escapeRegExp(value);

if (value)
this.searchInput.value = value;

Expand Down
Loading
Loading