Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add editor auto focus preference #2498

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions web/src/components/MemoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const MemoEditor = (props: Props) => {

useEffect(() => {
editorRef.current?.setContent(contentCache || "");
if (user.localSetting.enableEditorAutoFocus) {
handleEditorFocus();
}
Mahoo12138 marked this conversation as resolved.
Show resolved Hide resolved
}, []);

useEffect(() => {
Expand Down
9 changes: 9 additions & 0 deletions web/src/components/Settings/PreferencesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const PreferencesSection = () => {
userStore.upsertLocalSetting({ ...localSetting, enableDoubleClickEditing: event.target.checked });
};

const handleEditorAutoFocusEnabledChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
userStore.upsertLocalSetting({ ...localSetting, enableEditorAutoFocus: event.target.checked });
};

const handleSaveTelegramUserId = async () => {
try {
await userStore.upsertUserSetting("telegram-user-id", telegramUserId);
Expand Down Expand Up @@ -87,6 +91,11 @@ const PreferencesSection = () => {
<Switch className="ml-2" checked={localSetting.enableDoubleClickEditing} onChange={handleDoubleClickEnabledChanged} />
</label>

<label className="form-label selector">
<span className="text-sm break-keep">{t("setting.preference-section.enable-editor-auto-focus")}</span>
<Switch className="ml-2" checked={localSetting.enableEditorAutoFocus} onChange={handleEditorAutoFocusEnabledChanged} />
</label>

<Divider className="!mt-3 !my-4" />

<div className="mb-2 w-full flex flex-row justify-between items-center">
Expand Down
3 changes: 2 additions & 1 deletion web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"default-resource-visibility": "Default resource visibility",
"enable-folding-memo": "Enable folding memo",
"enable-double-click": "Enable double-click to edit",
"enable-editor-auto-focus": "Enable editor auto focus",
"editor-font-style": "Editor font style",
"mobile-editor-style": "Mobile editor style",
"default-memo-sort-option": "Memo display time",
Expand Down Expand Up @@ -373,4 +374,4 @@
"memo-comment": "{{user}} has a comment on your {{memo}}.",
"version-update": "New version {{version}} is available now!"
}
}
}
1 change: 1 addition & 0 deletions web/src/locales/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
"default-resource-visibility": "默认资源可见性",
"editor-font-style": "编辑器字体样式",
"enable-double-click": "开启双击编辑",
"enable-editor-auto-focus": "开启编辑器自动聚焦",
"enable-folding-memo": "开启折叠备忘录",
"mobile-editor-style": "移动端编辑器样式",
"telegram-user-id": "Telegram UserID",
Expand Down
1 change: 1 addition & 0 deletions web/src/store/module/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaultSetting: Setting = {

const defaultLocalSetting: LocalSetting = {
enableDoubleClickEditing: false,
enableEditorAutoFocus: true,
};

export const convertResponseModelUser = (user: User): User => {
Expand Down
1 change: 1 addition & 0 deletions web/src/types/modules/setting.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Setting {

interface LocalSetting {
enableDoubleClickEditing: boolean;
enableEditorAutoFocus: boolean;
}

interface UserLocaleSetting {
Expand Down