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

Commit 43ee97e

Browse files
committed
Add an option to open results in a right or a bottom pane
1 parent d2c9830 commit 43ee97e

6 files changed

Lines changed: 111 additions & 19 deletions

File tree

lib/find.coffee

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ 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
config:
1520
focusEditorAfterSearch:
1621
type: 'boolean'
1722
default: false
1823
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.'
19-
openProjectFindResultsInRightPane:
20-
type: 'boolean'
21-
default: false
24+
openProjectFindResultsInANewPane:
25+
type: 'string'
26+
default: 'no'
27+
enum: ['no', 'right pane', 'bottom pane']
28+
title: 'Open Results in a new pane'
2229
description: 'When a project-wide search is executed, open the results in a split pane instead of a tab in the same pane.'
2330
closeFindPanelAfterSearch:
2431
type: 'boolean'

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,9 +43,11 @@ class MatchView extends View
4343
@matchText.removeClass('highlight-error').addClass('highlight-info')
4444

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"repository": "https://github.com/atom/find-and-replace",
2727
"engines": {
28-
"atom": "*"
28+
"atom": ">=1.2.0"
2929
},
3030
"dependencies": {
3131
"atom-space-pen-views": "^2.1.0",

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
@@ -421,25 +421,35 @@ describe 'ResultsView', ->
421421
runs ->
422422
expect(atom.workspace.getActivePaneItem().getPath()).toContain('sample.')
423423

424-
describe "when `openProjectFindResultsInRightPane` option is true", ->
424+
describe "when `openProjectFindResultsInANewPane` option is no", ->
425425
beforeEach ->
426-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
426+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no')
427427

428428
it "always opens the file in the left pane", ->
429+
spyOn(atom.workspace, 'open').andCallThrough()
430+
atom.commands.dispatch resultsView.element, 'core:move-down'
431+
atom.commands.dispatch resultsView.element, 'core:confirm'
432+
expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {}
433+
434+
describe "when `openProjectFindResultsInANewPane` option is right pane", ->
435+
beforeEach ->
436+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane')
437+
438+
it "does not specify a pane to split", ->
429439
spyOn(atom.workspace, 'open').andCallThrough()
430440
atom.commands.dispatch resultsView.element, 'core:move-down'
431441
atom.commands.dispatch resultsView.element, 'core:confirm'
432442
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'left'
433443

434-
describe "when `openProjectFindResultsInRightPane` option is false", ->
444+
describe "when `openProjectFindResultsInANewPane` option is bottom pane", ->
435445
beforeEach ->
436-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false)
446+
atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane')
437447

438448
it "does not specify a pane to split", ->
439449
spyOn(atom.workspace, 'open').andCallThrough()
440450
atom.commands.dispatch resultsView.element, 'core:move-down'
441451
atom.commands.dispatch resultsView.element, 'core:confirm'
442-
expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {}
452+
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'up'
443453

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

0 commit comments

Comments
 (0)