From 0b37b89f9b8da4c5b392cd33ca5a29ade1d425b1 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Tue, 23 Jan 2024 19:44:11 +0800 Subject: [PATCH] perf: support select multiple font and input custom font name #115 #130 --- backend/types/preferences.go | 30 ++++----- .../components/content_value/ContentCli.vue | 11 ++++ .../content_value/ContentEditor.vue | 16 +---- .../components/dialogs/PreferencesDialog.vue | 63 +++++++++++++------ frontend/src/components/icons/Subscribe.vue | 2 +- .../src/components/sidebar/ConnectionPane.vue | 4 +- frontend/src/components/sidebar/Ribbon.vue | 6 +- frontend/src/langs/en-us.json | 2 +- frontend/src/langs/pt-br.json | 1 - frontend/src/langs/zh-cn.json | 2 +- frontend/src/stores/preferences.js | 54 ++++++++++------ 11 files changed, 118 insertions(+), 73 deletions(-) diff --git a/backend/types/preferences.go b/backend/types/preferences.go index 01815ec..18b73ff 100644 --- a/backend/types/preferences.go +++ b/backend/types/preferences.go @@ -41,21 +41,23 @@ type PreferencesBehavior struct { } type PreferencesGeneral struct { - Theme string `json:"theme" yaml:"theme"` - Language string `json:"language" yaml:"language"` - Font string `json:"font" yaml:"font,omitempty"` - FontSize int `json:"fontSize" yaml:"font_size"` - ScanSize int `json:"scanSize" yaml:"scan_size"` - KeyIconStyle int `json:"keyIconStyle" yaml:"key_icon_style"` - UseSysProxy bool `json:"useSysProxy" yaml:"use_sys_proxy,omitempty"` - UseSysProxyHttp bool `json:"useSysProxyHttp" yaml:"use_sys_proxy_http,omitempty"` - CheckUpdate bool `json:"checkUpdate" yaml:"check_update"` - SkipVersion string `json:"skipVersion" yaml:"skip_version,omitempty"` + Theme string `json:"theme" yaml:"theme"` + Language string `json:"language" yaml:"language"` + Font string `json:"font" yaml:"font,omitempty"` + FontFamily []string `json:"fontFamily" yaml:"font_family,omitempty"` + FontSize int `json:"fontSize" yaml:"font_size"` + ScanSize int `json:"scanSize" yaml:"scan_size"` + KeyIconStyle int `json:"keyIconStyle" yaml:"key_icon_style"` + UseSysProxy bool `json:"useSysProxy" yaml:"use_sys_proxy,omitempty"` + UseSysProxyHttp bool `json:"useSysProxyHttp" yaml:"use_sys_proxy_http,omitempty"` + CheckUpdate bool `json:"checkUpdate" yaml:"check_update"` + SkipVersion string `json:"skipVersion" yaml:"skip_version,omitempty"` } type PreferencesEditor struct { - Font string `json:"font" yaml:"font,omitempty"` - FontSize int `json:"fontSize" yaml:"font_size"` - ShowLineNum bool `json:"showLineNum" yaml:"show_line_num"` - ShowFolding bool `json:"showFolding" yaml:"show_folding"` + Font string `json:"font" yaml:"font,omitempty"` + FontFamily []string `json:"fontFamily" yaml:"font_family,omitempty"` + FontSize int `json:"fontSize" yaml:"font_size"` + ShowLineNum bool `json:"showLineNum" yaml:"show_line_num"` + ShowFolding bool `json:"showFolding" yaml:"show_folding"` } diff --git a/frontend/src/components/content_value/ContentCli.vue b/frontend/src/components/content_value/ContentCli.vue index bd8ceb9..17532d3 100644 --- a/frontend/src/components/content_value/ContentCli.vue +++ b/frontend/src/components/content_value/ContentCli.vue @@ -34,6 +34,7 @@ let fitAddonInst = null const newTerm = () => { const term = new Terminal({ allowProposedApi: true, + fontFamily: prefStore.general.fontFamily, fontSize: prefStore.general.fontSize || 14, cursorBlink: true, disableStdin: false, @@ -89,6 +90,16 @@ defineExpose({ resizeTerm, }) +// watch( +// () => prefStore.general.font, +// (font = undefined) => { +// if (termInst != null) { +// termInst.options.fontFamily = font || 'Courier New' +// } +// resizeTerm() +// }, +// ) + watch( () => prefStore.general.fontSize, (fontSize) => { diff --git a/frontend/src/components/content_value/ContentEditor.vue b/frontend/src/components/content_value/ContentEditor.vue index 642d45d..eeaa696 100644 --- a/frontend/src/components/content_value/ContentEditor.vue +++ b/frontend/src/components/content_value/ContentEditor.vue @@ -58,7 +58,7 @@ const readonlyValue = computed(() => { const pref = usePreferencesStore() onMounted(async () => { if (editorRef.value != null) { - const { fontSize, fontFamily = undefined } = pref.editorFont + const { fontSize, fontFamily = ['monaco'] } = pref.editorFont editorNode = monaco.editor.create(editorRef.value, { // value: props.content, theme: pref.isDark ? 'rdm-dark' : 'rdm-light', @@ -151,21 +151,11 @@ watch( ) watch( - () => pref.editorFont.fontSize, - (fontSize) => { + () => pref.editorFont, + ({ fontSize, fontFamily }) => { if (editorNode != null) { editorNode.updateOptions({ fontSize, - }) - } - }, -) - -watch( - () => pref.editorFont.fontFamily, - (fontFamily = undefined) => { - if (editorNode != null) { - editorNode.updateOptions({ fontFamily, }) } diff --git a/frontend/src/components/dialogs/PreferencesDialog.vue b/frontend/src/components/dialogs/PreferencesDialog.vue index a79d72d..38e5645 100644 --- a/frontend/src/components/dialogs/PreferencesDialog.vue +++ b/frontend/src/components/dialogs/PreferencesDialog.vue @@ -5,6 +5,7 @@ import useDialog from 'stores/dialog' import usePreferencesStore from 'stores/preferences.js' import { map, sortBy } from 'lodash' import { typesIconStyle } from '@/consts/support_redis_type.js' +import Help from '@/components/icons/Help.vue' const prefStore = usePreferencesStore() @@ -92,14 +93,27 @@ const onClose = () => { :render-label="({ label, value }) => (value === 'auto' ? $t(label) : label)" filterable /> - + + + filterable + multiple + tag /> - + @@ -115,16 +129,16 @@ const onClose = () => { :options="keyOptions" :render-label="({ label }) => $t(label)" /> - - - - {{ $t('preferences.general.use_system_proxy') }} - - - {{ $t('preferences.general.use_system_proxy_http') }} - - - + + + + + + + + + + {{ $t('preferences.general.auto_check_update') }} @@ -137,14 +151,27 @@ const onClose = () => { - + + + filterable + multiple + tag /> - + diff --git a/frontend/src/components/icons/Subscribe.vue b/frontend/src/components/icons/Subscribe.vue index d8c5422..2d32080 100644 --- a/frontend/src/components/icons/Subscribe.vue +++ b/frontend/src/components/icons/Subscribe.vue @@ -14,9 +14,9 @@ const props = defineProps({