feat: add code folding toggle to preferences

This commit is contained in:
Lykin 2023-12-12 10:35:29 +08:00
parent d819502bc7
commit 44770a4a8e
9 changed files with 45 additions and 17 deletions

View File

@ -26,6 +26,7 @@ func NewPreferences() Preferences {
Editor: PreferencesEditor{ Editor: PreferencesEditor{
FontSize: consts.DEFAULT_FONT_SIZE, FontSize: consts.DEFAULT_FONT_SIZE,
ShowLineNum: true, ShowLineNum: true,
ShowFolding: true,
}, },
} }
} }
@ -54,4 +55,5 @@ 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"` ShowLineNum bool `json:"showLineNum" yaml:"show_line_num"`
ShowFolding bool `json:"showFolding" yaml:"show_folding"`
} }

View File

@ -1 +1 @@
4f3d1a3f7ec34feb214a2f699649e44e c645c91528721588c620ff74fd475d09

View File

@ -22,6 +22,10 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
showFolding: {
type: Boolean,
default: true,
},
border: { border: {
type: Boolean, type: Boolean,
default: false, default: false,
@ -65,7 +69,7 @@ onMounted(async () => {
accessibilitySupport: 'off', accessibilitySupport: 'off',
wordWrap: 'on', wordWrap: 'on',
tabSize: 2, tabSize: 2,
folding: true, folding: props.showFolding !== false,
fontFamily, fontFamily,
fontSize, fontSize,
scrollBeyondLastLine: false, scrollBeyondLastLine: false,

View File

@ -179,6 +179,7 @@ const onSave = () => {
:content="displayValue" :content="displayValue"
:language="viewLanguage" :language="viewLanguage"
:show-line-num="prefStore.showLineNum" :show-line-num="prefStore.showLineNum"
:show-folding="prefStore.showFolding"
class="flex-item-expand" class="flex-item-expand"
@input="onInput" @input="onInput"
@reset="onInput" @reset="onInput"

View File

@ -211,6 +211,7 @@ defineExpose({
:language="viewLanguage" :language="viewLanguage"
:loading="props.loading" :loading="props.loading"
:show-line-num="prefStore.showLineNum" :show-line-num="prefStore.showLineNum"
:show-folding="prefStore.showFolding"
class="flex-item-expand" class="flex-item-expand"
style="height: 100%" style="height: 100%"
@input="onInput" @input="onInput"

View File

@ -132,19 +132,28 @@ const onClose = () => {
<n-tab-pane :tab="$t('preferences.editor.name')" display-directive="show" name="editor"> <n-tab-pane :tab="$t('preferences.editor.name')" display-directive="show" name="editor">
<n-form :disabled="loading" :model="prefStore.editor" :show-require-mark="false" label-placement="top"> <n-form :disabled="loading" :model="prefStore.editor" :show-require-mark="false" label-placement="top">
<n-form-item :label="$t('preferences.general.font')" required> <n-grid :x-gap="10">
<n-form-item-gi :label="$t('preferences.general.font')" :span="24" required>
<n-select <n-select
v-model:value="prefStore.editor.font" v-model:value="prefStore.editor.font"
:input-props="{ spellcheck: 'false' }" :input-props="{ spellcheck: 'false' }"
:options="prefStore.fontOption" :options="prefStore.fontOption"
filterable /> filterable />
</n-form-item> </n-form-item-gi>
<n-form-item :label="$t('preferences.general.font_size')"> <n-form-item-gi :label="$t('preferences.general.font_size')" :show-feedback="false" :span="24">
<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-gi>
<n-form-item-gi :show-feedback="false" :span="24">
<n-checkbox v-model:checked="prefStore.editor.showLineNum"> <n-checkbox v-model:checked="prefStore.editor.showLineNum">
{{ $t('preferences.editor.show_linenum') }} {{ $t('preferences.editor.show_linenum') }}
</n-checkbox> </n-checkbox>
</n-form-item-gi>
<n-form-item-gi :show-feedback="false" :span="24">
<n-checkbox v-model:checked="prefStore.editor.showFolding">
{{ $t('preferences.editor.show_folding') }}
</n-checkbox>
</n-form-item-gi>
</n-grid>
</n-form> </n-form>
</n-tab-pane> </n-tab-pane>
</n-tabs> </n-tabs>

View File

@ -48,7 +48,8 @@
}, },
"editor": { "editor": {
"name": "Editor", "name": "Editor",
"show_linenum": "Show Line Numbers" "show_linenum": "Show Line Numbers",
"show_folding": "Enable Code Folding"
} }
}, },
"interface": { "interface": {

View File

@ -48,7 +48,8 @@
}, },
"editor": { "editor": {
"name": "编辑器", "name": "编辑器",
"show_linenum": "显示行号" "show_linenum": "显示行号",
"show_folding": "启用代码折叠"
} }
}, },
"interface": { "interface": {

View File

@ -55,6 +55,7 @@ const usePreferencesStore = defineStore('preferences', {
font: '', font: '',
fontSize: 14, fontSize: 14,
showLineNum: true, showLineNum: true,
showFolding: true,
}, },
lastPref: {}, lastPref: {},
fontList: [], fontList: [],
@ -190,6 +191,10 @@ const usePreferencesStore = defineStore('preferences', {
return get(this.editor, 'showLineNum', true) return get(this.editor, 'showLineNum', true)
}, },
showFolding() {
return get(this.editor, 'showFolding', true)
},
keyIconType() { keyIconType() {
return get(this.general, 'keyIconStyle', typesIconStyle.SHORT) return get(this.general, 'keyIconStyle', typesIconStyle.SHORT)
}, },
@ -215,6 +220,10 @@ const usePreferencesStore = defineStore('preferences', {
if (showLineNum === undefined) { if (showLineNum === undefined) {
set(data, 'editor.showLineNum', true) set(data, 'editor.showLineNum', true)
} }
const showFolding = get(data, 'editor.showFolding')
if (showFolding === undefined) {
set(data, 'editor.showFolding', true)
}
i18nGlobal.locale.value = this.currentLanguage i18nGlobal.locale.value = this.currentLanguage
} }
}, },