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

View File

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

View File

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