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

Commit b830254

Browse files
committed
Add 'Find in Open Files' feature
1 parent 666ab9e commit b830254

File tree

9 files changed

+2052
-14
lines changed

9 files changed

+2052
-14
lines changed

lib/find-options.coffee

Lines changed: 2 additions & 0 deletions
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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ FindOptions = require './find-options'
66
BufferSearch = require './buffer-search'
77
FileIcons = require './file-icons'
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'
@@ -35,39 +36,48 @@ module.exports =
3536
else
3637
@findModel.setEditor(null)
3738

38-
@subscriptions.add atom.commands.add '.find-and-replace, .project-find', 'window:focus-next-pane', ->
39+
@subscriptions.add atom.commands.add '.find-and-replace, .open-files-find, .project-find', 'window:focus-next-pane', ->
3940
atom.views.getView(atom.workspace).focus()
4041

42+
@subscriptions.add atom.commands.add 'atom-workspace', 'open-files-find:show', =>
43+
@createViews()
44+
showPanel @openFilesFindPanel, => @openFilesFindView.focusFindElement()
45+
46+
@subscriptions.add atom.commands.add 'atom-workspace', 'open-files-find:toggle', =>
47+
@createViews()
48+
togglePanel @openFilesFindPanel, => @openFilesFindView.focusFindElement()
49+
4150
@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:show', =>
4251
@createViews()
43-
showPanel @projectFindPanel, @findPanel, => @projectFindView.focusFindElement()
52+
showPanel @projectFindPanel, => @projectFindView.focusFindElement()
4453

4554
@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:toggle', =>
4655
@createViews()
47-
togglePanel @projectFindPanel, @findPanel, => @projectFindView.focusFindElement()
56+
togglePanel @projectFindPanel, => @projectFindView.focusFindElement()
4857

4958
@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:show-in-current-directory', ({target}) =>
5059
@createViews()
5160
@findPanel.hide()
61+
@openFilesFindPanel.hide()
5262
@projectFindPanel.show()
5363
@projectFindView.focusFindElement()
5464
@projectFindView.findInCurrentlySelectedDirectory(target)
5565

5666
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:use-selection-as-find-pattern', =>
57-
return if @projectFindPanel?.isVisible() or @findPanel?.isVisible()
67+
return if @openFilesFindPanel?.isVisible() or @projectFindPanel?.isVisible() or @findPanel?.isVisible()
5868
@createViews()
5969

6070
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:toggle', =>
6171
@createViews()
62-
togglePanel @findPanel, @projectFindPanel, => @findView.focusFindEditor()
72+
togglePanel @findPanel, => @findView.focusFindEditor()
6373

6474
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:show', =>
6575
@createViews()
66-
showPanel @findPanel, @projectFindPanel, => @findView.focusFindEditor()
76+
showPanel @findPanel, => @findView.focusFindEditor()
6777

6878
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:show-replace', =>
6979
@createViews()
70-
showPanel @findPanel, @projectFindPanel, => @findView.focusReplaceEditor()
80+
showPanel @findPanel, => @findView.focusReplaceEditor()
7181

7282
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:clear-history', =>
7383
@findHistory.clear()
@@ -78,6 +88,7 @@ module.exports =
7888
isMiniEditor = target.tagName is 'ATOM-TEXT-EDITOR' and target.hasAttribute('mini')
7989
unless isMiniEditor
8090
@findPanel?.hide()
91+
@openFilesFindPanel?.hide()
8192
@projectFindPanel?.hide()
8293

8394
@subscriptions.add atom.commands.add 'atom-workspace',
@@ -93,13 +104,13 @@ module.exports =
93104
@selectNextObjects.set(editor, selectNext)
94105
selectNext
95106

96-
showPanel = (panelToShow, panelToHide, postShowAction) ->
97-
panelToHide.hide()
107+
showPanel = (panelToShow, postShowAction) =>
108+
@panels.map (p) => p.hide() unless p is panelToShow
98109
panelToShow.show()
99110
postShowAction?()
100111

101-
togglePanel = (panelToToggle, panelToHide, postToggleAction) ->
102-
panelToHide.hide()
112+
togglePanel = (panelToToggle, postToggleAction) =>
113+
@panels.map (p) => p.hide() unless p is panelToToggle
103114

104115
if panelToToggle.isVisible()
105116
panelToToggle.hide()
@@ -159,13 +170,16 @@ module.exports =
159170
options = {findBuffer, replaceBuffer, pathsBuffer, findHistoryCycler, replaceHistoryCycler, pathsHistoryCycler}
160171

161172
@findView = new FindView(@findModel, options)
162-
173+
@openFilesFindView = new OpenFilesFindView(@resultsModel, options)
163174
@projectFindView = new ProjectFindView(@resultsModel, options)
164175

165176
@findPanel = atom.workspace.addBottomPanel(item: @findView, visible: false, className: 'tool-panel panel-bottom')
177+
@openFilesFindPanel = atom.workspace.addBottomPanel(item: @openFilesFindView, visible: false, className: 'tool-panel panel-bottom')
166178
@projectFindPanel = atom.workspace.addBottomPanel(item: @projectFindView, visible: false, className: 'tool-panel panel-bottom')
179+
@panels = [@findPanel, @openFilesFindPanel, @projectFindPanel]
167180

168181
@findView.setPanel(@findPanel)
182+
@openFilesFindView.setPanel(@openFilesFindPanel)
169183
@projectFindView.setPanel(@projectFindPanel)
170184

171185
# HACK: Soooo, we need to get the model to the pane view whenever it is
@@ -191,6 +205,11 @@ module.exports =
191205
@findModel?.destroy()
192206
@findModel = null
193207

208+
@openFilesFindPanel?.destroy()
209+
@openFilesFindPanel = null
210+
@openFilesFindView?.destroy()
211+
@openFilesFindView = null
212+
194213
@projectFindPanel?.destroy()
195214
@projectFindPanel = null
196215
@projectFindView?.destroy()

0 commit comments

Comments
 (0)