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

Commit df0c233

Browse files
author
Max Brunsfeld
authored
Merge pull request #860 from atom/mb-ns-fix-invalid-regex-exception
Fix exceptions when searching for invalid regexps
2 parents 797a4b1 + 97ff07c commit df0c233

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/buffer-search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class BufferSearch {
223223
scanEnd = Point.INFINITY;
224224
}
225225

226-
const newMarkers = this.createMarkers(scanStart, scanEnd);
226+
const newMarkers = this.createMarkers(scanStart, scanEnd) || [];
227227
const oldMarkers = this.markers.splice(spliceStart, (spliceEnd - spliceStart) + 1, ...newMarkers);
228228
for (let oldMarker of oldMarkers) {
229229
oldMarker.destroy();

lib/find-view.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class FindView extends View
371371

372372
firstMarkerIndexAfterCursor: (indexIncluded=false) ->
373373
editor = @model.getEditor()
374-
return null unless editor
374+
return null unless editor and @markers?.length > 0
375375

376376
selection = editor.getLastSelection()
377377
{start, end} = selection.getBufferRange()

spec/find-view-spec.coffee

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,19 @@ describe 'FindView', ->
12221222
atom.commands.dispatch(findView.findEditor.element, 'core:confirm')
12231223
expect(getResultDecorations(editor, 'find-result')).toHaveLength 0
12241224

1225+
it "doesn't throw an exception when toggling the regex option with an invalid pattern before performing any other search (regression)", ->
1226+
atom.commands.dispatch editorView, 'find-and-replace:show'
1227+
1228+
waitsForPromise ->
1229+
activationPromise
1230+
1231+
runs ->
1232+
findView.findEditor.setText '('
1233+
atom.commands.dispatch(findView.findEditor.element, 'find-and-replace:toggle-regex-option')
1234+
1235+
editor.insertText('hi')
1236+
advanceClock(editor.getBuffer().stoppedChangingDelay)
1237+
12251238
describe "replacing", ->
12261239
beforeEach ->
12271240
editor.setCursorBufferPosition([2, 0])

0 commit comments

Comments
 (0)