From 44770a4a8ef55c9446960d1d8f19141182eac5a3 Mon Sep 17 00:00:00 2001 From: Lykin <137850705+tiny-craft@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:35:29 +0800 Subject: [PATCH] feat: add code folding toggle to preferences --- backend/types/preferences.go | 2 ++ frontend/package.json.md5 | 2 +- .../content_value/ContentEditor.vue | 6 +++- .../content_value/ContentEntryEditor.vue | 1 + .../content_value/ContentValueString.vue | 1 + .../components/dialogs/PreferencesDialog.vue | 35 ++++++++++++------- frontend/src/langs/en-us.json | 3 +- frontend/src/langs/zh-cn.json | 3 +- frontend/src/stores/preferences.js | 9 +++++ 9 files changed, 45 insertions(+), 17 deletions(-) diff --git a/backend/types/preferences.go b/backend/types/preferences.go index dc02db0..1a1e595 100644 --- a/backend/types/preferences.go +++ b/backend/types/preferences.go @@ -26,6 +26,7 @@ func NewPreferences() Preferences { Editor: PreferencesEditor{ FontSize: consts.DEFAULT_FONT_SIZE, ShowLineNum: true, + ShowFolding: true, }, } } @@ -54,4 +55,5 @@ 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"` } diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index 31fc3ac..5c2d427 100755 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -4f3d1a3f7ec34feb214a2f699649e44e \ No newline at end of file +c645c91528721588c620ff74fd475d09 \ No newline at end of file diff --git a/frontend/src/components/content_value/ContentEditor.vue b/frontend/src/components/content_value/ContentEditor.vue index b45ec7e..e769efe 100644 --- a/frontend/src/components/content_value/ContentEditor.vue +++ b/frontend/src/components/content_value/ContentEditor.vue @@ -22,6 +22,10 @@ const props = defineProps({ type: Boolean, default: true, }, + showFolding: { + type: Boolean, + default: true, + }, border: { type: Boolean, default: false, @@ -65,7 +69,7 @@ onMounted(async () => { accessibilitySupport: 'off', wordWrap: 'on', tabSize: 2, - folding: true, + folding: props.showFolding !== false, fontFamily, fontSize, scrollBeyondLastLine: false, diff --git a/frontend/src/components/content_value/ContentEntryEditor.vue b/frontend/src/components/content_value/ContentEntryEditor.vue index 0d6a68a..f7ca93d 100644 --- a/frontend/src/components/content_value/ContentEntryEditor.vue +++ b/frontend/src/components/content_value/ContentEntryEditor.vue @@ -179,6 +179,7 @@ const onSave = () => { :content="displayValue" :language="viewLanguage" :show-line-num="prefStore.showLineNum" + :show-folding="prefStore.showFolding" class="flex-item-expand" @input="onInput" @reset="onInput" diff --git a/frontend/src/components/content_value/ContentValueString.vue b/frontend/src/components/content_value/ContentValueString.vue index 04cfd4e..b9a1ba8 100644 --- a/frontend/src/components/content_value/ContentValueString.vue +++ b/frontend/src/components/content_value/ContentValueString.vue @@ -211,6 +211,7 @@ defineExpose({ :language="viewLanguage" :loading="props.loading" :show-line-num="prefStore.showLineNum" + :show-folding="prefStore.showFolding" 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 a331621..ab7dca1 100644 --- a/frontend/src/components/dialogs/PreferencesDialog.vue +++ b/frontend/src/components/dialogs/PreferencesDialog.vue @@ -132,19 +132,28 @@ const onClose = () => { - - - - - - - - {{ $t('preferences.editor.show_linenum') }} - + + + + + + + + + + {{ $t('preferences.editor.show_linenum') }} + + + + + {{ $t('preferences.editor.show_folding') }} + + + diff --git a/frontend/src/langs/en-us.json b/frontend/src/langs/en-us.json index 8dc2492..9deac01 100644 --- a/frontend/src/langs/en-us.json +++ b/frontend/src/langs/en-us.json @@ -48,7 +48,8 @@ }, "editor": { "name": "Editor", - "show_linenum": "Show Line Numbers" + "show_linenum": "Show Line Numbers", + "show_folding": "Enable Code Folding" } }, "interface": { diff --git a/frontend/src/langs/zh-cn.json b/frontend/src/langs/zh-cn.json index 39c6df9..349e6ae 100644 --- a/frontend/src/langs/zh-cn.json +++ b/frontend/src/langs/zh-cn.json @@ -48,7 +48,8 @@ }, "editor": { "name": "编辑器", - "show_linenum": "显示行号" + "show_linenum": "显示行号", + "show_folding": "启用代码折叠" } }, "interface": { diff --git a/frontend/src/stores/preferences.js b/frontend/src/stores/preferences.js index 796ac93..d262cb3 100644 --- a/frontend/src/stores/preferences.js +++ b/frontend/src/stores/preferences.js @@ -55,6 +55,7 @@ const usePreferencesStore = defineStore('preferences', { font: '', fontSize: 14, showLineNum: true, + showFolding: true, }, lastPref: {}, fontList: [], @@ -190,6 +191,10 @@ const usePreferencesStore = defineStore('preferences', { return get(this.editor, 'showLineNum', true) }, + showFolding() { + return get(this.editor, 'showFolding', true) + }, + keyIconType() { return get(this.general, 'keyIconStyle', typesIconStyle.SHORT) }, @@ -215,6 +220,10 @@ const usePreferencesStore = defineStore('preferences', { if (showLineNum === undefined) { set(data, 'editor.showLineNum', true) } + const showFolding = get(data, 'editor.showFolding') + if (showFolding === undefined) { + set(data, 'editor.showFolding', true) + } i18nGlobal.locale.value = this.currentLanguage } },