From 09d5e57a17e013271772daffebb3408abc656e67 Mon Sep 17 00:00:00 2001 From: Ben Colon Date: Tue, 17 Nov 2015 11:13:31 +0100 Subject: [PATCH 1/5] Add an option to open results in a right or a bottom pane --- lib/find.coffee | 5 ++ lib/project-find-view.coffee | 4 +- lib/project/match-view.coffee | 6 ++- package.json | 10 ++-- spec/project-find-view-spec.coffee | 85 +++++++++++++++++++++++++++--- spec/results-view-spec.coffee | 20 +++++-- 6 files changed, 111 insertions(+), 19 deletions(-) diff --git a/lib/find.coffee b/lib/find.coffee index f20018e4..4dba4888 100644 --- a/lib/find.coffee +++ b/lib/find.coffee @@ -10,6 +10,11 @@ ProjectFindView = require './project-find-view' ResultsModel = require './project/results-model' ResultsPaneView = require './project/results-pane' +# To convert previous (and now unused) config setting "openProjectFindResultsInRightPane" +if atom.config.get('find-and-replace.openProjectFindResultsInRightPane') + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + atom.config.unset('find-and-replace.openProjectFindResultsInRightPane') + module.exports = activate: ({findOptions, findHistory, replaceHistory, pathsHistory}={}) -> atom.workspace.addOpener (filePath) -> diff --git a/lib/project-find-view.coffee b/lib/project-find-view.coffee index 4100fc77..5fce4c1e 100644 --- a/lib/project-find-view.coffee +++ b/lib/project-find-view.coffee @@ -299,7 +299,9 @@ class ProjectFindView extends View showResultPane: -> options = {searchAllPanes: true} - options.split = 'right' if atom.config.get('find-and-replace.openProjectFindResultsInRightPane') + switch atom.config.get('find-and-replace.openProjectFindResultsInANewPane') + when 'right pane' then options.split = 'right' + when 'bottom pane' then options.split = 'down' atom.workspace.open(ResultsPaneView.URI, options) onFinishedReplacing: (results) -> diff --git a/lib/project/match-view.coffee b/lib/project/match-view.coffee index 485b7593..a45255eb 100644 --- a/lib/project/match-view.coffee +++ b/lib/project/match-view.coffee @@ -43,8 +43,10 @@ class MatchView extends View @matchText.removeClass('highlight-error').addClass('highlight-info') confirm: (options = {}) -> - openInRightPane = atom.config.get('find-and-replace.openProjectFindResultsInRightPane') - options.split = 'left' if openInRightPane + openInNewPane = atom.config.get('find-and-replace.openProjectFindResultsInANewPane') + switch openInNewPane + when 'right pane' then options = {split: 'left'} + when 'bottom pane' then options = {split: 'up'} editorPromise = atom.workspace.open(@filePath, options) editorPromise.then (editor) => editor.setSelectedBufferRange(@match.range, autoscroll: true) diff --git a/package.json b/package.json index 869fe2fd..d6c6db93 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "repository": "https://github.com/atom/find-and-replace", "engines": { - "atom": "*" + "atom": ">=1.2.0" }, "dependencies": { "atom-space-pen-views": "^2.1.0", @@ -51,9 +51,11 @@ "default": false, "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." }, - "openProjectFindResultsInRightPane": { - "type": "boolean", - "default": false, + "openProjectFindResultsInANewPane": { + "type": "string", + "default": "no", + "enum": ["no", "right pane", "bottom pane"], + "title": "Open Results in a new pane", "description": "When a project-wide search is executed, open the results in a split pane instead of a tab in the same pane." }, "closeFindPanelAfterSearch": { diff --git a/spec/project-find-view-spec.coffee b/spec/project-find-view-spec.coffee index fd4a1efe..f351f2af 100644 --- a/spec/project-find-view-spec.coffee +++ b/spec/project-find-view-spec.coffee @@ -27,7 +27,7 @@ describe 'ProjectFindView', -> atom.project.setPaths([path.join(__dirname, 'fixtures')]) jasmine.attachToDOM(workspaceElement) - atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false) + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no') activationPromise = atom.packages.activatePackage("find-and-replace").then (options) -> mainModule = options.mainModule mainModule.createViews() @@ -329,9 +329,22 @@ describe 'ProjectFindView', -> workspaceElement.style.height = '1000px' atom.commands.dispatch editorView, 'project-find:show' - it "splits when option is true", -> + it "splits when option is right", -> initialPane = atom.workspace.getActivePane() - atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true) + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + projectFindView.findEditor.setText('items') + atom.commands.dispatch(projectFindView[0], 'core:confirm') + + waitsForPromise -> + searchPromise + + runs -> + pane1 = atom.workspace.getActivePane() + expect(pane1).not.toBe initialPane + + it "splits when option is bottom", -> + initialPane = atom.workspace.getActivePane() + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') projectFindView.findEditor.setText('items') atom.commands.dispatch(projectFindView[0], 'core:confirm') @@ -354,8 +367,8 @@ describe 'ProjectFindView', -> pane1 = atom.workspace.getActivePane() expect(pane1).toBe initialPane - it "can be duplicated", -> - atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true) + it "can be duplicated on the right", -> + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') projectFindView.findEditor.setText('items') atom.commands.dispatch(projectFindView[0], 'core:confirm') @@ -379,6 +392,31 @@ describe 'ProjectFindView', -> expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML + it "can be duplicated at the bottom", -> + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') + projectFindView.findEditor.setText('items') + atom.commands.dispatch(projectFindView[0], 'core:confirm') + + waitsForPromise -> + searchPromise + + runs -> + resultsPaneView1 = atom.views.getView(getExistingResultsPane()) + pane1 = atom.workspace.getActivePane() + pane1.splitDown(copyActiveItem: true) + + pane2 = atom.workspace.getActivePane() + resultsPaneView2 = atom.views.getView(pane2.itemForURI(ResultsPaneView.URI)) + + expect(pane1).not.toBe pane2 + expect(resultsPaneView1).not.toBe resultsPaneView2 + + length = resultsPaneView1.querySelectorAll('li > ul > li').length + expect(length).toBeGreaterThan 0 + expect(resultsPaneView2.querySelectorAll('li > ul > li')).toHaveLength length + + expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML + describe "serialization", -> it "serializes if the case, regex and whole word options", -> atom.commands.dispatch editorView, 'project-find:show' @@ -1375,9 +1413,9 @@ describe 'ProjectFindView', -> expect(projectFindView.pathsEditor).not.toHaveClass('is-focused') describe "panel opening", -> - describe "when a panel is already open", -> + describe "when a panel is already open on the right", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true) + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') waitsForPromise -> atom.workspace.open('sample.js') @@ -1408,6 +1446,39 @@ describe 'ProjectFindView', -> runs -> expect(workspaceElement.querySelectorAll('.preview-pane').length).toBe(1) + describe "when a panel is already open at the bottom", -> + beforeEach -> + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') + + waitsForPromise -> + atom.workspace.open('sample.js') + + runs -> + editor = atom.workspace.getActiveTextEditor() + editorView = atom.views.getView(editor) + atom.commands.dispatch(workspaceElement, 'project-find:show') + + waitsForPromise -> + activationPromise + + runs -> + projectFindView.findEditor.setText('items') + atom.commands.dispatch(projectFindView[0], 'core:confirm') + + waitsForPromise -> + searchPromise + + it "doesn't open another panel even if the active pane is horizontally split", -> + atom.commands.dispatch(editorView, 'pane:split-right') + projectFindView.findEditor.setText('items') + atom.commands.dispatch(projectFindView[0], 'core:confirm') + + waitsForPromise -> + searchPromise + + runs -> + expect(workspaceElement.querySelectorAll('.preview-pane').length).toBe(1) + describe "when language-javascript is active", -> beforeEach -> waitsForPromise -> diff --git a/spec/results-view-spec.coffee b/spec/results-view-spec.coffee index 64c484ff..96d6fc20 100644 --- a/spec/results-view-spec.coffee +++ b/spec/results-view-spec.coffee @@ -445,25 +445,35 @@ describe 'ResultsView', -> expect(editor.isPending()).toBe false expect(atom.views.getView(editor)).toHaveFocus() - describe "when `openProjectFindResultsInRightPane` option is true", -> + describe "when `openProjectFindResultsInANewPane` option is no", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInRightPane', true) + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no') it "always opens the file in the left pane", -> + spyOn(atom.workspace, 'open').andCallThrough() + atom.commands.dispatch resultsView.element, 'core:move-down' + atom.commands.dispatch resultsView.element, 'core:confirm' + expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {} + + describe "when `openProjectFindResultsInANewPane` option is right pane", -> + beforeEach -> + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + + it "does not specify a pane to split", -> spyOn(atom.workspace, 'open').andCallThrough() atom.commands.dispatch resultsView.element, 'core:move-down' atom.commands.dispatch resultsView.element, 'core:confirm' expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'left' - describe "when `openProjectFindResultsInRightPane` option is false", -> + describe "when `openProjectFindResultsInANewPane` option is bottom pane", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInRightPane', false) + atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') it "does not specify a pane to split", -> spyOn(atom.workspace, 'open').andCallThrough() atom.commands.dispatch resultsView.element, 'core:move-down' atom.commands.dispatch resultsView.element, 'core:confirm' - expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {} + expect(atom.workspace.open.mostRecentCall.args[1].split).toBe 'up' describe "arrowing through the list", -> it "arrows through the entire list without selecting paths and overshooting the boundaries", -> From 42d71db7ef549f9b162f3b71a2fbf6ff5c5bdbb3 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 13 Dec 2016 21:39:20 -0600 Subject: [PATCH 2/5] Fix regression of pending tab on single click The specs were failing because the confirm method overwrote its options parameter when the pane setting was set, and that parameter contains the pending flag. Now we just add the split attribute to the existing options object. --- lib/project/match-view.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/project/match-view.coffee b/lib/project/match-view.coffee index a45255eb..062c27db 100644 --- a/lib/project/match-view.coffee +++ b/lib/project/match-view.coffee @@ -45,8 +45,8 @@ class MatchView extends View confirm: (options = {}) -> openInNewPane = atom.config.get('find-and-replace.openProjectFindResultsInANewPane') switch openInNewPane - when 'right pane' then options = {split: 'left'} - when 'bottom pane' then options = {split: 'up'} + when 'right pane' then options.split = 'left' + when 'bottom pane' then options.split = 'up' editorPromise = atom.workspace.open(@filePath, options) editorPromise.then (editor) => editor.setSelectedBufferRange(@match.range, autoscroll: true) From 3ecf0fd1f5a5f593d8705839c696b4f020944fee Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 13 Dec 2016 22:36:20 -0600 Subject: [PATCH 3/5] Rename as per comment re atom/markdown-preview#368 --- lib/find.coffee | 2 +- lib/project-find-view.coffee | 5 ++--- lib/project/match-view.coffee | 11 +++++++---- package.json | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/find.coffee b/lib/find.coffee index b385c335..bce263be 100644 --- a/lib/find.coffee +++ b/lib/find.coffee @@ -13,7 +13,7 @@ ResultsPaneView = require './project/results-pane' # To convert previous (and now unused) config setting "openProjectFindResultsInRightPane" if atom.config.get('find-and-replace.openProjectFindResultsInRightPane') - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right') atom.config.unset('find-and-replace.openProjectFindResultsInRightPane') module.exports = diff --git a/lib/project-find-view.coffee b/lib/project-find-view.coffee index 0df0355a..70c1c993 100644 --- a/lib/project-find-view.coffee +++ b/lib/project-find-view.coffee @@ -302,9 +302,8 @@ class ProjectFindView extends View showResultPane: -> options = {searchAllPanes: true} - switch atom.config.get('find-and-replace.openProjectFindResultsInANewPane') - when 'right pane' then options.split = 'right' - when 'bottom pane' then options.split = 'down' + openDirection = atom.config.get('find-and-replace.openProjectFindResultsDirection') + options.split = openDirection unless openDirection is 'none' atom.workspace.open(ResultsPaneView.URI, options) onFinishedReplacing: (results) -> diff --git a/lib/project/match-view.coffee b/lib/project/match-view.coffee index 062c27db..a76fff17 100644 --- a/lib/project/match-view.coffee +++ b/lib/project/match-view.coffee @@ -43,10 +43,13 @@ class MatchView extends View @matchText.removeClass('highlight-error').addClass('highlight-info') confirm: (options = {}) -> - openInNewPane = atom.config.get('find-and-replace.openProjectFindResultsInANewPane') - switch openInNewPane - when 'right pane' then options.split = 'left' - when 'bottom pane' then options.split = 'up' + reverseDirections = + left: 'right' + right: 'left' + up: 'down' + down: 'up' + openDirection = atom.config.get('find-and-replace.openProjectFindResultsDirection') + options.split = reverseDirections[openDirection] unless openDirection is 'none' editorPromise = atom.workspace.open(@filePath, options) editorPromise.then (editor) => editor.setSelectedBufferRange(@match.range, autoscroll: true) diff --git a/package.json b/package.json index 376a4e28..2ea5458b 100644 --- a/package.json +++ b/package.json @@ -58,11 +58,11 @@ "default": false, "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." }, - "openProjectFindResultsInANewPane": { + "openProjectFindResultsDirection": { "type": "string", - "default": "no", - "enum": ["no", "right pane", "bottom pane"], - "title": "Open Results in a new pane", + "default": "none", + "enum": ["none", "right", "down"], + "title": "Direction to open results pane", "description": "When a project-wide search is executed, open the results in a split pane instead of a tab in the same pane." }, "closeFindPanelAfterSearch": { From 70a55dec369af35d0f1782bd4742ecbf3035bd37 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 13 Dec 2016 22:41:40 -0600 Subject: [PATCH 4/5] Update specs w/r/t new names --- spec/project-find-view-spec.coffee | 14 +++++++------- spec/results-view-spec.coffee | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/project-find-view-spec.coffee b/spec/project-find-view-spec.coffee index d07bdadd..8928edfc 100644 --- a/spec/project-find-view-spec.coffee +++ b/spec/project-find-view-spec.coffee @@ -28,7 +28,7 @@ describe 'ProjectFindView', -> atom.project.setPaths([path.join(__dirname, 'fixtures')]) jasmine.attachToDOM(workspaceElement) - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'none') activationPromise = atom.packages.activatePackage("find-and-replace").then (options) -> mainModule = options.mainModule mainModule.createViews() @@ -368,7 +368,7 @@ describe 'ProjectFindView', -> it "splits when option is right", -> initialPane = atom.workspace.getActivePane() - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right') projectFindView.findEditor.setText('items') atom.commands.dispatch(projectFindView[0], 'core:confirm') @@ -381,7 +381,7 @@ describe 'ProjectFindView', -> it "splits when option is bottom", -> initialPane = atom.workspace.getActivePane() - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down') projectFindView.findEditor.setText('items') atom.commands.dispatch(projectFindView[0], 'core:confirm') @@ -405,7 +405,7 @@ describe 'ProjectFindView', -> expect(pane1).toBe initialPane it "can be duplicated on the right", -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right') projectFindView.findEditor.setText('items') atom.commands.dispatch(projectFindView[0], 'core:confirm') @@ -430,7 +430,7 @@ describe 'ProjectFindView', -> expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual resultsPaneView1.querySelector('.preview-count').innerHTML it "can be duplicated at the bottom", -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down') projectFindView.findEditor.setText('items') atom.commands.dispatch(projectFindView[0], 'core:confirm') @@ -1452,7 +1452,7 @@ describe 'ProjectFindView', -> describe "panel opening", -> describe "when a panel is already open on the right", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right') waitsForPromise -> atom.workspace.open('sample.js') @@ -1485,7 +1485,7 @@ describe 'ProjectFindView', -> describe "when a panel is already open at the bottom", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down') waitsForPromise -> atom.workspace.open('sample.js') diff --git a/spec/results-view-spec.coffee b/spec/results-view-spec.coffee index 850d5658..1e238e94 100644 --- a/spec/results-view-spec.coffee +++ b/spec/results-view-spec.coffee @@ -441,9 +441,9 @@ describe 'ResultsView', -> runs -> expect(atom.views.getView(editor)).toHaveFocus() - describe "when `openProjectFindResultsInANewPane` option is no", -> + describe "when `openProjectFindResultsDirection` option is none", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'no') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'none') it "does not specify a pane to split", -> spyOn(atom.workspace, 'open').andCallThrough() @@ -451,9 +451,9 @@ describe 'ResultsView', -> atom.commands.dispatch resultsView.element, 'core:confirm' expect(atom.workspace.open.mostRecentCall.args[1]).toEqual {} - describe "when `openProjectFindResultsInANewPane` option is right pane", -> + describe "when `openProjectFindResultsDirection` option is right", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'right pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'right') it "always opens the file in the left pane", -> spyOn(atom.workspace, 'open').andCallThrough() @@ -474,9 +474,9 @@ describe 'ResultsView', -> runs -> expect(atom.views.getView(editor)).toHaveFocus() - describe "when `openProjectFindResultsInANewPane` option is bottom pane", -> + describe "when `openProjectFindResultsDirection` option is down", -> beforeEach -> - atom.config.set('find-and-replace.openProjectFindResultsInANewPane', 'bottom pane') + atom.config.set('find-and-replace.openProjectFindResultsDirection', 'down') it "always opens the file in the up pane", -> spyOn(atom.workspace, 'open').andCallThrough() From 5945db6d53c85ce5f8f6a29a03dadcd81426d408 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 13 Dec 2016 22:48:15 -0600 Subject: [PATCH 5/5] Leave the dependencies as they are in upstream --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ea5458b..c5371e3e 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ }, "repository": "https://github.com/atom/find-and-replace", "engines": { - "atom": ">=1.2.0" + "atom": "*" }, "dependencies": { "atom-space-pen-views": "^2.1.0",