Merge pull request #2530 from urbit/mp/soto/cmdv

soto: cmd/ctrl+v pasting, whitelist keys
This commit is contained in:
ixv 2020-03-17 17:03:16 -07:00 committed by GitHub
commit 0872419f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,14 +15,20 @@ export class Input extends Component {
}
keyPress = (e) => {
if ((e.getModifierState("Control") || event.getModifierState("Meta"))
&& e.key === "v") {
return;
}
e.preventDefault();
let ignoredKeys = ["Meta", "Alt", "Control", "Escape", "Shift",
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
"F9", "F10", "F11", "F12", "Backspace", "Unidentified",
"Delete", "Insert", "Home", "PageUp", "PageDown", "End",
"Dead", "CapsLock"
];
let allowedKeys = [
"Enter", "Backspace", "ArrowLeft", "ArrowRight", "Tab"
];
if ((e.key.length > 1) && (!(allowedKeys.includes(e.key)))) {
return;
}
// submit on enter
if (e.key === "Enter") {
@ -58,7 +64,7 @@ export class Input extends Component {
}
// capture and transmit most characters
else if (ignoredKeys.indexOf(e.key) === -1) {
else {
store.doEdit({ ins: { cha: e.key, at: this.props.cursor } });
store.setState({ cursor: this.props.cursor + 1 });
}