Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: editor tab support (#309)

f9724154c95f2be
diff --git a/web/src/components/MemoEditor.tsx b/web/src/components/MemoEditor.tsx
index 3619b5994..d4c9e99da 100644
--- a/web/src/components/MemoEditor.tsx
+++ b/web/src/components/MemoEditor.tsx
@@ -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;
}
};
diff --git a/web/src/helpers/consts.ts b/web/src/helpers/consts.ts
index ef9277e93..3c80989f7 100644
--- a/web/src/helpers/consts.ts
+++ b/web/src/helpers/consts.ts
@@ -12,3 +12,5 @@ export const VISIBILITY_SELECTOR_ITEMS = [
{ text: "PROTECTED", value: "PROTECTED" },
{ text: "PRIVATE", value: "PRIVATE" },
];
+
+export const TAB_SPACE_WIDTH = 2;