persist showContextLines state in FindOptions
MODIFY
lib/find-options.coffee
lib/find-options.coffee
@@ -9,6 +9,7 @@ Params = [
'wholeWord'
'caseSensitive'
'inCurrentSelection'
+ 'showContextLines'
]
module.exports =
@@ -23,6 +24,7 @@ class FindOptions
@caseSensitive = state.caseSensitive ? atom.config.get('find-and-replace.caseSensitive') ? false
@wholeWord = state.wholeWord ? atom.config.get('find-and-replace.wholeWord') ? false
@inCurrentSelection = state.inCurrentSelection ? atom.config.get('find-and-replace.inCurrentSelection') ? false
+ @showContextLines = state.showContextLines ? atom.config.get('find-and-replace.showContextLines') ? false
onDidChange: (callback) ->
@emitter.on('did-change', callback)

MODIFY
lib/project/results-pane.js
lib/project/results-pane.js
@@ -84,7 +84,11 @@ class ResultsPaneView {
$.div({className: 'btn-toolbar'},
hasContext ?
$.div({className: 'btn-group'},
- $.button({ref: 'toggleContext', className: 'btn'}, 'Show Context')
+ $.button(
+ {
+ ref: 'toggleContext',
+ className: 'btn' + (this.model.getFindOptions().showContextLines ? ' selected' : '')
+ }, 'Show Context')
) : null,
$.div({className: 'btn-group'},
@@ -224,7 +228,7 @@ class ResultsPaneView {
toggleContextLines() {
this.refs.resultsView.toggleContextLines();
- if (this.refs.resultsView.showContextLines) {
+ if (this.model.getFindOptions().showContextLines) {
this.refs.toggleContext.classList.add('selected');
} else {
this.refs.toggleContext.classList.remove('selected');

MODIFY
lib/project/results-view.js
lib/project/results-view.js
@@ -20,7 +20,6 @@ class ResultsView {
this.selectedResultIndex = 0;
this.selectedMatchIndex = -1;
this.collapsedResultIndices = [];
- this.showContextLines = true;
this.heightForSearchResult = this.heightForSearchResult.bind(this);
this.resolveHeightInvalidationPromise = null
@@ -127,7 +126,7 @@ class ResultsView {
pathDetailsHeight: this.pathDetailsHeight,
matchHeight: this.matchHeight,
contextLineHeight: this.contextLineHeight,
- showContextLines: this.showContextLines
+ showContextLines: this.model.getFindOptions().showContextLines
}, this.model.results[filePath]);
}),
})
@@ -140,8 +139,12 @@ class ResultsView {
for (let i = 0, n = searchResult.matches.length; i < n; i++) {
const match = searchResult.matches[i];
result += this.matchHeight;
- if (match.leadingContextLines && this.showContextLines) result += this.contextLineHeight * match.leadingContextLines.length;
- if (match.trailingContextLines && this.showContextLines) result += this.contextLineHeight * match.trailingContextLines.length;
+ if (match.leadingContextLines && this.model.getFindOptions().showContextLines) {
+ result += this.contextLineHeight * match.leadingContextLines.length;
+ }
+ if (match.trailingContextLines && this.model.getFindOptions().showContextLines) {
+ result += this.contextLineHeight * match.trailingContextLines.length;
+ }
}
}
return result;
@@ -443,7 +446,7 @@ class ResultsView {
}
toggleContextLines() {
- this.showContextLines = !this.showContextLines;
+ this.model.getFindOptions().showContextLines = !this.model.getFindOptions().showContextLines;
return etch.update(this);
}

MODIFY
spec/results-view-spec.js
spec/results-view-spec.js
@@ -698,6 +698,7 @@ describe('ResultsView', () => {
beforeEach(async () => {
atom.config.set('find-and-replace.searchContextLineCountBefore', 2);
atom.config.set('find-and-replace.searchContextLineCountAfter', 1);
+ atom.config.set('find-and-replace.showContextLines', false);
projectFindView.findEditor.setText('items');
atom.commands.dispatch(projectFindView.element, 'core:confirm');
@@ -710,7 +711,9 @@ describe('ResultsView', () => {
// the following condition is pretty hacky
// it doesn't work correctly for e.g. version 1.2
if (parseFloat(atom.getVersion()) >= 1.17) {
- expect(resultsView.showContextLines).toBe(true);
+ expect(resultsView.model.getFindOptions().showContextLines).toBe(false);
+ await resultsView.toggleContextLines();
+ expect(resultsView.model.getFindOptions().showContextLines).toBe(true);
const pathNodes = resultsView.refs.listView.element.querySelectorAll('.path');
expect(pathNodes.length).toBe(2);
const pathNameNode = pathNodes[0].querySelector('.path-name');
@@ -732,8 +735,7 @@ describe('ResultsView', () => {
// the following condition is pretty hacky
// it doesn't work correctly for e.g. version 1.2
if (parseFloat(atom.getVersion()) >= 1.17) {
- await resultsView.toggleContextLines();
- expect(resultsView.showContextLines).toBe(false);
+ expect(resultsView.model.getFindOptions().showContextLines).toBe(false);
const pathNodes = resultsView.refs.listView.element.querySelectorAll('.path');
expect(pathNodes.length).toBe(2);
let pathNameNode = pathNodes[0].querySelector('.path-name');

persist showContextLines state in FindOptions