Fix error when selecting result after changing its corresponding buffer
MODIFY
lib/project/results-model.coffee
lib/project/results-model.coffee
_ = require 'underscore-plus'
-{Emitter, TextEditor} = require 'atom'
+{Emitter, TextEditor, Range} = require 'atom'
escapeHelper = require '../escape-helper'
class Result
@@ -10,7 +10,7 @@ class Result
matchText: m.matchText,
lineText: m.lineText,
lineTextOffset: m.lineTextOffset,
- range: m.range,
+ range: Range.fromObject(m.range),
leadingContextLines: m.leadingContextLines,
trailingContextLines: m.trailingContextLines
}

MODIFY
lib/project/results-view.js
lib/project/results-view.js
@@ -452,7 +452,7 @@ class ResultsView {
split: reverseDirections[atom.config.get('find-and-replace.projectSearchResultsPaneSplitDirection')]
})
.then(editor => {
- editor.unfoldBufferRow(match.range[0][0]); // Equivalent to match.range.start.row
+ editor.unfoldBufferRow(match.range.start.row);
editor.setSelectedBufferRange(match.range, {flash: true});
editor.scrollToCursorPosition();
});

MODIFY
spec/project-find-view-spec.js
spec/project-find-view-spec.js
@@ -767,7 +767,7 @@ describe('ProjectFindView', () => {
});
it("updates the results list when a buffer changes", async () => {
- const buffer = atom.project.bufferForPathSync('sample.js');
+ const editor = await atom.workspace.open('sample.js')
atom.commands.dispatch(projectFindView.element, 'core:confirm');
await searchPromise;
@@ -783,14 +783,20 @@ describe('ProjectFindView', () => {
for (let i = 0; i < 7; i++) await resultsView.moveDown()
expect(resultsView.refs.listView.element.querySelectorAll(".path")[1]).toHaveClass('selected');
- buffer.setText('there is one "items" in this file');
- advanceClock(buffer.stoppedChangingDelay);
+ editor.setText('there is one "items" in this file');
+ advanceClock(editor.getBuffer().stoppedChangingDelay);
await etch.getScheduler().getNextUpdatePromise()
expect(resultsPaneView.refs.previewCount.textContent).toBe("8 results found in 2 files for items");
expect(resultsView.refs.listView.element.querySelectorAll(".path")[1]).toHaveClass('selected');
- buffer.setText('no matches in this file');
- advanceClock(buffer.stoppedChangingDelay);
+ // Ensure the newly added item can be opened.
+ await resultsView.moveDown()
+ atom.commands.dispatch(resultsView.element, 'core:confirm');
+ await new Promise(resolve => editor.onDidChangeSelectionRange(resolve));
+ expect(editor.getSelectedText()).toBe("items")
+
+ editor.setText('no matches in this file');
+ advanceClock(editor.getBuffer().stoppedChangingDelay);
await etch.getScheduler().getNextUpdatePromise()
expect(resultsPaneView.refs.previewCount.textContent).toBe("7 results found in 1 file for items");
});

Fix error when selecting result after changing its corresponding buffer