Use Keyboard Key variables instead of hardcoded strings
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
84e71297ef
commit
58317b1608
9 changed files with 51 additions and 30 deletions
|
@ -38,6 +38,7 @@ import EMOJIBASE from 'emojibase-data/en/compact.json';
|
|||
import SettingsStore from "../../../settings/SettingsStore";
|
||||
import EMOTICON_REGEX from 'emojibase-regex/emoticon';
|
||||
import sdk from '../../../index';
|
||||
import {Key} from "../../../Keyboard";
|
||||
|
||||
const REGEX_EMOTICON_WHITESPACE = new RegExp('(?:^|\\s)(' + EMOTICON_REGEX.source + ')\\s$');
|
||||
|
||||
|
@ -313,19 +314,19 @@ export default class BasicMessageEditor extends React.Component {
|
|||
const modKey = IS_MAC ? event.metaKey : event.ctrlKey;
|
||||
let handled = false;
|
||||
// format bold
|
||||
if (modKey && event.key === "b") {
|
||||
if (modKey && event.key === Key.B) {
|
||||
this._onFormatAction("bold");
|
||||
handled = true;
|
||||
// format italics
|
||||
} else if (modKey && event.key === "i") {
|
||||
} else if (modKey && event.key === Key.I) {
|
||||
this._onFormatAction("italics");
|
||||
handled = true;
|
||||
// format quote
|
||||
} else if (modKey && event.key === ">") {
|
||||
} else if (modKey && event.key === Key.GREATER_THAN) {
|
||||
this._onFormatAction("quote");
|
||||
handled = true;
|
||||
// undo
|
||||
} else if (modKey && event.key === "z") {
|
||||
} else if (modKey && event.key === Key.Z) {
|
||||
if (this.historyManager.canUndo()) {
|
||||
const {parts, caret} = this.historyManager.undo(this.props.model);
|
||||
// pass matching inputType so historyManager doesn't push echo
|
||||
|
@ -334,7 +335,7 @@ export default class BasicMessageEditor extends React.Component {
|
|||
}
|
||||
handled = true;
|
||||
// redo
|
||||
} else if (modKey && event.key === "y") {
|
||||
} else if (modKey && event.key === Key.Y) {
|
||||
if (this.historyManager.canRedo()) {
|
||||
const {parts, caret} = this.historyManager.redo();
|
||||
// pass matching inputType so historyManager doesn't push echo
|
||||
|
@ -343,7 +344,7 @@ export default class BasicMessageEditor extends React.Component {
|
|||
}
|
||||
handled = true;
|
||||
// insert newline on Shift+Enter
|
||||
} else if (event.key === "Enter" && (event.shiftKey || (IS_MAC && event.altKey))) {
|
||||
} else if (event.key === Key.ENTER && (event.shiftKey || (IS_MAC && event.altKey))) {
|
||||
this._insertText("\n");
|
||||
handled = true;
|
||||
// autocomplete or enter to send below shouldn't have any modifier keys pressed.
|
||||
|
@ -353,25 +354,25 @@ export default class BasicMessageEditor extends React.Component {
|
|||
if (model.autoComplete && model.autoComplete.hasCompletions()) {
|
||||
const autoComplete = model.autoComplete;
|
||||
switch (event.key) {
|
||||
case "ArrowUp":
|
||||
case Key.ARROW_UP:
|
||||
if (!modifierPressed) {
|
||||
autoComplete.onUpArrow(event);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case "ArrowDown":
|
||||
case Key.ARROW_DOWN:
|
||||
if (!modifierPressed) {
|
||||
autoComplete.onDownArrow(event);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case "Tab":
|
||||
case Key.TAB:
|
||||
if (!metaOrAltPressed) {
|
||||
autoComplete.onTab(event);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case "Escape":
|
||||
case Key.ESCAPE:
|
||||
if (!modifierPressed) {
|
||||
autoComplete.onEscape(event);
|
||||
handled = true;
|
||||
|
@ -380,7 +381,7 @@ export default class BasicMessageEditor extends React.Component {
|
|||
default:
|
||||
return; // don't preventDefault on anything else
|
||||
}
|
||||
} else if (event.key === "Tab") {
|
||||
} else if (event.key === Key.TAB) {
|
||||
this._tabCompleteName();
|
||||
handled = true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue