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

Commit 09d5e57

Browse files
committed
Add an option to open results in a right or a bottom pane
1 parent b675406 commit 09d5e57

File tree

6 files changed

+111
-19
lines changed

6 files changed

+111
-19
lines changed

lib/find.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ ProjectFindView = require './project-find-view'
1010
ResultsModel = require './project/results-model'
1111
ResultsPaneView = require './project/results-pane'
1212

13+
# To convert previous (and now unused) config setting "openProjectFindResultsInRightPane"
14+
if atom.config.get('find-and-replace.openProjectFindResultsInRightPane')
15+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane')
16+
atom.config.unset('find-and-replace.openProjectFindResultsInRightPane')
17+
1318
module.exports =
1419
activate: ({findOptions, findHistory, replaceHistory, pathsHistory}={}) ->
1520
atom.workspace.addOpener (filePath) ->

lib/project-find-view.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ class ProjectFindView extends View
299299

300300
showResultPane: ->
301301
options = {searchAllPanes: true}
302-
options.split = 'right' if atom.config.get('find-and-replace.openProjectFindResultsInRightPane')
302+
switch atom.config.get('find-and-replace.openProjectFindResultsInANewPane')
303+
when 'right pane' then options.split = 'right'
304+
when 'bottom pane' then options.split = 'down'
303305
atom.workspace.open(ResultsPaneView.URI, options)
304306

305307
onFinishedReplacing: (results) ->

lib/project/match-view.coffee

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ class MatchView extends View
4343
@matchText.removeClass('highlight-error').addClass('highlight-info')
4444

4545
confirm: (options = {}) ->
46-
openInRightPane = atom.config.get('find-and-replace.openProjectFindResultsInRightPane')
47-
options.split = 'left' if openInRightPane
46+
openInNewPane = atom.config.get('find-and-replace.openProjectFindResultsInANewPane')
47+
switch openInNewPane
48+
when 'right pane' then options = {split: 'left'}
49+
when 'bottom pane' then options = {split: 'up'}
4850
editorPromise = atom.workspace.open(@filePath, options)
4951
editorPromise.then (editor) =>
5052
editor.setSelectedBufferRange(@match.range, autoscroll: true)

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"repository": "https://github.com/atom/find-and-replace",
2828
"engines": {
29-
"atom": "*"
29+
"atom": ">=1.2.0"
3030
},
3131
"dependencies": {
3232
"atom-space-pen-views": "^2.1.0",
@@ -51,9 +51,11 @@
5151
"default": false,
5252
"description": "Focus the editor and select the next match when a file search is executed. If no matches are found, the editor will not be focused."
5353
},
54-
"openProjectFindResultsInRightPane": {
55-
"type": "boolean",
56-
"default": false,
54+
"openProjectFindResultsInANewPane": {
55+
"type": "string",
56+
"default": "no",
57+
"enum": ["no", "right pane", "bottom pane"],
58+
"title": "Open Results in a new pane",
5759
"description": "When a project-wide search is executed, open the results in a split pane instead of a tab in the same pane."
5860
},
5961
"closeFindPanelAfterSearch": {

spec/project-find-view-spec.coffee

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe 'ProjectFindView', ->
2727
atom.project.setPaths([path.join(__dirname, 'fixtures')])
2828
jasmine.attachToDOM(workspaceElement)
2929

30-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false)
30+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no')
3131
activationPromise = atom.packages.activatePackage("find-and-replace").then (options) ->
3232
mainModule = options.mainModule
3333
mainModule.createViews()
@@ -329,9 +329,22 @@ describe 'ProjectFindView', ->
329329
workspaceElement.style.height = '1000px'
330330
atom.commands.dispatch editorView, 'project-find:show'
331331

332-
it "splits when option is true", ->
332+
it "splits when option is right", ->
333333
initialPane = atom.workspace.getActivePane()
334-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
334+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane')
335+
projectFindView.findEditor.setText('items')
336+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
337+
338+
waitsForPromise ->
339+
searchPromise
340+
341+
runs ->
342+
pane1 = atom.workspace.getActivePane()
343+
expect(pane1).not.toBe initialPane
344+
345+
it "splits when option is bottom", ->
346+
initialPane = atom.workspace.getActivePane()
347+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane')
335348
projectFindView.findEditor.setText('items')
336349
atom.commands.dispatch(projectFindView[0], 'core:confirm')
337350

@@ -354,8 +367,8 @@ describe 'ProjectFindView', ->
354367
pane1 = atom.workspace.getActivePane()
355368
expect(pane1).toBe initialPane
356369

357-
it "can be duplicated", ->
358-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
370+
it "can be duplicated on the right", ->
371+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane')
359372
projectFindView.findEditor.setText('items')
360373
atom.commands.dispatch(projectFindView[0], 'core:confirm')
361374

@@ -379,6 +392,31 @@ describe 'ProjectFindView', ->
379392

380393
expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML
381394

395+
it "can be duplicated at the bottom", ->
396+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane')
397+
projectFindView.findEditor.setText('items')
398+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
399+
400+
waitsForPromise ->
401+
searchPromise
402+
403+
runs ->
404+
resultsPaneView1 = atom.views.getView(getExistingResultsPane())
405+
pane1 = atom.workspace.getActivePane()
406+
pane1.splitDown(copyActiveItem: true)
407+
408+
pane2 = atom.workspace.getActivePane()
409+
resultsPaneView2 = atom.views.getView(pane2.itemForURI(ResultsPaneView.URI))
410+
411+
expect(pane1).not.toBe pane2
412+
expect(resultsPaneView1).not.toBe resultsPaneView2
413+
414+
length = resultsPaneView1.querySelectorAll('li > ul > li').length
415+
expect(length).toBeGreaterThan 0
416+
expect(resultsPaneView2.querySelectorAll('li > ul > li')).toHaveLength length
417+
418+
expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML
419+
382420
describe "serialization", ->
383421
it "serializes if the case, regex and whole word options", ->
384422
atom.commands.dispatch editorView, 'project-find:show'
@@ -1375,9 +1413,9 @@ describe 'ProjectFindView', ->
13751413
expect(projectFindView.pathsEditor).not.toHaveClass('is-focused')
13761414

13771415
describe "panel opening", ->
1378-
describe "when a panel is already open", ->
1416+
describe "when a panel is already open on the right", ->
13791417
beforeEach ->
1380-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
1418+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane')
13811419

13821420
waitsForPromise ->
13831421
atom.workspace.open('sample.js')
@@ -1408,6 +1446,39 @@ describe 'ProjectFindView', ->
14081446
runs ->
14091447
expect(workspaceElement.querySelectorAll('.preview-pane').length).toBe(1)
14101448

1449+
describe "when a panel is already open at the bottom", ->
1450+
beforeEach ->
1451+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane')
1452+
1453+
waitsForPromise ->
1454+
atom.workspace.open('sample.js')
1455+
1456+
runs ->
1457+
editor = atom.workspace.getActiveTextEditor()
1458+
editorView = atom.views.getView(editor)
1459+
atom.commands.dispatch(workspaceElement, 'project-find:show')
1460+
1461+
waitsForPromise ->
1462+
activationPromise
1463+
1464+
runs ->
1465+
projectFindView.findEditor.setText('items')
1466+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
1467+
1468+
waitsForPromise ->
1469+
searchPromise
1470+
1471+
it "doesn't open another panel even if the active pane is horizontally split", ->
1472+
atom.commands.dispatch(editorView, 'pane:split-right')
1473+
projectFindView.findEditor.setText('items')
1474+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
1475+
1476+
waitsForPromise ->
1477+
searchPromise
1478+
1479+
runs ->
1480+
expect(workspaceElement.querySelectorAll('.preview-pane').length).toBe(1)
1481+
14111482
describe "when language-javascript is active", ->
14121483
beforeEach ->
14131484
waitsForPromise ->

spec/results-view-spec.coffee

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,35 @@ describe 'ResultsView', ->
445445
expect(editor.isPending()).toBe false
446446
expect(atom.views.getView(editor)).toHaveFocus()
447447

448-
describe "when `openProjectFindResultsInRightPane` option is true", ->
448+
describe "when `openProjectFindResultsInANewPane` option is no", ->
449449
beforeEach ->
450-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
450+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no')
451451

452452
it "always opens the file in the left pane", ->
453+
spyOn(atom.workspace, 'open').andCallThrough()
454+
atom.commands.dispatch resultsView.element, 'core:move-down'
455+
atom.commands.dispatch resultsView.element, 'core:confirm'
456+
expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {}
457+
458+
describe "when `openProjectFindResultsInANewPane` option is right pane", ->
459+
beforeEach ->
460+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane')
461+
462+
it "does not specify a pane to split", ->
453463
spyOn(atom.workspace, 'open').andCallThrough()
454464
atom.commands.dispatch resultsView.element, 'core:move-down'
455465
atom.commands.dispatch resultsView.element, 'core:confirm'
456466
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'left'
457467

458-
describe "when `openProjectFindResultsInRightPane` option is false", ->
468+
describe "when `openProjectFindResultsInANewPane` option is bottom pane", ->
459469
beforeEach ->
460-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false)
470+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane')
461471

462472
it "does not specify a pane to split", ->
463473
spyOn(atom.workspace, 'open').andCallThrough()
464474
atom.commands.dispatch resultsView.element, 'core:move-down'
465475
atom.commands.dispatch resultsView.element, 'core:confirm'
466-
expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {}
476+
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'up'
467477

468478
describe "arrowing through the list", ->
469479
it "arrows through the entire list without selecting paths and overshooting the boundaries", ->

0 commit comments

Comments
 (0)