From a78c6cdb265920125296a1e2508a662f95e3055d Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Sun, 3 Dec 2023 22:51:14 +0800 Subject: [PATCH] perf: add "show line numbers" preferences option --- backend/types/preferences.go | 8 +++++--- .../components/content_value/ContentEntryEditor.vue | 3 +++ .../components/content_value/ContentValueString.vue | 9 ++++++--- .../src/components/dialogs/PreferencesDialog.vue | 3 +++ frontend/src/langs/en-us.json | 3 ++- frontend/src/langs/zh-cn.json | 3 ++- frontend/src/stores/preferences.js | 13 ++++++++++++- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/backend/types/preferences.go b/backend/types/preferences.go index 68f4fd9..907403a 100644 --- a/backend/types/preferences.go +++ b/backend/types/preferences.go @@ -23,7 +23,8 @@ func NewPreferences() Preferences { CheckUpdate: true, }, Editor: PreferencesEditor{ - FontSize: consts.DEFAULT_FONT_SIZE, + FontSize: consts.DEFAULT_FONT_SIZE, + ShowLineNum: true, }, } } @@ -48,6 +49,7 @@ type PreferencesGeneral struct { } type PreferencesEditor struct { - Font string `json:"font" yaml:"font,omitempty"` - FontSize int `json:"fontSize" yaml:"font_size"` + Font string `json:"font" yaml:"font,omitempty"` + FontSize int `json:"fontSize" yaml:"font_size"` + ShowLineNum bool `json:"showLineNum" yaml:"show_line_num,omitempty"` } diff --git a/frontend/src/components/content_value/ContentEntryEditor.vue b/frontend/src/components/content_value/ContentEntryEditor.vue index 270da29..ebb2821 100644 --- a/frontend/src/components/content_value/ContentEntryEditor.vue +++ b/frontend/src/components/content_value/ContentEntryEditor.vue @@ -12,6 +12,7 @@ import WindowClose from '@/components/icons/WindowClose.vue' import Pin from '@/components/icons/Pin.vue' import OffScreen from '@/components/icons/OffScreen.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue' +import usePreferencesStore from 'stores/preferences.js' const props = defineProps({ field: { @@ -42,6 +43,7 @@ const props = defineProps({ const themeVars = useThemeVars() const browserStore = useBrowserStore() +const prefStore = usePreferencesStore() const emit = defineEmits([ 'update:field', 'update:value', @@ -169,6 +171,7 @@ const onSave = () => { :border="true" :content="displayValue" :language="viewLanguage" + :show-line-num="prefStore.showLineNum" class="flex-item-expand" style="height: 100%" @input="onInput" diff --git a/frontend/src/components/content_value/ContentValueString.vue b/frontend/src/components/content_value/ContentValueString.vue index 8a26eb1..db748f3 100644 --- a/frontend/src/components/content_value/ContentValueString.vue +++ b/frontend/src/components/content_value/ContentValueString.vue @@ -14,9 +14,7 @@ import useBrowserStore from 'stores/browser.js' import { decodeRedisKey } from '@/utils/key_convert.js' import FormatSelector from '@/components/content_value/FormatSelector.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue' - -const i18n = useI18n() -const themeVars = useThemeVars() +import usePreferencesStore from 'stores/preferences.js' const props = defineProps({ name: String, @@ -38,6 +36,10 @@ const props = defineProps({ const emit = defineEmits(['reload', 'rename', 'delete']) +const i18n = useI18n() +const themeVars = useThemeVars() +const prefStore = usePreferencesStore() + /** * * @type {ComputedRef} @@ -208,6 +210,7 @@ defineExpose({ :content="displayValue" :language="viewLanguage" :loading="props.loading" + :show-line-num="prefStore.showLineNum" class="flex-item-expand" style="height: 100%" @input="onInput" diff --git a/frontend/src/components/dialogs/PreferencesDialog.vue b/frontend/src/components/dialogs/PreferencesDialog.vue index 8ceab69..ae7e6f1 100644 --- a/frontend/src/components/dialogs/PreferencesDialog.vue +++ b/frontend/src/components/dialogs/PreferencesDialog.vue @@ -123,6 +123,9 @@ const onClose = () => { + + {{ $t('preferences.editor.show_linenum') }} + diff --git a/frontend/src/langs/en-us.json b/frontend/src/langs/en-us.json index d82148d..dd01a7e 100644 --- a/frontend/src/langs/en-us.json +++ b/frontend/src/langs/en-us.json @@ -42,7 +42,8 @@ "auto_check_update": "Automatically check for updates" }, "editor": { - "name": "Editor" + "name": "Editor", + "show_linenum": "Show Line Numbers" } }, "interface": { diff --git a/frontend/src/langs/zh-cn.json b/frontend/src/langs/zh-cn.json index db07bdb..feaefe8 100644 --- a/frontend/src/langs/zh-cn.json +++ b/frontend/src/langs/zh-cn.json @@ -42,7 +42,8 @@ "auto_check_update": "自动检查更新" }, "editor": { - "name": "编辑器" + "name": "编辑器", + "show_linenum": "显示行号" } }, "interface": { diff --git a/frontend/src/stores/preferences.js b/frontend/src/stores/preferences.js index 6f527c5..a4b9424 100644 --- a/frontend/src/stores/preferences.js +++ b/frontend/src/stores/preferences.js @@ -36,6 +36,7 @@ const usePreferencesStore = defineStore('preferences', { asideWidth: 300, windowWidth: 0, windowHeight: 0, + windowMaximised: false, }, general: { theme: 'auto', @@ -45,12 +46,13 @@ const usePreferencesStore = defineStore('preferences', { scanSize: 3000, useSysProxy: false, useSysProxyHttp: false, - checkUpdate: false, + checkUpdate: true, skipVersion: '', }, editor: { font: '', fontSize: 14, + showLineNum: false, }, lastPref: {}, fontList: [], @@ -181,6 +183,10 @@ const usePreferencesStore = defineStore('preferences', { autoCheckUpdate() { return get(this.general, 'checkUpdate', false) }, + + showLineNum() { + return get(this.editor, 'showLineNum', true) + }, }, actions: { _applyPreferences(data) { @@ -198,6 +204,11 @@ const usePreferencesStore = defineStore('preferences', { if (success) { this.lastPref = cloneDeep(data) this._applyPreferences(data) + // default value + const showLineNum = get(data, 'editor.showLineNum') + if (showLineNum === undefined) { + set(data, 'editor.showLineNum', true) + } i18nGlobal.locale.value = this.currentLanguage } },