Skip to content

Commit

Permalink
Merge pull request atom#1043 from t9md/ensure-open-exisiting-seting-view
Browse files Browse the repository at this point in the history
always open existing setting item in 'settings-view:open' command
  • Loading branch information
Bryant Ung authored Feb 26, 2018
2 parents 897206b + c132a7b commit 693f406
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
28 changes: 4 additions & 24 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@ const SnippetsProvider = {
}

const CONFIG_URI = 'atom://config'
const uriRegex = /config\/([a-z]+)\/?([a-zA-Z0-9_-]+)?/i

const openPanel = (settingsView, panelName, uri) => {
const match = uriRegex.exec(uri)

const options = {uri}
if (match) {
const panel = match[1]
const detail = match[2]
if (panel === 'packages' && detail != null) {
panelName = detail
options.pack = {name: detail}
if (atom.packages.getLoadedPackage(detail)) options.back = 'Packages'
}
}

settingsView.showPanel(panelName, options)
}

module.exports = {
handleURI(parsed) {
Expand All @@ -46,14 +28,12 @@ module.exports = {
if (uri.startsWith(CONFIG_URI)) {
if (settingsView == null || settingsView.destroyed) {
settingsView = this.createSettingsView({uri})
} else {
const pane = atom.workspace.paneForItem(settingsView)
if (pane) pane.activate()
}

const match = uriRegex.exec(uri)
if (match) {
let panelName = match[1]
panelName = panelName[0].toUpperCase() + panelName.slice(1)
openPanel(settingsView, panelName, uri)
}
settingsView.showPanelForURI(uri)
return settingsView
}
})
Expand Down
21 changes: 21 additions & 0 deletions lib/settings-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ export default class SettingsView {
}
}

showPanelForURI (uri) {
const regex = /config\/([a-z]+)\/?([a-zA-Z0-9_-]+)?/i
const match = regex.exec(uri)

if (match) {
const path1 = match[1]
const path2 = match[2]

if (path1 === 'packages' && path2 != null) {
this.showPanel(path2, {
uri: uri,
pack: {name: path2},
back: atom.packages.getLoadedPackage(path2) ? 'Packages' : null
})
} else {
const panelName = path1[0].toUpperCase() + path1.slice(1)
this.showPanel(panelName, {uri})
}
}
}

appendPanel (panel, options) {
for (let i = 0; i < this.refs.panels.children.length; i++) {
this.refs.panels.children[i].style.display = 'none'
Expand Down
25 changes: 25 additions & 0 deletions spec/settings-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ describe "SettingsView", ->
expect(atom.workspace.getActivePaneItem().activePanel)
.toEqual name: 'Core', options: {}

it "always open existing item in workspace", ->
center = atom.workspace.getCenter()
[pane1, pane2] = []

waitsForPromise -> atom.workspace.open(null, split: 'right')
runs ->
expect(center.getPanes()).toHaveLength(2)
[pane1, pane2] = center.getPanes()
expect(atom.workspace.getActivePane()).toBe(pane2)

openWithCommand('settings-view:open')

runs ->
expect(atom.workspace.getActivePaneItem().activePanel).toEqual name: 'Core', options: {}
expect(atom.workspace.getActivePane()).toBe(pane2)

runs ->
pane1.activate()

openWithCommand('settings-view:open')

runs ->
expect(atom.workspace.getActivePaneItem().activePanel).toEqual name: 'Core', options: {}
expect(atom.workspace.getActivePane()).toBe(pane2)

describe "settings-view:core", ->
it "opens the core settings view", ->
openWithCommand('settings-view:editor')
Expand Down

0 comments on commit 693f406

Please sign in to comment.