perf: add "show line numbers" preferences option

This commit is contained in:
Lykin 2023-12-03 22:51:14 +08:00
parent 8573d24a47
commit a78c6cdb26
7 changed files with 33 additions and 9 deletions

View File

@ -24,6 +24,7 @@ func NewPreferences() Preferences {
},
Editor: PreferencesEditor{
FontSize: consts.DEFAULT_FONT_SIZE,
ShowLineNum: true,
},
}
}
@ -50,4 +51,5 @@ type PreferencesGeneral struct {
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,omitempty"`
}

View File

@ -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"

View File

@ -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<string|number[]>}
@ -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"

View File

@ -123,6 +123,9 @@ const onClose = () => {
<n-form-item :label="$t('preferences.general.font_size')">
<n-input-number v-model:value="prefStore.editor.fontSize" :max="65535" :min="1" />
</n-form-item>
<n-checkbox v-model:checked="prefStore.editor.showLineNum">
{{ $t('preferences.editor.show_linenum') }}
</n-checkbox>
</n-form>
</n-tab-pane>
</n-tabs>

View File

@ -42,7 +42,8 @@
"auto_check_update": "Automatically check for updates"
},
"editor": {
"name": "Editor"
"name": "Editor",
"show_linenum": "Show Line Numbers"
}
},
"interface": {

View File

@ -42,7 +42,8 @@
"auto_check_update": "自动检查更新"
},
"editor": {
"name": "编辑器"
"name": "编辑器",
"show_linenum": "显示行号"
}
},
"interface": {

View File

@ -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
}
},