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

Commit

Permalink
Add 'Find in Open Files' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
trevdor committed Oct 24, 2017
1 parent 666ab9e commit b830254
Show file tree
Hide file tree
Showing 9 changed files with 2,052 additions and 14 deletions.
2 changes: 2 additions & 0 deletions lib/find-options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ _ = require 'underscore-plus'
Params = [
'findPattern'
'replacePattern'
'paths'
'pathsPattern'
'useRegex'
'wholeWord'
Expand All @@ -20,6 +21,7 @@ class FindOptions

@findPattern = ''
@replacePattern = state.replacePattern ? ''
@paths = state.paths ? []
@pathsPattern = state.pathsPattern ? ''
@useRegex = state.useRegex ? atom.config.get('find-and-replace.useRegex') ? false
@caseSensitive = state.caseSensitive ? atom.config.get('find-and-replace.caseSensitive') ? false
Expand Down
43 changes: 31 additions & 12 deletions lib/find.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FindOptions = require './find-options'
BufferSearch = require './buffer-search'
FileIcons = require './file-icons'
FindView = require './find-view'
OpenFilesFindView = require './open-files-find-view'
ProjectFindView = require './project-find-view'
ResultsModel = require './project/results-model'
ResultsPaneView = require './project/results-pane'
Expand Down Expand Up @@ -35,39 +36,48 @@ module.exports =
else
@findModel.setEditor(null)

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

@subscriptions.add atom.commands.add 'atom-workspace', 'open-files-find:show', =>
@createViews()
showPanel @openFilesFindPanel, => @openFilesFindView.focusFindElement()

@subscriptions.add atom.commands.add 'atom-workspace', 'open-files-find:toggle', =>
@createViews()
togglePanel @openFilesFindPanel, => @openFilesFindView.focusFindElement()

@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:show', =>
@createViews()
showPanel @projectFindPanel, @findPanel, => @projectFindView.focusFindElement()
showPanel @projectFindPanel, => @projectFindView.focusFindElement()

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

@subscriptions.add atom.commands.add 'atom-workspace', 'project-find:show-in-current-directory', ({target}) =>
@createViews()
@findPanel.hide()
@openFilesFindPanel.hide()
@projectFindPanel.show()
@projectFindView.focusFindElement()
@projectFindView.findInCurrentlySelectedDirectory(target)

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

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

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

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

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

@subscriptions.add atom.commands.add 'atom-workspace',
Expand All @@ -93,13 +104,13 @@ module.exports =
@selectNextObjects.set(editor, selectNext)
selectNext

showPanel = (panelToShow, panelToHide, postShowAction) ->
panelToHide.hide()
showPanel = (panelToShow, postShowAction) =>
@panels.map (p) => p.hide() unless p is panelToShow
panelToShow.show()
postShowAction?()

togglePanel = (panelToToggle, panelToHide, postToggleAction) ->
panelToHide.hide()
togglePanel = (panelToToggle, postToggleAction) =>
@panels.map (p) => p.hide() unless p is panelToToggle

if panelToToggle.isVisible()
panelToToggle.hide()
Expand Down Expand Up @@ -159,13 +170,16 @@ module.exports =
options = {findBuffer, replaceBuffer, pathsBuffer, findHistoryCycler, replaceHistoryCycler, pathsHistoryCycler}

@findView = new FindView(@findModel, options)

@openFilesFindView = new OpenFilesFindView(@resultsModel, options)
@projectFindView = new ProjectFindView(@resultsModel, options)

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

@findView.setPanel(@findPanel)
@openFilesFindView.setPanel(@openFilesFindPanel)
@projectFindView.setPanel(@projectFindPanel)

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

@openFilesFindPanel?.destroy()
@openFilesFindPanel = null
@openFilesFindView?.destroy()
@openFilesFindView = null

@projectFindPanel?.destroy()
@projectFindPanel = null
@projectFindView?.destroy()
Expand Down
Loading

0 comments on commit b830254

Please sign in to comment.