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{ Editor: PreferencesEditor{
FontSize: consts.DEFAULT_FONT_SIZE, FontSize: consts.DEFAULT_FONT_SIZE,
ShowLineNum: true,
}, },
} }
} }
@ -50,4 +51,5 @@ type PreferencesGeneral struct {
type PreferencesEditor struct { type PreferencesEditor struct {
Font string `json:"font" yaml:"font,omitempty"` Font string `json:"font" yaml:"font,omitempty"`
FontSize int `json:"fontSize" yaml:"font_size"` 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 Pin from '@/components/icons/Pin.vue'
import OffScreen from '@/components/icons/OffScreen.vue' import OffScreen from '@/components/icons/OffScreen.vue'
import ContentEditor from '@/components/content_value/ContentEditor.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue'
import usePreferencesStore from 'stores/preferences.js'
const props = defineProps({ const props = defineProps({
field: { field: {
@ -42,6 +43,7 @@ const props = defineProps({
const themeVars = useThemeVars() const themeVars = useThemeVars()
const browserStore = useBrowserStore() const browserStore = useBrowserStore()
const prefStore = usePreferencesStore()
const emit = defineEmits([ const emit = defineEmits([
'update:field', 'update:field',
'update:value', 'update:value',
@ -169,6 +171,7 @@ const onSave = () => {
:border="true" :border="true"
:content="displayValue" :content="displayValue"
:language="viewLanguage" :language="viewLanguage"
:show-line-num="prefStore.showLineNum"
class="flex-item-expand" class="flex-item-expand"
style="height: 100%" style="height: 100%"
@input="onInput" @input="onInput"

View File

@ -14,9 +14,7 @@ import useBrowserStore from 'stores/browser.js'
import { decodeRedisKey } from '@/utils/key_convert.js' import { decodeRedisKey } from '@/utils/key_convert.js'
import FormatSelector from '@/components/content_value/FormatSelector.vue' import FormatSelector from '@/components/content_value/FormatSelector.vue'
import ContentEditor from '@/components/content_value/ContentEditor.vue' import ContentEditor from '@/components/content_value/ContentEditor.vue'
import usePreferencesStore from 'stores/preferences.js'
const i18n = useI18n()
const themeVars = useThemeVars()
const props = defineProps({ const props = defineProps({
name: String, name: String,
@ -38,6 +36,10 @@ const props = defineProps({
const emit = defineEmits(['reload', 'rename', 'delete']) const emit = defineEmits(['reload', 'rename', 'delete'])
const i18n = useI18n()
const themeVars = useThemeVars()
const prefStore = usePreferencesStore()
/** /**
* *
* @type {ComputedRef<string|number[]>} * @type {ComputedRef<string|number[]>}
@ -208,6 +210,7 @@ defineExpose({
:content="displayValue" :content="displayValue"
:language="viewLanguage" :language="viewLanguage"
:loading="props.loading" :loading="props.loading"
:show-line-num="prefStore.showLineNum"
class="flex-item-expand" class="flex-item-expand"
style="height: 100%" style="height: 100%"
@input="onInput" @input="onInput"

View File

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

View File

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

View File

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

View File

@ -36,6 +36,7 @@ const usePreferencesStore = defineStore('preferences', {
asideWidth: 300, asideWidth: 300,
windowWidth: 0, windowWidth: 0,
windowHeight: 0, windowHeight: 0,
windowMaximised: false,
}, },
general: { general: {
theme: 'auto', theme: 'auto',
@ -45,12 +46,13 @@ const usePreferencesStore = defineStore('preferences', {
scanSize: 3000, scanSize: 3000,
useSysProxy: false, useSysProxy: false,
useSysProxyHttp: false, useSysProxyHttp: false,
checkUpdate: false, checkUpdate: true,
skipVersion: '', skipVersion: '',
}, },
editor: { editor: {
font: '', font: '',
fontSize: 14, fontSize: 14,
showLineNum: false,
}, },
lastPref: {}, lastPref: {},
fontList: [], fontList: [],
@ -181,6 +183,10 @@ const usePreferencesStore = defineStore('preferences', {
autoCheckUpdate() { autoCheckUpdate() {
return get(this.general, 'checkUpdate', false) return get(this.general, 'checkUpdate', false)
}, },
showLineNum() {
return get(this.editor, 'showLineNum', true)
},
}, },
actions: { actions: {
_applyPreferences(data) { _applyPreferences(data) {
@ -198,6 +204,11 @@ const usePreferencesStore = defineStore('preferences', {
if (success) { if (success) {
this.lastPref = cloneDeep(data) this.lastPref = cloneDeep(data)
this._applyPreferences(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 i18nGlobal.locale.value = this.currentLanguage
} }
}, },