diff --git a/lib/buffer-search.js b/lib/buffer-search.js index c00671b2..47b9555a 100644 --- a/lib/buffer-search.js +++ b/lib/buffer-search.js @@ -223,7 +223,7 @@ class BufferSearch { scanEnd = Point.INFINITY; } - const newMarkers = this.createMarkers(scanStart, scanEnd); + const newMarkers = this.createMarkers(scanStart, scanEnd) || []; const oldMarkers = this.markers.splice(spliceStart, (spliceEnd - spliceStart) + 1, ...newMarkers); for (let oldMarker of oldMarkers) { oldMarker.destroy(); diff --git a/lib/find-view.coffee b/lib/find-view.coffee index 53aaaf51..51f732b6 100644 --- a/lib/find-view.coffee +++ b/lib/find-view.coffee @@ -371,7 +371,7 @@ class FindView extends View firstMarkerIndexAfterCursor: (indexIncluded=false) -> editor = @model.getEditor() - return null unless editor + return null unless editor and @markers?.length > 0 selection = editor.getLastSelection() {start, end} = selection.getBufferRange() diff --git a/spec/find-view-spec.coffee b/spec/find-view-spec.coffee index 722c9ae9..a18951e7 100644 --- a/spec/find-view-spec.coffee +++ b/spec/find-view-spec.coffee @@ -1222,6 +1222,19 @@ describe 'FindView', -> atom.commands.dispatch(findView.findEditor.element, 'core:confirm') expect(getResultDecorations(editor, 'find-result')).toHaveLength 0 + it "doesn't throw an exception when toggling the regex option with an invalid pattern before performing any other search (regression)", -> + atom.commands.dispatch editorView, 'find-and-replace:show' + + waitsForPromise -> + activationPromise + + runs -> + findView.findEditor.setText '(' + atom.commands.dispatch(findView.findEditor.element, 'find-and-replace:toggle-regex-option') + + editor.insertText('hi') + advanceClock(editor.getBuffer().stoppedChangingDelay) + describe "replacing", -> beforeEach -> editor.setCursorBufferPosition([2, 0])