fix: When in uppercase mode, shortcuts don't work. (#413)

* fix: When entering caps lock state, pressing hotkeys does not work correctly

* More e.key -> e.code

---------

Co-authored-by: zyc9012 <zyc9012@163.com>
This commit is contained in:
zhengbin 2023-06-26 14:53:01 +08:00 committed by GitHub
parent 42afc3c190
commit 2d9d8d899f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 17 deletions

View File

@ -160,35 +160,35 @@ export function handleWithCtrlOrMetaKey(
// $("#luckysheet-rich-text-editor").html(value);
// luckysheetRangeLast($("#luckysheet-rich-text-editor")[0]);
handleFormulaInput(ctx, fxInput, cellInput, e.keyCode);
} else if (e.key === "z") {
} else if (e.code === "KeyZ") {
// Ctrl + shift + z 重做
handleRedo();
e.stopPropagation();
return;
}
} else if (e.key === "b") {
} else if (e.code === "KeyB") {
// Ctrl + B 加粗
handleBold(ctx, cellInput);
// $("#luckysheet-icon-bold").click();
} else if (e.key === "c") {
} else if (e.code === "KeyC") {
// Ctrl + C 复制
handleCopy(ctx);
// luckysheetactiveCell();
e.stopPropagation();
return;
} else if (e.key === "f") {
} else if (e.code === "KeyF") {
// Ctrl + F 查找
ctx.showSearch = true;
} else if (e.key === "h") {
} else if (e.code === "KeyH") {
// Ctrl + H 替换
ctx.showReplace = true;
// searchReplace.init();
// $("#luckysheet-search-replace #searchInput input").focus();
// } else if (e.key === "i") {
// } else if (e.code === "KeyI") {
// // Ctrl + I 斜体
// $("#luckysheet-icon-italic").click();
} else if (e.key === "v") {
} else if (e.code === "KeyV") {
// Ctrl + V 粘贴
// if (isEditMode()) {
// // 此模式下禁用粘贴
@ -212,7 +212,7 @@ export function handleWithCtrlOrMetaKey(
// luckysheetactiveCell();
e.stopPropagation();
return;
} else if (e.key === "x") {
} else if (e.code === "KeyX") {
// Ctrl + X 剪切
// 复制时存在格式刷状态,取消格式刷
if (ctx.luckysheetPaintModelOn) {
@ -268,7 +268,7 @@ export function handleWithCtrlOrMetaKey(
e.stopPropagation();
return;
} else if (e.key === "z") {
} else if (e.code === "KeyZ") {
// Ctrl + Z 撤销
handleUndo();
e.stopPropagation();
@ -349,7 +349,7 @@ export function handleWithCtrlOrMetaKey(
$("#luckysheet-rich-text-editor"),
e.keyCode
);
} */ else if (e.key === "a") {
} */ else if (e.code === "KeyA") {
// Ctrl + A 全选
// $("#luckysheet-left-top").trigger("mousedown");
// $(document).trigger("mouseup");

View File

@ -9,8 +9,8 @@ import { getFlowdata } from "../../src/context";
import { groupValuesRefresh } from "../../src";
describe("keyboard", () => {
const keypressWithCtrlPressed = (key) => {
return new KeyboardEvent("ctrl+[key]", { key, ctrlKey: true });
const keypressWithCtrlPressed = (key, code) => {
return new KeyboardEvent("ctrl+[key]", { key, ctrlKey: true, code });
};
const getContext = () =>
contextFactory({
@ -51,7 +51,7 @@ describe("keyboard", () => {
handleWithCtrlOrMetaKey(
ctx,
cache,
keypressWithCtrlPressed("b"),
keypressWithCtrlPressed("b", "KeyB"),
cellInput,
fxInput,
() => {},
@ -70,7 +70,7 @@ describe("keyboard", () => {
handleWithCtrlOrMetaKey(
ctx,
cache,
keypressWithCtrlPressed("z"),
keypressWithCtrlPressed("z", "KeyZ"),
cellInput,
fxInput,
undo
@ -99,7 +99,7 @@ describe("keyboard", () => {
handleWithCtrlOrMetaKey(
ctx,
cache,
keypressWithCtrlPressed("a"),
keypressWithCtrlPressed("a", "KeyA"),
cellInput,
fxInput,
() => {},

View File

@ -546,7 +546,7 @@ const Workbook = React.forwardRef<WorkbookInstance, Settings & AdditionalProps>(
// handling undo and redo ahead because handleUndo and handleRedo
// themselves are calling setContext, and should not be nested
// in setContextWithProduce.
if ((e.ctrlKey || e.metaKey) && e.key === "z") {
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
if (e.shiftKey) {
handleRedo();
} else {
@ -555,7 +555,7 @@ const Workbook = React.forwardRef<WorkbookInstance, Settings & AdditionalProps>(
e.stopPropagation();
return;
}
if ((e.ctrlKey || e.metaKey) && e.key === "y") {
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
handleRedo();
e.stopPropagation();
e.preventDefault();