mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
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:
@ -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 = () => {
|
|||||||
}, [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 = [
|
|||||||
{ text: "PROTECTED", value: "PROTECTED" },
|
{ text: "PROTECTED", value: "PROTECTED" },
|
||||||
{ text: "PRIVATE", value: "PRIVATE" },
|
{ text: "PRIVATE", value: "PRIVATE" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const TAB_SPACE_WIDTH = 2;
|
||||||
|
Reference in New Issue
Block a user