feat: editor tab support (#309)

* feat: editor tab support

* Update web/src/components/MemoEditor.tsx

Co-authored-by: boojack <stevenlgtm@gmail.com>

* chore: if return style

Co-authored-by: boojack <stevenlgtm@gmail.com>
Co-authored-by: hyoban <hi@hyoban.cc>
This commit is contained in:
f97 2022-10-19 17:19:50 +07:00 committed by GitHub
parent 0b10d24eb2
commit 24154c95f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -2,7 +2,7 @@ import { IEmojiData } from "emoji-picker-react";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { deleteMemoResource, upsertMemoResource } from "../helpers/api";
import { UNKNOWN_ID } from "../helpers/consts";
import { TAB_SPACE_WIDTH, UNKNOWN_ID } from "../helpers/consts";
import { editorStateService, locationService, memoService, resourceService } from "../services";
import { useAppSelector } from "../store";
import * as storage from "../helpers/storage";
@ -77,12 +77,18 @@ const MemoEditor: React.FC = () => {
}, [state, editorState.editMemoId]);
const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === "Escape") {
if (state.fullscreen) {
handleFullscreenBtnClick();
}
} else if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
if (event.key === "Escape" && state.fullscreen) {
handleFullscreenBtnClick();
return;
}
if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
handleSaveBtnClick();
return;
}
if (event.key === "Tab") {
event.preventDefault();
editorRef.current?.insertText(" ".repeat(TAB_SPACE_WIDTH));
return;
}
};

View file

@ -12,3 +12,5 @@ export const VISIBILITY_SELECTOR_ITEMS = [
{ text: "PROTECTED", value: "PROTECTED" },
{ text: "PRIVATE", value: "PRIVATE" },
];
export const TAB_SPACE_WIDTH = 2;