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

Commit 00b8d57

Browse files
committed
Add 'Find in Open Files' feature
1 parent 5423707 commit 00b8d57

9 files changed

+2052
-14
lines changed

lib/find-options.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ _ = require 'underscore-plus'
44
Params = [
55
'findPattern'
66
'replacePattern'
7+
'paths'
78
'pathsPattern'
89
'useRegex'
910
'wholeWord'
@@ -20,6 +21,7 @@ class FindOptions
2021

2122
@findPattern = ''
2223
@replacePattern = state.replacePattern ? ''
24+
@paths = state.paths ? []
2325
@pathsPattern = state.pathsPattern ? ''
2426
@useRegex = state.useRegex ? atom.config.get('find-and-replace.useRegex') ? false
2527
@caseSensitive = state.caseSensitive ? atom.config.get('find-and-replace.caseSensitive') ? false

lib/find.coffee

+31-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FindOptions = require './find-options'
66
BufferSearch = require './buffer-search'
77
getIconServices = require './get-icon-services'
88
FindView = require './find-view'
9+
OpenFilesFindView = require './open-files-find-view'
910
ProjectFindView = require './project-find-view'
1011
ResultsModel = require './project/results-model'
1112
ResultsPaneView = require './project/results-pane'
@@ -49,26 +50,35 @@ module.exports =
4950
else
5051
@findModel.setEditor(null)
5152

52-
@subscriptions.add atom.commands.add '.find-and-replace, .project-find', 'window:focus-next-pane', ->
53+
@subscriptions.add atom.commands.add '.find-and-replace, .open-files-find, .project-find', 'window:focus-next-pane', ->
5354
atom.views.getView(atom.workspace).focus()
5455

56+
@subscriptions.add atom.commands.add 'atom-workspace', 'open-files-find:show', =>
57+
@createViews()
58+
showPanel @openFilesFindPanel, => @openFilesFindView.focusFindElement()
59+
60+
@subscriptions.add atom.commands.add 'atom-workspace', 'open-files-find:toggle', =>
61+
@createViews()
62+
togglePanel @openFilesFindPanel, => @openFilesFindView.focusFindElement()
63+
5564
@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:show', =>
5665
@createViews()
57-
showPanel @projectFindPanel, @findPanel, => @projectFindView.focusFindElement()
66+
showPanel @projectFindPanel, => @projectFindView.focusFindElement()
5867

5968
@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:toggle', =>
6069
@createViews()
61-
togglePanel @projectFindPanel, @findPanel, => @projectFindView.focusFindElement()
70+
togglePanel @projectFindPanel, => @projectFindView.focusFindElement()
6271

6372
@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:show-in-current-directory', ({target}) =>
6473
@createViews()
6574
@findPanel.hide()
75+
@openFilesFindPanel.hide()
6676
@projectFindPanel.show()
6777
@projectFindView.focusFindElement()
6878
@projectFindView.findInCurrentlySelectedDirectory(target)
6979

7080
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:use-selection-as-find-pattern', =>
71-
return if @projectFindPanel?.isVisible() or @findPanel?.isVisible()
81+
return if @openFilesFindPanel?.isVisible() or @projectFindPanel?.isVisible() or @findPanel?.isVisible()
7282
@createViews()
7383

7484
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:use-selection-as-replace-pattern', =>
@@ -77,15 +87,15 @@ module.exports =
7787

7888
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:toggle', =>
7989
@createViews()
80-
togglePanel @findPanel, @projectFindPanel, => @findView.focusFindEditor()
90+
togglePanel @findPanel, => @findView.focusFindEditor()
8191

8292
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:show', =>
8393
@createViews()
84-
showPanel @findPanel, @projectFindPanel, => @findView.focusFindEditor()
94+
showPanel @findPanel, => @findView.focusFindEditor()
8595

8696
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:show-replace', =>
8797
@createViews()
88-
showPanel @findPanel, @projectFindPanel, => @findView.focusReplaceEditor()
98+
showPanel @findPanel, => @findView.focusReplaceEditor()
8999

90100
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:clear-history', =>
91101
@findHistory.clear()
@@ -96,6 +106,7 @@ module.exports =
96106
isMiniEditor = target.tagName is 'ATOM-TEXT-EDITOR' and target.hasAttribute('mini')
97107
unless isMiniEditor
98108
@findPanel?.hide()
109+
@openFilesFindPanel?.hide()
99110
@projectFindPanel?.hide()
100111

101112
@subscriptions.add atom.commands.add 'atom-workspace',
@@ -111,13 +122,13 @@ module.exports =
111122
@selectNextObjects.set(editor, selectNext)
112123
selectNext
113124

114-
showPanel = (panelToShow, panelToHide, postShowAction) ->
115-
panelToHide.hide()
125+
showPanel = (panelToShow, postShowAction) =>
126+
@panels.map (p) => p.hide() unless p is panelToShow
116127
panelToShow.show()
117128
postShowAction?()
118129

119-
togglePanel = (panelToToggle, panelToHide, postToggleAction) ->
120-
panelToHide.hide()
130+
togglePanel = (panelToToggle, postToggleAction) =>
131+
@panels.map (p) => p.hide() unless p is panelToToggle
121132

122133
if panelToToggle.isVisible()
123134
panelToToggle.hide()
@@ -187,13 +198,16 @@ module.exports =
187198
options = {findBuffer, replaceBuffer, pathsBuffer, findHistoryCycler, replaceHistoryCycler, pathsHistoryCycler}
188199

189200
@findView = new FindView(@findModel, options)
190-
201+
@openFilesFindView = new OpenFilesFindView(@resultsModel, options)
191202
@projectFindView = new ProjectFindView(@resultsModel, options)
192203

193204
@findPanel = atom.workspace.addBottomPanel(item: @findView, visible: false, className: 'tool-panel panel-bottom')
205+
@openFilesFindPanel = atom.workspace.addBottomPanel(item: @openFilesFindView, visible: false, className: 'tool-panel panel-bottom')
194206
@projectFindPanel = atom.workspace.addBottomPanel(item: @projectFindView, visible: false, className: 'tool-panel panel-bottom')
207+
@panels = [@findPanel, @openFilesFindPanel, @projectFindPanel]
195208

196209
@findView.setPanel(@findPanel)
210+
@openFilesFindView.setPanel(@openFilesFindPanel)
197211
@projectFindView.setPanel(@projectFindPanel)
198212

199213
# HACK: Soooo, we need to get the model to the pane view whenever it is
@@ -219,6 +233,11 @@ module.exports =
219233
@findModel?.destroy()
220234
@findModel = null
221235

236+
@openFilesFindPanel?.destroy()
237+
@openFilesFindPanel = null
238+
@openFilesFindView?.destroy()
239+
@openFilesFindView = null
240+
222241
@projectFindPanel?.destroy()
223242
@projectFindPanel = null
224243
@projectFindView?.destroy()

0 commit comments

Comments
 (0)