Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Only emit did-update when there are changes; set consistent classes on error #852

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/buffer-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class BufferSearch {
}
}

this.emitter.emit('did-update', this.markers.slice());
if (changes.length) this.emitter.emit('did-update', this.markers.slice());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this still be checking for changes then, or should it be checking for changed markers? (Not sure how to do that)

this.currentResultMarker = null;
this.setCurrentMarkerFromSelection();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/find-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ class FindView extends View
atom.beep()

markersUpdated: (@markers) =>
@findError = null
@updateResultCounter()
@updateReplaceEnablement()

Expand Down Expand Up @@ -342,6 +341,8 @@ class FindView extends View
@descriptionLabel.text(infoMessage).removeClass('text-error')

setErrorMessage: (errorMessage) ->
this.removeClass('has-results')
this.addClass('has-no-results')
@descriptionLabel.text(errorMessage).addClass('text-error')

clearMessage: ->
Expand Down
23 changes: 23 additions & 0 deletions spec/find-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,29 @@ describe 'FindView', ->
expect(findView.descriptionLabel).toHaveClass 'text-error'
expect(findView.descriptionLabel.text()).toContain 'Invalid regular expression'

it "does not reset when the buffer is updated", ->
# This is a rather specific test: the error message only disappeared
# when there were no changes. Backspacing nothing can reproduce this,
# as well as saving or undoing and then redoing.
editor.setCursorBufferPosition([0, 0])
# Since we're at the beginning of the file, backspacing will do nothing but still send a change event
editor.backspace()
advanceClock(editor.buffer.stoppedChangingDelay)

expect(findView.descriptionLabel).toHaveClass 'text-error'
expect(findView.descriptionLabel.text()).toContain 'Invalid regular expression'

it "adds the has-no-results class", ->
findView.findEditor.setText 'it'
atom.commands.dispatch(findView.findEditor.element, 'core:confirm')
expect(findView).toHaveClass 'has-results'
expect(findView).not.toHaveClass 'has-no-results'

findView.findEditor.setText 'i[t'
atom.commands.dispatch(findView.findEditor.element, 'core:confirm')
expect(findView).toHaveClass 'has-no-results'
expect(findView).not.toHaveClass 'has-results'

it "will be reset when there is no longer an error", ->
expect(findView.descriptionLabel).toHaveClass 'text-error'

Expand Down