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

Commit 62bdcb6

Browse files
authored
Merge pull request #546 from codingbelief/master
Add find in parent directory functionality
2 parents 98049b3 + 0bca679 commit 62bdcb6

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

keymaps/find-and-replace.cson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
'cmd-f': 'find-and-replace:show'
44
'cmd-alt-f': 'find-and-replace:show-replace'
55

6+
'atom-text-editor':
7+
'alt-a': 'project-find:show-in-current-directory'
8+
69
'.platform-win32, .platform-linux':
710
'ctrl-F': 'project-find:show'
811
'ctrl-f': 'find-and-replace:show'

lib/find.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports =
4545
@createViews()
4646
@findPanel.hide()
4747
@projectFindPanel.show()
48+
@projectFindView.focusFindElement()
4849
@projectFindView.findInCurrentlySelectedDirectory(target)
4950

5051
@subscriptions.add atom.commands.add 'atom-workspace', 'find-and-replace:use-selection-as-find-pattern', =>

lib/project-find-view.coffee

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ class ProjectFindView extends View
282282
elementPath = element.dataset.path
283283
break if elementPath
284284
element = element.parentElement
285+
# Use the active editor path if all elements don't have a path
286+
unless elementPath
287+
elementPath = atom.workspace.getActiveTextEditor()?.getPath()
285288

286289
if fs.isFileSync(elementPath)
287290
require('path').dirname(elementPath)

spec/project-find-view-spec.coffee

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,42 @@ describe 'ProjectFindView', ->
127127
expect(projectFindView.regexOptionButton).toHaveClass 'selected'
128128
expect(projectFindView.wholeWordOptionButton).toHaveClass 'selected'
129129

130+
describe "when project-find:show-in-current-directory is triggered with an open buffer", ->
131+
editor = null
132+
133+
beforeEach ->
134+
atom.project.setPaths([__dirname])
135+
atom.commands.dispatch(workspaceElement, 'project-find:show')
136+
137+
waitsForPromise ->
138+
activationPromise
139+
140+
runs ->
141+
projectFindView.findEditor.setText('')
142+
projectFindView.pathsEditor.setText('')
143+
144+
waitsForPromise ->
145+
atom.workspace.open('fixtures/sample.js').then (o) -> editor = o
146+
147+
it "calls project-find:show, and populates both findEditor and pathsEditor when there is a selection", ->
148+
editor.setSelectedBufferRange([[3, 8], [3, 13]])
149+
atom.commands.dispatch(workspaceElement, 'project-find:show-in-current-directory')
150+
expect(getAtomPanel()).toBeVisible()
151+
expect(projectFindView.findEditor.getText()).toBe('pivot')
152+
expect(projectFindView.pathsEditor.getText()).toBe('fixtures')
153+
154+
editor.setSelectedBufferRange([[2, 14], [2, 20]])
155+
atom.commands.dispatch(workspaceElement, 'project-find:show-in-current-directory')
156+
expect(getAtomPanel()).toBeVisible()
157+
expect(projectFindView.findEditor.getText()).toBe('length')
158+
expect(projectFindView.pathsEditor.getText()).toBe('fixtures')
159+
160+
it "calls project-find:show, and populates only pathsEditor when there is no selection", ->
161+
atom.commands.dispatch(workspaceElement, 'project-find:show-in-current-directory')
162+
expect(getAtomPanel()).toBeVisible()
163+
expect(projectFindView.findEditor.getText()).toBe('')
164+
expect(projectFindView.pathsEditor.getText()).toBe('fixtures')
165+
130166
describe "when project-find:toggle is triggered", ->
131167
it "toggles the visibility of the ProjectFindView", ->
132168
atom.commands.dispatch(workspaceElement, 'project-find:toggle')

0 commit comments

Comments
 (0)