Unverified Commit 24154c95 authored by f97's avatar f97 Committed by GitHub

feat: editor tab support (#309)

* feat: editor tab support

* Update web/src/components/MemoEditor.tsx
Co-authored-by: 's avatarboojack <stevenlgtm@gmail.com>

* chore: if return style
Co-authored-by: 's avatarboojack <stevenlgtm@gmail.com>
Co-authored-by: 's avatarhyoban <hi@hyoban.cc>
parent 0b10d24e
...@@ -2,7 +2,7 @@ import { IEmojiData } from "emoji-picker-react"; ...@@ -2,7 +2,7 @@ import { IEmojiData } from "emoji-picker-react";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"; import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { deleteMemoResource, upsertMemoResource } from "../helpers/api"; 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 { editorStateService, locationService, memoService, resourceService } from "../services";
import { useAppSelector } from "../store"; import { useAppSelector } from "../store";
import * as storage from "../helpers/storage"; import * as storage from "../helpers/storage";
...@@ -77,12 +77,18 @@ const MemoEditor: React.FC = () => { ...@@ -77,12 +77,18 @@ const MemoEditor: React.FC = () => {
}, [state, editorState.editMemoId]); }, [state, editorState.editMemoId]);
const handleKeyDown = (event: React.KeyboardEvent) => { const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === "Escape") { if (event.key === "Escape" && state.fullscreen) {
if (state.fullscreen) { handleFullscreenBtnClick();
handleFullscreenBtnClick(); return;
} }
} else if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) { if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
handleSaveBtnClick(); handleSaveBtnClick();
return;
}
if (event.key === "Tab") {
event.preventDefault();
editorRef.current?.insertText(" ".repeat(TAB_SPACE_WIDTH));
return;
} }
}; };
......
...@@ -12,3 +12,5 @@ export const VISIBILITY_SELECTOR_ITEMS = [ ...@@ -12,3 +12,5 @@ export const VISIBILITY_SELECTOR_ITEMS = [
{ text: "PROTECTED", value: "PROTECTED" }, { text: "PROTECTED", value: "PROTECTED" },
{ text: "PRIVATE", value: "PRIVATE" }, { text: "PRIVATE", value: "PRIVATE" },
]; ];
export const TAB_SPACE_WIDTH = 2;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment