Skip to content

Commit

Permalink
feat: add x-terminal:unfocus command (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech authored Aug 19, 2020
1 parent bfe94d9 commit e128b93
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
9 changes: 6 additions & 3 deletions keymaps/x-terminal.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@
"ctrl-insert": "x-terminal:copy",
"ctrl-shift-c": "x-terminal:copy",
"shift-insert": "x-terminal:paste",
"ctrl-shift-v": "x-terminal:paste"
"ctrl-shift-v": "x-terminal:paste",
"ctrl-shift-u": "x-terminal:unfocus"
},
".platform-win32 x-terminal": {
"ctrl-insert": "x-terminal:copy",
"ctrl-shift-c": "x-terminal:copy",
"shift-insert": "x-terminal:paste",
"ctrl-shift-v": "x-terminal:paste"
"ctrl-shift-v": "x-terminal:paste",
"ctrl-shift-u": "x-terminal:unfocus"
},
".platform-darwin x-terminal": {
"ctrl-shift-c": "x-terminal:copy",
"ctrl-insert": "x-terminal:copy",
"ctrl-shift-v": "x-terminal:paste",
"shift-insert": "x-terminal:paste",
"cmd-c": "x-terminal:copy",
"cmd-v": "x-terminal:paste"
"cmd-v": "x-terminal:paste",
"ctrl-shift-u": "x-terminal:unfocus"
}
}
7 changes: 6 additions & 1 deletion spec/custom-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

import { createRunner } from 'atom-jasmine3-test-runner'

module.exports = createRunner({}, () => {
module.exports = createRunner({
specHelper: {
attachToDom: true,
customMatchers: true,
},
}, () => {
// eslint-disable-next-line no-console
const warn = console.warn.bind(console)
beforeEach(() => {
Expand Down
14 changes: 14 additions & 0 deletions spec/x-terminal-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ describe('x-terminal', () => {
expect(moveDown).toHaveBeenCalledWith(1)
})
})

describe('unfocus()', () => {
it('focuses atom-workspace', async () => {
jasmine.attachToDOM(atom.views.getView(atom.workspace))
await xTerminalInstance.activate()
const model = await xTerminalInstance.openInCenterOrDock(atom.workspace)
await model.initializedPromise
await model.element.createTerminal()

expect(model.element).toHaveFocus()
xTerminalInstance.unfocus()
expect(model.element).not.toHaveFocus()
})
})
})
27 changes: 20 additions & 7 deletions src/x-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class XTerminalSingleton {
'x-terminal:restart': () => this.restart(),
'x-terminal:copy': () => this.copy(),
'x-terminal:paste': () => this.paste(),
'x-terminal:unfocus': () => this.unfocus(),
}),
)
}
Expand Down Expand Up @@ -355,14 +356,22 @@ class XTerminalSingleton {
* @return {XTerminalModel} Instance of XTerminalModel.
*/
async runCommands (commands) {
const options = this.addDefaultPosition()
const model = await this.open(
XTerminalProfilesSingleton.instance.generateNewUri(),
options,
)
await model.element.initializedPromise
let terminal
if (atom.config.get('x-terminal.terminalSettings.runInActive')) {
terminal = this.getActiveTerminal()
}

if (!terminal) {
const options = this.addDefaultPosition()
terminal = await this.open(
XTerminalProfilesSingleton.instance.generateNewUri(),
options,
)
}

await terminal.element.initializedPromise
for (const command of commands) {
model.runCommand(command)
terminal.runCommand(command)
}
}

Expand Down Expand Up @@ -498,6 +507,10 @@ class XTerminalSingleton {
this.performOperationOnItem('paste')
}

unfocus () {
atom.views.getView(atom.workspace).focus()
}

toggleProfileMenu () {
const item = atom.workspace.getActivePaneItem()
if (isXTerminalModel(item)) {
Expand Down

0 comments on commit e128b93

Please sign in to comment.