Skip to content

Commit

Permalink
feat: add Copy on Select setting
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Mar 7, 2020
1 parent e97e8ea commit 40f4e51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function resetConfigDefaults () {
title: '',
xtermOptions: '{}',
promptToStartup: false,
copyOnSelect: false,
apiOpenPosition: 'Center',
}
}
Expand Down Expand Up @@ -767,6 +768,21 @@ export const config = configOrder({
toMenuSetting: (val) => val,
},
},
copyOnSelect: {
title: 'Copy On Select',
description: 'Copy text to clipboard on selection.',
type: 'boolean',
default: configDefaults.copyOnSelect,
profileData: {
defaultProfile: configDefaults.copyOnSelect,
toUrlParam: (val) => JSON.stringify(val),
fromUrlParam: (val) => JSON.parse(val),
checkUrlParam: (val) => (val !== null && val !== ''),
toBaseProfile: (previousValue) => validateBooleanConfigSetting('x-terminal.terminalSettings.copyOnSelect', configDefaults.copyOnSelect),
fromMenuSetting: (element, baseValue) => element.checked,
toMenuSetting: (val) => val,
},
},
},
},
xtermAddons: {
Expand Down
15 changes: 13 additions & 2 deletions src/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,22 @@ class XTerminalElementImpl extends HTMLElement {
this.refitTerminal()
this.ptyProcess = null
this.ptyProcessRunning = false
this.terminal.onData((data) => {
this.disposables.add(this.terminal.onData((data) => {
if (this.isPtyProcessRunning()) {
this.ptyProcess.write(data)
}
})
}))
this.disposables.add(this.terminal.onSelectionChange(() => {
if (this.model.profile.copyOnSelect) {
let text = this.terminal.getSelection()
if (text) {
const rawLines = text.split(/\r?\n/g)
const lines = rawLines.map(line => line.replace(/\s/g, ' ').trimRight())
text = lines.join('\n')
atom.clipboard.write(text)
}
}
}))
this.disposables.add(this.profilesSingleton.onDidResetBaseProfile((baseProfile) => {
const frontEndSettings = {}
for (const data of CONFIG_DATA) {
Expand Down

0 comments on commit 40f4e51

Please sign in to comment.