From bf4e364b2717ab2fcaf572d838b498fa4032ec14 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 14 Feb 2017 11:21:47 -0800 Subject: [PATCH 1/2] Fix exeption when toggling invalid regex option as first search --- lib/find-view.coffee | 2 +- spec/find-view-spec.coffee | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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..daad8a09 100644 --- a/spec/find-view-spec.coffee +++ b/spec/find-view-spec.coffee @@ -1222,6 +1222,16 @@ 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') + describe "replacing", -> beforeEach -> editor.setCursorBufferPosition([2, 0]) From 97ff07c1f166dcb5285e759d3b7af0aac3b21b1f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 14 Feb 2017 11:40:01 -0800 Subject: [PATCH 2/2] Fix error when editing with an invalid regex search --- lib/buffer-search.js | 2 +- spec/find-view-spec.coffee | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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/spec/find-view-spec.coffee b/spec/find-view-spec.coffee index daad8a09..a18951e7 100644 --- a/spec/find-view-spec.coffee +++ b/spec/find-view-spec.coffee @@ -1232,6 +1232,9 @@ describe 'FindView', -> 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])