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

Commit df5cf87

Browse files
author
Max Brunsfeld
authored
Merge pull request #829 from HebaruSan/results-pane-option
Results pane direction option (#585, #597)
2 parents 5b48ac4 + 5945db6 commit df5cf87

File tree

6 files changed

+126
-19
lines changed

6 files changed

+126
-19
lines changed

lib/find.coffee

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

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

lib/project-find-view.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ class ProjectFindView extends View
302302

303303
showResultPane: ->
304304
options = {searchAllPanes: true}
305-
options.split = 'right' if atom.config.get('find-and-replace.openProjectFindResultsInRightPane')
305+
openDirection = atom.config.get('find-and-replace.openProjectFindResultsDirection')
306+
options.split = openDirection unless openDirection is 'none'
306307
atom.workspace.open(ResultsPaneView.URI, options)
307308

308309
onFinishedReplacing: (results) ->

lib/project/match-view.coffee

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ 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+
reverseDirections =
47+
left: 'right'
48+
right: 'left'
49+
up: 'down'
50+
down: 'up'
51+
openDirection = atom.config.get('find-and-replace.openProjectFindResultsDirection')
52+
options.split = reverseDirections[openDirection] unless openDirection is 'none'
4853
editorPromise = atom.workspace.open(@filePath, options)
4954
editorPromise.then (editor) =>
5055
editor.setSelectedBufferRange(@match.range, autoscroll: true)

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@
5858
"default": false,
5959
"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."
6060
},
61-
"openProjectFindResultsInRightPane": {
62-
"type": "boolean",
63-
"default": false,
61+
"openProjectFindResultsDirection": {
62+
"type": "string",
63+
"default": "none",
64+
"enum": ["none", "right", "down"],
65+
"title": "Direction to open results pane",
6466
"description": "When a project-wide search is executed, open the results in a split pane instead of a tab in the same pane."
6567
},
6668
"closeFindPanelAfterSearch": {

spec/project-find-view-spec.coffee

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

31-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false)
31+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'none')
3232
activationPromise = atom.packages.activatePackage("find-and-replace").then (options) ->
3333
mainModule = options.mainModule
3434
mainModule.createViews()
@@ -366,9 +366,22 @@ describe 'ProjectFindView', ->
366366
workspaceElement.style.height = '1000px'
367367
atom.commands.dispatch editorView, 'project-find:show'
368368

369-
it "splits when option is true", ->
369+
it "splits when option is right", ->
370370
initialPane = atom.workspace.getActivePane()
371-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
371+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right')
372+
projectFindView.findEditor.setText('items')
373+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
374+
375+
waitsForPromise ->
376+
searchPromise
377+
378+
runs ->
379+
pane1 = atom.workspace.getActivePane()
380+
expect(pane1).not.toBe initialPane
381+
382+
it "splits when option is bottom", ->
383+
initialPane = atom.workspace.getActivePane()
384+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down')
372385
projectFindView.findEditor.setText('items')
373386
atom.commands.dispatch(projectFindView[0], 'core:confirm')
374387

@@ -391,8 +404,8 @@ describe 'ProjectFindView', ->
391404
pane1 = atom.workspace.getActivePane()
392405
expect(pane1).toBe initialPane
393406

394-
it "can be duplicated", ->
395-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
407+
it "can be duplicated on the right", ->
408+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right')
396409
projectFindView.findEditor.setText('items')
397410
atom.commands.dispatch(projectFindView[0], 'core:confirm')
398411

@@ -416,6 +429,31 @@ describe 'ProjectFindView', ->
416429

417430
expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML
418431

432+
it "can be duplicated at the bottom", ->
433+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down')
434+
projectFindView.findEditor.setText('items')
435+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
436+
437+
waitsForPromise ->
438+
searchPromise
439+
440+
runs ->
441+
resultsPaneView1 = atom.views.getView(getExistingResultsPane())
442+
pane1 = atom.workspace.getActivePane()
443+
pane1.splitDown(copyActiveItem: true)
444+
445+
pane2 = atom.workspace.getActivePane()
446+
resultsPaneView2 = atom.views.getView(pane2.itemForURI(ResultsPaneView.URI))
447+
448+
expect(pane1).not.toBe pane2
449+
expect(resultsPaneView1).not.toBe resultsPaneView2
450+
451+
length = resultsPaneView1.querySelectorAll('li > ul > li').length
452+
expect(length).toBeGreaterThan 0
453+
expect(resultsPaneView2.querySelectorAll('li > ul > li')).toHaveLength length
454+
455+
expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML
456+
419457
describe "serialization", ->
420458
it "serializes if the case, regex and whole word options", ->
421459
atom.commands.dispatch editorView, 'project-find:show'
@@ -1412,9 +1450,9 @@ describe 'ProjectFindView', ->
14121450
expect(projectFindView.pathsEditor).not.toHaveClass('is-focused')
14131451

14141452
describe "panel opening", ->
1415-
describe "when a panel is already open", ->
1453+
describe "when a panel is already open on the right", ->
14161454
beforeEach ->
1417-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
1455+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right')
14181456

14191457
waitsForPromise ->
14201458
atom.workspace.open('sample.js')
@@ -1445,6 +1483,39 @@ describe 'ProjectFindView', ->
14451483
runs ->
14461484
expect(workspaceElement.querySelectorAll('.preview-pane').length).toBe(1)
14471485

1486+
describe "when a panel is already open at the bottom", ->
1487+
beforeEach ->
1488+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down')
1489+
1490+
waitsForPromise ->
1491+
atom.workspace.open('sample.js')
1492+
1493+
runs ->
1494+
editor = atom.workspace.getActiveTextEditor()
1495+
editorView = atom.views.getView(editor)
1496+
atom.commands.dispatch(workspaceElement, 'project-find:show')
1497+
1498+
waitsForPromise ->
1499+
activationPromise
1500+
1501+
runs ->
1502+
projectFindView.findEditor.setText('items')
1503+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
1504+
1505+
waitsForPromise ->
1506+
searchPromise
1507+
1508+
it "doesn't open another panel even if the active pane is horizontally split", ->
1509+
atom.commands.dispatch(editorView, 'pane:split-right')
1510+
projectFindView.findEditor.setText('items')
1511+
atom.commands.dispatch(projectFindView[0], 'core:confirm')
1512+
1513+
waitsForPromise ->
1514+
searchPromise
1515+
1516+
runs ->
1517+
expect(workspaceElement.querySelectorAll('.preview-pane').length).toBe(1)
1518+
14481519
describe "when language-javascript is active", ->
14491520
beforeEach ->
14501521
waitsForPromise ->

spec/results-view-spec.coffee

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,19 @@ describe 'ResultsView', ->
441441
runs ->
442442
expect(atom.views.getView(editor)).toHaveFocus()
443443

444-
describe "when `openProjectFindResultsInRightPane` option is true", ->
444+
describe "when `openProjectFindResultsDirection` option is none", ->
445445
beforeEach ->
446-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true)
446+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'none')
447+
448+
it "does not specify a pane to split", ->
449+
spyOn(atom.workspace, 'open').andCallThrough()
450+
atom.commands.dispatch resultsView.element, 'core:move-down'
451+
atom.commands.dispatch resultsView.element, 'core:confirm'
452+
expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {}
453+
454+
describe "when `openProjectFindResultsDirection` option is right", ->
455+
beforeEach ->
456+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right')
447457

448458
it "always opens the file in the left pane", ->
449459
spyOn(atom.workspace, 'open').andCallThrough()
@@ -464,15 +474,28 @@ describe 'ResultsView', ->
464474
runs ->
465475
expect(atom.views.getView(editor)).toHaveFocus()
466476

467-
describe "when `openProjectFindResultsInRightPane` option is false", ->
477+
describe "when `openProjectFindResultsDirection` option is down", ->
468478
beforeEach ->
469-
atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false)
479+
atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down')
470480

471-
it "does not specify a pane to split", ->
481+
it "always opens the file in the up pane", ->
472482
spyOn(atom.workspace, 'open').andCallThrough()
473483
atom.commands.dispatch resultsView.element, 'core:move-down'
474484
atom.commands.dispatch resultsView.element, 'core:confirm'
475-
expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {}
485+
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'up'
486+
487+
describe "when a search result is single-clicked", ->
488+
it "opens the file containing the result in pending state", ->
489+
pathNode = resultsView.find(".search-result")[0]
490+
pathNode.dispatchEvent(buildMouseEvent('mousedown', target: pathNode, which: 1))
491+
editor = null
492+
waitsFor ->
493+
editor = atom.workspace.getActiveTextEditor()
494+
waitsFor ->
495+
atom.workspace.getActivePane().getPendingItem() is editor
496+
497+
runs ->
498+
expect(atom.views.getView(editor)).toHaveFocus()
476499

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

0 commit comments

Comments
 (0)