feat: allows adjustable tab size in file editor (#1354)
This commit is contained in:
parent
a08f9ac9a5
commit
ea274c6d4a
@ -19,6 +19,7 @@ import { gcode } from '@/plugins/StreamParserGcode'
|
|||||||
import { indentWithTab } from '@codemirror/commands'
|
import { indentWithTab } from '@codemirror/commands'
|
||||||
import { json } from '@codemirror/lang-json'
|
import { json } from '@codemirror/lang-json'
|
||||||
import { css } from '@codemirror/lang-css'
|
import { css } from '@codemirror/lang-css'
|
||||||
|
import { indentUnit } from '@codemirror/language'
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
export default class Codemirror extends Mixins(BaseMixin) {
|
export default class Codemirror extends Mixins(BaseMixin) {
|
||||||
@ -83,6 +84,7 @@ export default class Codemirror extends Mixins(BaseMixin) {
|
|||||||
const extensions = [
|
const extensions = [
|
||||||
basicSetup,
|
basicSetup,
|
||||||
mainsailTheme,
|
mainsailTheme,
|
||||||
|
indentUnit.of(' '.repeat(this.getTabSize())),
|
||||||
keymap.of([indentWithTab]),
|
keymap.of([indentWithTab]),
|
||||||
EditorView.updateListener.of((update) => {
|
EditorView.updateListener.of((update) => {
|
||||||
this.content = update.state?.doc.toString()
|
this.content = update.state?.doc.toString()
|
||||||
@ -103,5 +105,9 @@ export default class Codemirror extends Mixins(BaseMixin) {
|
|||||||
visibilityChanged(isVisible: boolean) {
|
visibilityChanged(isVisible: boolean) {
|
||||||
if (isVisible) this.cminstance?.focus()
|
if (isVisible) this.cminstance?.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTabSize() {
|
||||||
|
return this.$store.state.gui.editor.tabSize || 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -15,6 +15,15 @@
|
|||||||
:dynamic-slot-width="true">
|
:dynamic-slot-width="true">
|
||||||
<v-switch v-model="confirmUnsavedChanges" hide-details class="mt-0"></v-switch>
|
<v-switch v-model="confirmUnsavedChanges" hide-details class="mt-0"></v-switch>
|
||||||
</settings-row>
|
</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>
|
<v-divider class="my-2"></v-divider>
|
||||||
<settings-row
|
<settings-row
|
||||||
:title="$t('Settings.EditorTab.KlipperRestartMethod')"
|
: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() {
|
get escToClose() {
|
||||||
return this.$store.state.gui.editor.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 })
|
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() {
|
get klipperRestartMethod() {
|
||||||
return this.$store.state.gui.editor.klipperRestartMethod
|
return this.$store.state.gui.editor.klipperRestartMethod
|
||||||
}
|
}
|
||||||
|
@ -799,7 +799,10 @@
|
|||||||
"MoonrakerRestartInstance": "Moonraker Neustartinstanz",
|
"MoonrakerRestartInstance": "Moonraker Neustartinstanz",
|
||||||
"MoonrakerRestartInstanceDescription": "Wähle aus, welche Moonrakerinstanz neu gestartet werden soll wenn 'Speichern & Neustarten' im Editor geklickt wird.",
|
"MoonrakerRestartInstanceDescription": "Wähle aus, welche Moonrakerinstanz neu gestartet werden soll wenn 'Speichern & Neustarten' im Editor geklickt wird.",
|
||||||
"UseEscToClose": "ESC drücken um Editor zu schließen",
|
"UseEscToClose": "ESC drücken um Editor zu schließen",
|
||||||
"UseEscToCloseDescription": "Erlaubt es den Editor mit ESC zu schließen."
|
"UseEscToCloseDescription": "Erlaubt es den Editor mit ESC zu schließen.",
|
||||||
|
"TabSize": "TAB Größe",
|
||||||
|
"TabSizeDescription": "Legt fest, um wie viele Leerzeichen für TAB eingerückt werden sollen",
|
||||||
|
"Spaces": "Leerzeichen: {count}"
|
||||||
},
|
},
|
||||||
"GCodeViewerTab": {
|
"GCodeViewerTab": {
|
||||||
"BackgroundColor": "Hintergrundfarbe",
|
"BackgroundColor": "Hintergrundfarbe",
|
||||||
|
@ -804,7 +804,10 @@
|
|||||||
"MoonrakerRestartInstance": "Moonraker restart instance",
|
"MoonrakerRestartInstance": "Moonraker restart instance",
|
||||||
"MoonrakerRestartInstanceDescription": "Select which Moonraker service will restart on 'Save & Restart' when editing Moonraker config files.",
|
"MoonrakerRestartInstanceDescription": "Select which Moonraker service will restart on 'Save & Restart' when editing Moonraker config files.",
|
||||||
"UseEscToClose": "Use ESC to close editor",
|
"UseEscToClose": "Use ESC to close editor",
|
||||||
"UseEscToCloseDescription": "Allows the ESC key to close the editor"
|
"UseEscToCloseDescription": "Allows the ESC key to close the editor",
|
||||||
|
"TabSize": "TAB Size",
|
||||||
|
"TabSizeDescription": "Adjusts how many spaces should be indented for TAB",
|
||||||
|
"Spaces": "Spaces: {count}"
|
||||||
},
|
},
|
||||||
"GCodeViewerTab": {
|
"GCodeViewerTab": {
|
||||||
"BackgroundColor": "Background Color",
|
"BackgroundColor": "Background Color",
|
||||||
|
@ -725,7 +725,10 @@
|
|||||||
"MoonrakerRestartInstance": "Moonraker példány Újraindítása",
|
"MoonrakerRestartInstance": "Moonraker példány Újraindítása",
|
||||||
"MoonrakerRestartInstanceDescription": "Válaszd ki melyik Moonraker szolgáltatást indítsuk újra a 'Ment és Újraindít' esetén, amikor a Moonraker konfig fájlait szerkeszted.",
|
"MoonrakerRestartInstanceDescription": "Válaszd ki melyik Moonraker szolgáltatást indítsuk újra a 'Ment és Újraindít' esetén, amikor a Moonraker konfig fájlait szerkeszted.",
|
||||||
"UseEscToClose": "Kilépéshez nyomd meg az ESC gombot",
|
"UseEscToClose": "Kilépéshez nyomd meg az ESC gombot",
|
||||||
"UseEscToCloseDescription": "Az ESC gomb megnyomása bezárja a szerkesztőt"
|
"UseEscToCloseDescription": "Az ESC gomb megnyomása bezárja a szerkesztőt",
|
||||||
|
"TabSize": "TAB Méret",
|
||||||
|
"TabSizeDescription": "Beállítja, hogy hány szóközzel legyen behúzva a TAB-oknál",
|
||||||
|
"Spaces": "Szóközök: {count}"
|
||||||
},
|
},
|
||||||
"GCodeViewerTab": {
|
"GCodeViewerTab": {
|
||||||
"BackgroundColor": "Háttérszín",
|
"BackgroundColor": "Háttérszín",
|
||||||
|
@ -726,7 +726,10 @@
|
|||||||
"MoonrakerRestartInstance": "Инстанция перезапуска Moonraker",
|
"MoonrakerRestartInstance": "Инстанция перезапуска Moonraker",
|
||||||
"MoonrakerRestartInstanceDescription": "Выберите, какая служба Moonraker будет перезапускаться при 'Save & Restart' при редактировании файлов конфигурации Moonraker.",
|
"MoonrakerRestartInstanceDescription": "Выберите, какая служба Moonraker будет перезапускаться при 'Save & Restart' при редактировании файлов конфигурации Moonraker.",
|
||||||
"UseEscToClose": "Нажмите ESC, чтобы закрыть редактор",
|
"UseEscToClose": "Нажмите ESC, чтобы закрыть редактор",
|
||||||
"UseEscToCloseDescription": "Позволяет закрыть редактор с помощью ESC."
|
"UseEscToCloseDescription": "Позволяет закрыть редактор с помощью ESC.",
|
||||||
|
"TabSize": "Размер TAB",
|
||||||
|
"TabSizeDescription": "Регулирует, сколько пробелов должно быть отступом для TAB",
|
||||||
|
"Spaces": "Пробе́лов: {count}"
|
||||||
},
|
},
|
||||||
"GCodeViewerTab": {
|
"GCodeViewerTab": {
|
||||||
"BackgroundColor": "Цвет фона",
|
"BackgroundColor": "Цвет фона",
|
||||||
|
@ -111,6 +111,7 @@ export const getDefaultState = (): GuiState => {
|
|||||||
escToClose: true,
|
escToClose: true,
|
||||||
confirmUnsavedChanges: true,
|
confirmUnsavedChanges: true,
|
||||||
klipperRestartMethod: 'FIRMWARE_RESTART',
|
klipperRestartMethod: 'FIRMWARE_RESTART',
|
||||||
|
tabSize: 2,
|
||||||
moonrakerRestartInstance: null,
|
moonrakerRestartInstance: null,
|
||||||
},
|
},
|
||||||
gcodeViewer: {
|
gcodeViewer: {
|
||||||
|
@ -59,6 +59,7 @@ export interface GuiState {
|
|||||||
escToClose: boolean
|
escToClose: boolean
|
||||||
confirmUnsavedChanges: boolean
|
confirmUnsavedChanges: boolean
|
||||||
klipperRestartMethod: 'FIRMWARE_RESTART' | 'RESTART'
|
klipperRestartMethod: 'FIRMWARE_RESTART' | 'RESTART'
|
||||||
|
tabSize: number
|
||||||
moonrakerRestartInstance: string | null
|
moonrakerRestartInstance: string | null
|
||||||
}
|
}
|
||||||
gcodeViewer: {
|
gcodeViewer: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user