add setting for context lines, show context in match view
MODIFY
lib/project/match-view.coffee
lib/project/match-view.coffee
@@ -13,13 +13,27 @@ class MatchView extends View
prefix = removeLeadingWhitespace(match.lineText[0...matchStart])
suffix = match.lineText[matchEnd..]
- @li class: 'search-result list-item', =>
+ linesBefore = match.linesBefore or []
+ linesAfter = match.linesAfter or []
+ @li class: 'search-result list-group', =>
+ @ul class: 'list-tree', =>
+ for line, index in linesBefore
+ @li class: 'list-item', =>
+ @span range.start.row + 1 - linesBefore.length + index, class: 'line-number text-subtle'
+ @span class: 'preview', outlet: 'preview', =>
+ @span line
+ @li class: 'list-item match-line', =>
@span range.start.row + 1, class: 'line-number text-subtle'
@span class: 'preview', outlet: 'preview', =>
@span prefix
@span match.matchText, class: 'match highlight-info', outlet: 'matchText'
@span match.matchText, class: 'replacement highlight-success', outlet: 'replacementText'
@span suffix
+ for line, index in linesAfter
+ @li class: 'list-item', =>
+ @span range.end.row + 1 + index + 1, class: 'line-number text-subtle'
+ @span class: 'preview', outlet: 'preview', =>
+ @span line
initialize: (@model, {@filePath, @match}) ->
@render()

MODIFY
lib/project/result-view.coffee
lib/project/result-view.coffee
@@ -49,7 +49,7 @@ class ResultView extends View
for match in matches
@matches.append(new MatchView(@model, {@filePath, match}))
- @matches.children().eq(selectedIndex).addClass('selected') if selectedIndex > -1
+ @matches.find('.match-line').eq(selectedIndex).addClass('selected') if selectedIndex > -1
expand: (expanded) ->
# expand or collapse the list
@@ -59,7 +59,7 @@ class ResultView extends View
if @hasClass('selected')
@removeClass('selected')
firstResult = @find('.search-result:first').view()
- firstResult.addClass('selected')
+ firstResult.find('.match-line').addClass('selected')
# scroll to the proper place
resultView = firstResult.closest('.results-view').view()

MODIFY
lib/project/results-model.coffee
lib/project/results-model.coffee
@@ -10,7 +10,9 @@ class Result
matchText: m.matchText,
lineText: m.lineText,
lineTextOffset: m.lineTextOffset,
- range: m.range
+ range: m.range,
+ linesBefore: m.linesBefore,
+ linesAfter: m.linesAfter
}
)
new Result({filePath: result.filePath, matches})
@@ -126,7 +128,9 @@ class ResultsModel
onPathsSearched = (numberOfPathsSearched) =>
@emitter.emit 'did-search-paths', numberOfPathsSearched
- @inProgressSearchPromise = atom.workspace.scan @regex, {paths: searchPaths, onPathsSearched}, (result, error) =>
+ lineCountBefore = atom.config.get('find-and-replace.searchContextLineCountBefore')
+ lineCountAfter = atom.config.get('find-and-replace.searchContextLineCountAfter')
+ @inProgressSearchPromise = atom.workspace.scan @regex, {paths: searchPaths, onPathsSearched, lineCountBefore, lineCountAfter}, (result, error) =>
if result
@setResult(result.filePath, Result.create(result))
else
@@ -240,7 +244,9 @@ class ResultsModel
return unless editor.getPath()
matches = []
- editor.scan @regex, (match) ->
+ lineCountBefore = atom.config.get('find-and-replace.searchContextLineCountBefore')
+ lineCountAfter = atom.config.get('find-and-replace.searchContextLineCountAfter')
+ editor.scan @regex, {lineCountBefore, lineCountAfter}, (match) ->
matches.push(match)
result = Result.create({matches})

MODIFY
lib/project/results-view.coffee
lib/project/results-view.coffee
@@ -18,7 +18,7 @@ class ResultsView extends ScrollView
@on 'mousedown', '.path', (e) =>
@find('.selected').removeClass('selected')
view = $(e.target).view()
- view.addClass('selected')
+ view.find('.match-line').addClass('selected')
if not e.ctrlKey
if e.originalEvent?.detail is 1
view.confirm(pending: true)
@@ -206,7 +206,7 @@ class ResultsView extends ScrollView
parentView = resultView.closest('.path')
resultView = parentView if parentView.hasClass('collapsed')
- resultView.addClass('selected')
+ resultView.find('.match-line').addClass('selected')
collapseResult: ->
parent = @find('.selected').closest('.path').view()

MODIFY
package.json
package.json
"minimum": 0,
"description": "The minimum number of characters which need to be typed into the buffer find box before search starts matching and highlighting matches as you type."
},
+ "searchContextLineCountBefore": {
+ "type": "integer",
+ "default": 0,
+ "minimum": 0,
+ "description": "The number of extra lines of context to show before the match for project results"
+ },
+ "searchContextLineCountAfter": {
+ "type": "integer",
+ "default": 0,
+ "minimum": 0,
+ "description": "The number of extra lines of context to show after the match for project results"
+ },
"showSearchWrapIcon": {
"type": "boolean",
"default": true,

MODIFY
styles/find-and-replace.less
styles/find-and-replace.less
@@ -257,6 +257,14 @@ atom-workspace.find-visible {
.search-result {
padding-top: 2px;
padding-bottom: 2px;
+
+ .match-line {
+ color: @text-color-selected;
+ }
+
+ .match-line.selected {
+ color: @text-color;
+ }
}
.line-number {

add setting for context lines, show context in match view