feat: allows adjustable tab size in file editor (#1354)

This commit is contained in:
Benjamin Liertz authored and GitHub committed 2023-05-07 22:01:50 +02:00
1 parent a08f9ac9a5
commit ea274c6d4a
8 files changed
+49 -4

No files matched your search

+6
View File
@@ -19,6 +19,7 @@ import { gcode } from '@/plugins/StreamParserGcode'
import { indentWithTab } from '@codemirror/commands'
import { json } from '@codemirror/lang-json'
import { css } from '@codemirror/lang-css'
import { indentUnit } from '@codemirror/language'
@Component
export default class Codemirror extends Mixins(BaseMixin) {
@@ -83,6 +84,7 @@ export default class Codemirror extends Mixins(BaseMixin) {
const extensions = [
basicSetup,
mainsailTheme,
indentUnit.of(' '.repeat(this.getTabSize())),
keymap.of([indentWithTab]),
EditorView.updateListener.of((update) => {
this.content = update.state?.doc.toString()
@@ -103,5 +105,9 @@ export default class Codemirror extends Mixins(BaseMixin) {
visibilityChanged(isVisible: boolean) {
if (isVisible) this.cminstance?.focus()
}
getTabSize() {
return this.$store.state.gui.editor.tabSize || 2
}
}
</script>
@@ -15,6 +15,15 @@
:dynamic-slot-width="true">
<v-switch v-model="confirmUnsavedChanges" hide-details class="mt-0"></v-switch>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row
:title="$t('Settings.EditorTab.TabSize')"
:sub-title="$t('Settings.EditorTab.TabSizeDescription')"
:dynamic-slot-width="true">
<v-select v-model="tabSize" :items="tabSizes" hide-details outlined dense attached></v-select>
</settings-row>
<v-divider class="my-2"></v-divider>
<settings-row
:title="$t('Settings.EditorTab.KlipperRestartMethod')"
@@ -67,6 +76,14 @@ export default class SettingsEditorTab extends Mixins(BaseMixin) {
},
]
get tabSizes() {
const spaces = [2, 4, 6, 8]
return spaces.map((space) => ({
text: this.$t('Settings.EditorTab.Spaces', { count: space }),
value: space,
}))
}
get escToClose() {
return this.$store.state.gui.editor.escToClose
}
@@ -83,6 +100,14 @@ export default class SettingsEditorTab extends Mixins(BaseMixin) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.confirmUnsavedChanges', value: newVal })
}
get tabSize() {
return this.$store.state.gui.editor.tabSize || 2
}
set tabSize(newVal) {
this.$store.dispatch('gui/saveSetting', { name: 'editor.tabSize', value: newVal })
}
get klipperRestartMethod() {
return this.$store.state.gui.editor.klipperRestartMethod
}