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

Commit

Permalink
make core:copy behavior configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
t9md committed Dec 3, 2017
1 parent 6e400fb commit 8fa4f6f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/command-palette-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,14 @@ export default class CommandPaletteView {
const queryEditor = this.selectListView.refs.queryEditor
atom.commands.add(queryEditor.element, {
"core:copy": event => {
if (queryEditor.getSelectedBufferRange().isEmpty()) {
const configValue = atom.config.get('command-palette.copySelectedItemTextWhenEmptySelection')
if (configValue !== "none" && queryEditor.getSelectedBufferRange().isEmpty()) {
event.stopImmediatePropagation()
this.copyItemTextForEvent(event, "displayName")
if (configValue === "display-name") {
this.copyItemTextForEvent(null, "displayName")
} else if (configValue === "command-name") {
this.copyItemTextForEvent(null, "name")
}
}
}
})
Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@
},
"configSchema": {
"useAlternateScoring": {
"order": 0,
"type": "boolean",
"default": true,
"description": "Use an alternative scoring approach which prefers run of consecutive characters, acronyms and start of words."
},
"preserveLastSearch": {
"order": 1,
"type": "boolean",
"default": false,
"description": "Preserve the last search when reopening the command palette."
},
"copySelectedItemTextWhenEmptySelection": {
"order": 2,
"type": "string",
"default": "none",
"enum": ["none", "command-name", "display-name"],
"description": "Copy selected item's command name or display name by `core:copy`."
}
}
}
35 changes: 35 additions & 0 deletions test/command-palette-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,40 @@ describe('CommandPaletteView', () => {
atom.commands.dispatch(elementFive, 'command-palette:copy-command-name-from-context-menu')
assert(spy.calledWith("`test-xxxxx-command:command-five`"))
})

describe('core:copy behavior with command-palette.copySelectedItemTextWhenEmptySelection setting', () => {
let spy, selectListView
beforeEach(async () => {
spy = sandbox.spy(atom.clipboard, 'write')

const commandPalette = new CommandPaletteView()
selectListView = commandPalette.selectListView
await commandPalette.toggle()

selectListView.refs.queryEditor.setText('xxxxx')
await selectListView.update()
assert.equal(selectListView.getSelectedItem().name, 'test-xxxxx-command:command-one')
const elements = Array.from(selectListView.refs.items.children)
assert.equal(elements.length, 5)
})

it('[value = "none"]: copy line text', async () => {
atom.config.set("command-palette.copySelectedItemTextWhenEmptySelection", "none")
atom.commands.dispatch(selectListView.refs.queryEditor.element, 'core:copy')
assert(spy.calledWith("xxxxx")) // default behavoir of atom-text-editor
})

it('[value = "display-name"]: copy displayName of selected item', async () => {
atom.config.set("command-palette.copySelectedItemTextWhenEmptySelection", "display-name")
atom.commands.dispatch(selectListView.refs.queryEditor.element, 'core:copy')
assert(spy.calledWith("`Test Xxxxx Command: Command One`"))
})

it('[value = "command-name]": copy command name of selected item', async () => {
atom.config.set("command-palette.copySelectedItemTextWhenEmptySelection", "command-name")
atom.commands.dispatch(selectListView.refs.queryEditor.element, 'core:copy')
assert(spy.calledWith("`test-xxxxx-command:command-one`"))
})
})
})
})

0 comments on commit 8fa4f6f

Please sign in to comment.