mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Provide clear selection of text in terminal view (#608)
* Permit clearSelection on text enter and mouse selection. Fix #591 * Add config for copyOnSelect * Update with descriptive comment
This commit is contained in:
parent
77597da1d3
commit
fd351a5b93
6 changed files with 39 additions and 4 deletions
|
|
@ -64,7 +64,10 @@ module.exports = {
|
||||||
env: {},
|
env: {},
|
||||||
|
|
||||||
// set to false for no bell
|
// set to false for no bell
|
||||||
bell: 'SOUND'
|
bell: 'SOUND',
|
||||||
|
|
||||||
|
// if true, selected text will automatically be copied to the clipboard
|
||||||
|
copyOnSelect: false
|
||||||
|
|
||||||
// URL to custom bell
|
// URL to custom bell
|
||||||
// bellSoundURL: 'http://example.com/bell.mp3',
|
// bellSoundURL: 'http://example.com/bell.mp3',
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,12 @@ export default class Term extends Component {
|
||||||
this.term.prefs_.set('audible-bell-sound', '');
|
this.term.prefs_.set('audible-bell-sound', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.copyOnSelect) {
|
||||||
|
this.term.prefs_.set('copy-on-select', true);
|
||||||
|
} else {
|
||||||
|
this.term.prefs_.set('copy-on-select', false);
|
||||||
|
}
|
||||||
|
|
||||||
this.term.onTerminalReady = () => {
|
this.term.onTerminalReady = () => {
|
||||||
const io = this.term.io.push();
|
const io = this.term.io.push();
|
||||||
io.onVTKeystroke = io.sendString = props.onData;
|
io.onVTKeystroke = io.sendString = props.onData;
|
||||||
|
|
@ -215,6 +221,12 @@ export default class Term extends Component {
|
||||||
} else {
|
} else {
|
||||||
this.term.prefs_.set('audible-bell-sound', '');
|
this.term.prefs_.set('audible-bell-sound', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.props.copyOnSelect) {
|
||||||
|
this.term.prefs_.set('copy-on-select', true);
|
||||||
|
} else {
|
||||||
|
this.term.prefs_.set('copy-on-select', false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,8 @@ export default class Terms extends Component {
|
||||||
onData: this.bind(this.props.onData, null, uid),
|
onData: this.bind(this.props.onData, null, uid),
|
||||||
onURLAbort: this.bind(this.props.onURLAbort, null, uid),
|
onURLAbort: this.bind(this.props.onURLAbort, null, uid),
|
||||||
bell: this.props.bell,
|
bell: this.props.bell,
|
||||||
bellSoundURL: this.props.bellSoundURL
|
bellSoundURL: this.props.bellSoundURL,
|
||||||
|
copyOnSelect: this.props.copyOnSelect
|
||||||
});
|
});
|
||||||
return <div
|
return <div
|
||||||
key={`d${uid}`}
|
key={`d${uid}`}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ const TermsContainer = connect(
|
||||||
foregroundColor: state.ui.foregroundColor,
|
foregroundColor: state.ui.foregroundColor,
|
||||||
backgroundColor: state.ui.backgroundColor,
|
backgroundColor: state.ui.backgroundColor,
|
||||||
bell: state.ui.bell,
|
bell: state.ui.bell,
|
||||||
bellSoundURL: state.ui.bellSoundURL
|
bellSoundURL: state.ui.bellSoundURL,
|
||||||
|
copyOnSelect: state.ui.copyOnSelect
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
(dispatch) => {
|
(dispatch) => {
|
||||||
|
|
|
||||||
13
lib/hterm.js
13
lib/hterm.js
|
|
@ -2,6 +2,12 @@ import { hterm, lib } from 'hterm-umdjs';
|
||||||
|
|
||||||
hterm.defaultStorage = new lib.Storage.Memory();
|
hterm.defaultStorage = new lib.Storage.Memory();
|
||||||
|
|
||||||
|
// clear selection range of current selected term view
|
||||||
|
// Fix event when terminal text is selected and keyboard action is invoked
|
||||||
|
hterm.Terminal.prototype.clearSelection = function () {
|
||||||
|
this.document_.getSelection().removeAllRanges();
|
||||||
|
};
|
||||||
|
|
||||||
// override double click behavior to copy
|
// override double click behavior to copy
|
||||||
const oldMouse = hterm.Terminal.prototype.onMouse_;
|
const oldMouse = hterm.Terminal.prototype.onMouse_;
|
||||||
hterm.Terminal.prototype.onMouse_ = function (e) {
|
hterm.Terminal.prototype.onMouse_ = function (e) {
|
||||||
|
|
@ -85,6 +91,11 @@ hterm.Keyboard.prototype.onKeyDown_ = function (e) {
|
||||||
|
|
||||||
if (e.metaKey || e.altKey) {
|
if (e.metaKey || e.altKey) {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
// Test for valid keys in order to clear the terminal selection
|
||||||
|
if ((!e.ctrlKey || e.code !== 'ControlLeft') && !e.shiftKey && e.code !== 'CapsLock') {
|
||||||
|
this.terminal.clearSelection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return oldKeyDown.call(this, e);
|
return oldKeyDown.call(this, e);
|
||||||
};
|
};
|
||||||
|
|
@ -93,6 +104,8 @@ const oldKeyPress = hterm.Keyboard.prototype.onKeyPress_;
|
||||||
hterm.Keyboard.prototype.onKeyPress_ = function (e) {
|
hterm.Keyboard.prototype.onKeyPress_ = function (e) {
|
||||||
if (e.metaKey) {
|
if (e.metaKey) {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
this.terminal.clearSelection();
|
||||||
}
|
}
|
||||||
return oldKeyPress.call(this, e);
|
return oldKeyPress.call(this, e);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@ const initial = Immutable({
|
||||||
updateVersion: null,
|
updateVersion: null,
|
||||||
updateNotes: null,
|
updateNotes: null,
|
||||||
bell: 'SOUND',
|
bell: 'SOUND',
|
||||||
bellSoundURL: 'lib-resource:hterm/audio/bell'
|
bellSoundURL: 'lib-resource:hterm/audio/bell',
|
||||||
|
copyOnSelect: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const reducer = (state = initial, action) => {
|
const reducer = (state = initial, action) => {
|
||||||
|
|
@ -138,6 +139,10 @@ const reducer = (state = initial, action) => {
|
||||||
ret.bellSoundURL = config.bellSoundURL || initial.bellSoundURL;
|
ret.bellSoundURL = config.bellSoundURL || initial.bellSoundURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== config.copyOnSelect) {
|
||||||
|
ret.copyOnSelect = config.copyOnSelect;
|
||||||
|
}
|
||||||
|
|
||||||
if (null != config.colors) {
|
if (null != config.colors) {
|
||||||
if (Array.isArray(config.colors)) {
|
if (Array.isArray(config.colors)) {
|
||||||
const stateColors = Array.isArray(state.colors)
|
const stateColors = Array.isArray(state.colors)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue