mirror of
https://github.com/usememos/memos.git
synced 2024-12-19 00:51:30 +03:00
feat: add setting for power editor (#851)
This commit is contained in:
parent
60ee602639
commit
2e2657b39d
@ -59,6 +59,7 @@ const MemoEditor = () => {
|
|||||||
const tagSelectorRef = useRef<HTMLDivElement>(null);
|
const tagSelectorRef = useRef<HTMLDivElement>(null);
|
||||||
const user = userStore.state.user as User;
|
const user = userStore.state.user as User;
|
||||||
const setting = user.setting;
|
const setting = user.setting;
|
||||||
|
const localSetting = user.localSetting;
|
||||||
const tags = tagStore.state.tags;
|
const tags = tagStore.state.tags;
|
||||||
const memoVisibilityOptionSelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => {
|
const memoVisibilityOptionSelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => {
|
||||||
return {
|
return {
|
||||||
@ -215,25 +216,26 @@ const MemoEditor = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const symbol of pairSymbols) {
|
if (localSetting.enablePowerfulEditor) {
|
||||||
if (event.key === symbol[0]) {
|
for (const symbol of pairSymbols) {
|
||||||
event.preventDefault();
|
if (event.key === symbol[0]) {
|
||||||
editorRef.current.insertText("", symbol[0], symbol[1]);
|
event.preventDefault();
|
||||||
|
editorRef.current.insertText("", symbol[0], symbol[1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event.key === "Backspace") {
|
||||||
|
const cursor = editorRef.current.getCursorPosition();
|
||||||
|
const content = editorRef.current.getContent();
|
||||||
|
const deleteChar = content?.slice(cursor - 1, cursor);
|
||||||
|
const nextChar = content?.slice(cursor, cursor + 1);
|
||||||
|
if (pairSymbols.includes(`${deleteChar}${nextChar}`)) {
|
||||||
|
event.preventDefault();
|
||||||
|
editorRef.current.removeText(cursor - 1, 2);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "Backspace") {
|
|
||||||
const cursor = editorRef.current.getCursorPosition();
|
|
||||||
const content = editorRef.current.getContent();
|
|
||||||
const deleteChar = content?.slice(cursor - 1, cursor);
|
|
||||||
const nextChar = content?.slice(cursor, cursor + 1);
|
|
||||||
if (pairSymbols.includes(`${deleteChar}${nextChar}`)) {
|
|
||||||
event.preventDefault();
|
|
||||||
editorRef.current.removeText(cursor - 1, 2);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadMultiFiles = async (files: FileList) => {
|
const uploadMultiFiles = async (files: FileList) => {
|
||||||
|
@ -45,7 +45,11 @@ const PreferencesSection = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleIsFoldingEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleIsFoldingEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
userStore.upsertLocalSetting("enableFoldMemo", event.target.checked);
|
userStore.upsertLocalSetting({ ...localSetting, enableFoldMemo: event.target.checked });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePowerfulEditorEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
userStore.upsertLocalSetting({ ...localSetting, enablePowerfulEditor: event.target.checked });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -100,6 +104,10 @@ const PreferencesSection = () => {
|
|||||||
<span className="normal-text">{t("setting.preference-section.enable-folding-memo")}</span>
|
<span className="normal-text">{t("setting.preference-section.enable-folding-memo")}</span>
|
||||||
<Switch className="ml-2" checked={localSetting.enableFoldMemo} onChange={handleIsFoldingEnabledChanged} />
|
<Switch className="ml-2" checked={localSetting.enableFoldMemo} onChange={handleIsFoldingEnabledChanged} />
|
||||||
</label>
|
</label>
|
||||||
|
<label className="form-label selector">
|
||||||
|
<span className="normal-text">{t("setting.preference-section.enable-powerful-editor")}</span>
|
||||||
|
<Switch className="ml-2" checked={localSetting.enablePowerfulEditor} onChange={handlePowerfulEditorEnabledChanged} />
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -161,6 +161,7 @@
|
|||||||
"theme": "Theme",
|
"theme": "Theme",
|
||||||
"default-memo-visibility": "Default memo visibility",
|
"default-memo-visibility": "Default memo visibility",
|
||||||
"enable-folding-memo": "Enable folding memo",
|
"enable-folding-memo": "Enable folding memo",
|
||||||
|
"enable-powerful-editor": "Enable powerful editor",
|
||||||
"editor-font-style": "Editor font style",
|
"editor-font-style": "Editor font style",
|
||||||
"mobile-editor-style": "Mobile editor style",
|
"mobile-editor-style": "Mobile editor style",
|
||||||
"default-memo-sort-option": "Memo display time",
|
"default-memo-sort-option": "Memo display time",
|
||||||
|
@ -161,6 +161,7 @@
|
|||||||
"theme": "主题",
|
"theme": "主题",
|
||||||
"default-memo-visibility": "默认 Memo 可见性",
|
"default-memo-visibility": "默认 Memo 可见性",
|
||||||
"enable-folding-memo": "开启折叠 Memo",
|
"enable-folding-memo": "开启折叠 Memo",
|
||||||
|
"enable-powerful-editor": "开启编辑器自动补全",
|
||||||
"editor-font-style": "编辑器字体样式",
|
"editor-font-style": "编辑器字体样式",
|
||||||
"mobile-editor-style": "移动端编辑器样式",
|
"mobile-editor-style": "移动端编辑器样式",
|
||||||
"default-memo-sort-option": "Memo 显示时间",
|
"default-memo-sort-option": "Memo 显示时间",
|
||||||
|
@ -15,6 +15,7 @@ const defaultSetting: Setting = {
|
|||||||
|
|
||||||
const defaultLocalSetting: LocalSetting = {
|
const defaultLocalSetting: LocalSetting = {
|
||||||
enableFoldMemo: true,
|
enableFoldMemo: true,
|
||||||
|
enablePowerfulEditor: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const convertResponseModelUser = (user: User): User => {
|
export const convertResponseModelUser = (user: User): User => {
|
||||||
@ -133,9 +134,9 @@ export const useUserStore = () => {
|
|||||||
});
|
});
|
||||||
await doSignIn();
|
await doSignIn();
|
||||||
},
|
},
|
||||||
upsertLocalSetting: async (key: keyof LocalSetting, value: any) => {
|
upsertLocalSetting: async (localSetting: LocalSetting) => {
|
||||||
storage.set({ localSetting: { [key]: value } });
|
storage.set({ localSetting });
|
||||||
store.dispatch(patchUser({ localSetting: { [key]: value } }));
|
store.dispatch(patchUser({ localSetting }));
|
||||||
},
|
},
|
||||||
patchUser: async (userPatch: UserPatch): Promise<void> => {
|
patchUser: async (userPatch: UserPatch): Promise<void> => {
|
||||||
const { data } = (await api.patchUser(userPatch)).data;
|
const { data } = (await api.patchUser(userPatch)).data;
|
||||||
|
1
web/src/types/modules/setting.d.ts
vendored
1
web/src/types/modules/setting.d.ts
vendored
@ -9,6 +9,7 @@ interface Setting {
|
|||||||
|
|
||||||
interface LocalSetting {
|
interface LocalSetting {
|
||||||
enableFoldMemo: boolean;
|
enableFoldMemo: boolean;
|
||||||
|
enablePowerfulEditor: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserLocaleSetting {
|
interface UserLocaleSetting {
|
||||||
|
Loading…
Reference in New Issue
Block a user