Re-search when selection changes and "Only in selection" is set
MODIFY
lib/buffer-search.js
lib/buffer-search.js
@@ -12,17 +12,6 @@ class BufferSearch {
this.subscriptions = null;
this.markers = [];
this.editor = null;
-
- this.findOptions.onDidChange(changedParams => {
- if (changedParams && (
- changedParams.findPattern != null ||
- changedParams.useRegex != null ||
- changedParams.wholeWord != null ||
- changedParams.caseSensitive != null ||
- changedParams.inCurrentSelection != null)) {
- this.recreateMarkers();
- }
- });
}
onDidUpdate(callback) {
@@ -80,12 +69,17 @@ class BufferSearch {
search(findPattern, otherOptions) {
let options = {findPattern};
- if (otherOptions != null) {
- for (let key in otherOptions) {
- options[key] = otherOptions[key];
- }
+ Object.assign(options, otherOptions);
+
+ const changedParams = this.findOptions.set(options);
+ if (changedParams.findPattern != null ||
+ changedParams.useRegex != null ||
+ changedParams.wholeWord != null ||
+ changedParams.caseSensitive != null ||
+ changedParams.inCurrentSelection != null ||
+ (this.findOptions.inCurrentSelection === true && this.editor.getSelectedBufferRange() !== this.selectedRange)) {
+ this.recreateMarkers();
}
- this.findOptions.set(options);
}
replace(markers, replacePattern) {
@@ -141,10 +135,10 @@ class BufferSearch {
createMarkers(start, end) {
let newMarkers = [];
if (this.findOptions.findPattern && this.editor) {
- const selectedRange = this.editor.getSelectedBufferRange()
- if (this.findOptions.inCurrentSelection && !selectedRange.isEmpty()) {
- start = Point.max(start, selectedRange.start);
- end = Point.min(end, selectedRange.end);
+ this.selectedRange = this.editor.getSelectedBufferRange()
+ if (this.findOptions.inCurrentSelection && !this.selectedRange.isEmpty()) {
+ start = Point.max(start, this.selectedRange.start);
+ end = Point.min(end, this.selectedRange.end);
}
const regex = this.getFindPatternRegex()

MODIFY
lib/find-options.coffee
lib/find-options.coffee
@@ -41,16 +41,17 @@ class FindOptions
result
set: (newParams={}) ->
- changedParams = null
+ changedParams = {}
for key in Params
if newParams[key]? and newParams[key] isnt this[key]
changedParams ?= {}
this[key] = changedParams[key] = newParams[key]
- if changedParams?
+ if Object.keys(changedParams).length
for param, val of changedParams
@emitter.emit("did-change-#{param}")
@emitter.emit('did-change', changedParams)
+ return changedParams
getFindPatternRegex: ->
flags = 'gm'

MODIFY
lib/find-view.js
lib/find-view.js
@@ -352,7 +352,7 @@ class FindView {
findPattern = null;
}
if (findPattern == null) { findPattern = this.findEditor.getText(); }
- return this.model.search(findPattern, options);
+ this.model.search(findPattern, options);
}
findAll(options = {focusEditorAfter: true}) {

MODIFY
lib/find.coffee
lib/find.coffee
@@ -119,7 +119,7 @@ module.exports =
consumeElementIcons: (service) ->
getIconServices().setElementIcons service
- new Disposable =>
+ new Disposable ->
getIconServices().resetElementIcons()
consumeFileIcons: (service) ->

Re-search when selection changes and "Only in selection" is set