mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Make hotkeys for RSInput work in any language
This commit is contained in:
parent
3eada5b32d
commit
c58743bdb0
|
@ -121,11 +121,11 @@ function RSInput({
|
||||||
if (event.shiftKey && event.key === '*' && !event.altKey) {
|
if (event.shiftKey && event.key === '*' && !event.altKey) {
|
||||||
text.insertToken(TokenID.DECART);
|
text.insertToken(TokenID.DECART);
|
||||||
} else if (event.altKey) {
|
} else if (event.altKey) {
|
||||||
if (!text.processAltKey(event.key)) {
|
if (!text.processAltKey(event.code, event.shiftKey)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (!event.ctrlKey) {
|
} else if (!event.ctrlKey) {
|
||||||
const newSymbol = getSymbolSubstitute(event.key);
|
const newSymbol = getSymbolSubstitute(event.code, event.shiftKey);
|
||||||
if (!newSymbol) {
|
if (!newSymbol) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,34 +4,39 @@ import { ReactCodeMirrorRef } from '@uiw/react-codemirror';
|
||||||
|
|
||||||
import { TokenID } from '../../utils/enums';
|
import { TokenID } from '../../utils/enums';
|
||||||
|
|
||||||
export function getSymbolSubstitute(input: string): string | undefined {
|
export function getSymbolSubstitute(keyCode: string, shiftPressed: boolean): string | undefined {
|
||||||
switch (input) {
|
if (shiftPressed) {
|
||||||
case '`': return '∀';
|
switch (keyCode) {
|
||||||
case '~': return '∃';
|
case 'Backquote': return '∃';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (keyCode) {
|
||||||
|
case 'Backquote': return '∀';
|
||||||
|
|
||||||
// qwerty = μωερτπ
|
// qwerty = μωερτπ
|
||||||
// asdfgh = ασδφγλ
|
// asdfgh = ασδφγλ
|
||||||
// zxcvbn = ζξψθβη
|
// zxcvbn = ζξψθβη
|
||||||
case 'q': return 'μ';
|
case 'KeyQ': return 'μ';
|
||||||
case 'w': return 'ω';
|
case 'KeyW': return 'ω';
|
||||||
case 'e': return 'ε';
|
case 'KeyE': return 'ε';
|
||||||
case 'r': return 'ρ';
|
case 'KeyR': return 'ρ';
|
||||||
case 't': return 'τ';
|
case 'KeyT': return 'τ';
|
||||||
case 'y': return 'π';
|
case 'KeyY': return 'π';
|
||||||
|
|
||||||
case 'a': return 'α';
|
case 'KeyA': return 'α';
|
||||||
case 's': return 'σ';
|
case 'KeyS': return 'σ';
|
||||||
case 'd': return 'δ';
|
case 'KeyD': return 'δ';
|
||||||
case 'f': return 'φ';
|
case 'KeyF': return 'φ';
|
||||||
case 'g': return 'γ';
|
case 'KeyG': return 'γ';
|
||||||
case 'h': return 'λ';
|
case 'KeyH': return 'λ';
|
||||||
|
|
||||||
case 'z': return 'ζ';
|
case 'KeyZ': return 'ζ';
|
||||||
case 'x': return 'ξ';
|
case 'KeyX': return 'ξ';
|
||||||
case 'c': return 'ψ';
|
case 'KeyC': return 'ψ';
|
||||||
case 'v': return 'θ';
|
case 'KeyV': return 'θ';
|
||||||
case 'b': return 'β';
|
case 'KeyB': return 'β';
|
||||||
case 'n': return 'η';
|
case 'KeyN': return 'η';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -171,50 +176,61 @@ export class TextWrapper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
processAltKey(key: string): boolean {
|
processAltKey(keyCode: string, shiftPressed: boolean): boolean {
|
||||||
switch (key) {
|
if (shiftPressed) {
|
||||||
|
switch (keyCode) {
|
||||||
// qwert
|
// qwert
|
||||||
// asdfg
|
// asdfg
|
||||||
// zxcvb
|
// zxcvb
|
||||||
case 'q': return this.insertToken(TokenID.BIGPR);
|
case 'KeyE': return this.insertToken(TokenID.DECART);
|
||||||
case 'w': return this.insertToken(TokenID.SMALLPR);
|
|
||||||
case 'e': return this.insertToken(TokenID.BOOLEAN);
|
|
||||||
case 'E': return this.insertToken(TokenID.DECART);
|
|
||||||
case 'r': return this.insertToken(TokenID.REDUCE);
|
|
||||||
case 't': return this.insertToken(TokenID.NT_RECURSIVE_FULL);
|
|
||||||
case 'a': return this.insertToken(TokenID.INTERSECTION);
|
|
||||||
case 's': return this.insertToken(TokenID.UNION);
|
|
||||||
case 'd': return this.insertToken(TokenID.NT_DECLARATIVE_EXPR);
|
|
||||||
case 'f': return this.insertToken(TokenID.FILTER);
|
|
||||||
case 'g': return this.insertToken(TokenID.NT_IMPERATIVE_EXPR);
|
|
||||||
case 'z': return this.insertToken(TokenID.LIT_INTSET);
|
|
||||||
case 'x': return this.insertToken(TokenID.LIT_EMPTYSET);
|
|
||||||
case 'c': return this.insertToken(TokenID.CARD);
|
|
||||||
case 'v': return this.insertToken(TokenID.DEBOOL);
|
|
||||||
case 'b': return this.insertToken(TokenID.BOOL);
|
|
||||||
|
|
||||||
// `123456
|
// `123456
|
||||||
// ~!@#$%^
|
// ~!@#$%^
|
||||||
case '`': return this.insertToken(TokenID.NOT);
|
case 'Backquote': return this.insertToken(TokenID.NOTEQUAL);
|
||||||
case '~': return this.insertToken(TokenID.NOTEQUAL);
|
case 'Digit1': return this.insertToken(TokenID.NOTIN); // !
|
||||||
case '1': return this.insertToken(TokenID.IN);
|
case 'Digit2': return this.insertToken(TokenID.NOTSUBSET); // @
|
||||||
case '!': return this.insertToken(TokenID.NOTIN); // Alt + 1
|
case 'Digit3': return this.insertToken(TokenID.OR); // #
|
||||||
case '2': return this.insertToken(TokenID.SUBSET_OR_EQ);
|
case 'Digit4': return this.insertToken(TokenID.EQUIVALENT); // $
|
||||||
case '@': return this.insertToken(TokenID.NOTSUBSET); // Alt + 2
|
case 'Digit5': return this.insertToken(TokenID.SYMMINUS); // %
|
||||||
case '3': return this.insertToken(TokenID.AND);
|
case 'Digit6': return this.insertToken(TokenID.PUNC_ASSIGN); // ^
|
||||||
case '#': return this.insertToken(TokenID.OR); // Alt + 3
|
case 'Digit7': return this.insertToken(TokenID.GREATER_OR_EQ); // &
|
||||||
case '4': return this.insertToken(TokenID.IMPLICATION);
|
case 'Digit8': return this.insertToken(TokenID.LESSER_OR_EQ); // *
|
||||||
case '$': return this.insertToken(TokenID.EQUIVALENT); // Alt + 4
|
case 'Digit9': return this.insertToken(TokenID.PUNC_PL); // (
|
||||||
case '5': return this.insertToken(TokenID.SET_MINUS);
|
}
|
||||||
case '%': return this.insertToken(TokenID.SYMMINUS); // Alt + 5
|
} else {
|
||||||
case '6': return this.insertToken(TokenID.PUNC_ITERATE);
|
switch (keyCode) {
|
||||||
case '^': return this.insertToken(TokenID.PUNC_ASSIGN); // Alt + 6
|
// qwert
|
||||||
case '7': return this.insertToken(TokenID.SUBSET);
|
// asdfg
|
||||||
case '&': return this.insertToken(TokenID.GREATER_OR_EQ); // Alt + 7
|
// zxcvb
|
||||||
case '8': return this.insertToken(TokenID.MULTIPLY);
|
case 'KeyQ': return this.insertToken(TokenID.BIGPR);
|
||||||
case '*': return this.insertToken(TokenID.LESSER_OR_EQ); // Alt + 8
|
case 'KeyW': return this.insertToken(TokenID.SMALLPR);
|
||||||
case '(': return this.insertToken(TokenID.PUNC_PL); // Alt + 9
|
case 'KeyE': return this.insertToken(TokenID.BOOLEAN);
|
||||||
case '[': return this.insertToken(TokenID.PUNC_SL);
|
case 'KeyR': return this.insertToken(TokenID.REDUCE);
|
||||||
|
case 'KeyT': return this.insertToken(TokenID.NT_RECURSIVE_FULL);
|
||||||
|
case 'KeyA': return this.insertToken(TokenID.INTERSECTION);
|
||||||
|
case 'KeyS': return this.insertToken(TokenID.UNION);
|
||||||
|
case 'KeyD': return this.insertToken(TokenID.NT_DECLARATIVE_EXPR);
|
||||||
|
case 'KeyF': return this.insertToken(TokenID.FILTER);
|
||||||
|
case 'KeyG': return this.insertToken(TokenID.NT_IMPERATIVE_EXPR);
|
||||||
|
case 'KeyZ': return this.insertToken(TokenID.LIT_INTSET);
|
||||||
|
case 'KeyX': return this.insertToken(TokenID.LIT_EMPTYSET);
|
||||||
|
case 'KeyC': return this.insertToken(TokenID.CARD);
|
||||||
|
case 'KeyV': return this.insertToken(TokenID.DEBOOL);
|
||||||
|
case 'KeyB': return this.insertToken(TokenID.BOOL);
|
||||||
|
|
||||||
|
// `123456
|
||||||
|
// ~!@#$%^
|
||||||
|
case 'Backquote': return this.insertToken(TokenID.NOT);
|
||||||
|
case 'Digit1': return this.insertToken(TokenID.IN);
|
||||||
|
case 'Digit2': return this.insertToken(TokenID.SUBSET_OR_EQ);
|
||||||
|
case 'Digit3': return this.insertToken(TokenID.AND);
|
||||||
|
case 'Digit4': return this.insertToken(TokenID.IMPLICATION);
|
||||||
|
case 'Digit5': return this.insertToken(TokenID.SET_MINUS);
|
||||||
|
case 'Digit6': return this.insertToken(TokenID.PUNC_ITERATE);
|
||||||
|
case 'Digit7': return this.insertToken(TokenID.SUBSET);
|
||||||
|
case 'Digit8': return this.insertToken(TokenID.MULTIPLY);
|
||||||
|
case 'BracketLeft': return this.insertToken(TokenID.PUNC_SL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user