add configuration of tab size

This commit is contained in:
Min 2025-03-11 00:03:04 +09:00
parent 50f3cae372
commit 7fe5404304
4 changed files with 30 additions and 1 deletions

View File

@ -35,6 +35,7 @@ const schema = {
"showInMenu": {type: "boolean", default: false},
"alwaysOnTop": {type: "boolean", default: false},
"bracketClosing": {type: "boolean", default: false},
"tabSize": {type: "integer", default: 4},
"defaultBlockLanguage": {type: "string"},
"defaultBlockLanguageAutoDetect": {type: "boolean"},
@ -72,6 +73,7 @@ const defaults = {
showInMenu: false,
alwaysOnTop: false,
bracketClosing: false,
tabSize: 4,
},
theme: "system",
}

View File

@ -40,6 +40,7 @@
showInMenu: this.initialSettings.showInMenu,
alwaysOnTop: this.initialSettings.alwaysOnTop,
bracketClosing: this.initialSettings.bracketClosing,
tabSize: this.initialSettings.tabSize || 4,
autoUpdate: this.initialSettings.autoUpdate,
bufferPath: this.initialSettings.bufferPath,
fontFamily: this.initialSettings.fontFamily || defaultFontFamily,
@ -102,6 +103,7 @@
alwaysOnTop: this.alwaysOnTop,
autoUpdate: this.autoUpdate,
bracketClosing: this.bracketClosing,
tabSize: this.tabSize,
bufferPath: this.bufferPath,
fontFamily: this.fontFamily === defaultFontFamily ? undefined : this.fontFamily,
fontSize: this.fontSize === defaultFontSize ? undefined : this.fontSize,
@ -276,6 +278,19 @@
</label>
</div>
</div>
<div class="row">
<div class="entry">
<h2>Tab Size</h2>
<select v-model="tabSize" @change="updateSettings" class="tab-size">
<option
v-for="size in [1, 2, 3, 4, 5, 6, 7, 8]"
:key="size"
:selected="tabSize === size"
:value="size"
>{{ size }} {{ size === 1 ? 'space' : 'spaces' }}</option>
</select>
</div>
</div>
<div class="row">
<div class="entry">
<h2>Default Block Language</h2>

View File

@ -51,6 +51,7 @@ export class HeynoteEditor {
bracketClosing=false,
fontFamily,
fontSize,
tabSize=4,
defaultBlockToken,
defaultBlockAutoDetect,
}) {
@ -63,6 +64,7 @@ export class HeynoteEditor {
this.foldGutterCompartment = new Compartment
this.readOnlyCompartment = new Compartment
this.closeBracketsCompartment = new Compartment
this.indentUnitCompartment = new Compartment
this.deselectOnCopy = keymap === "emacs"
this.emacsMetaKey = emacsMetaKey
this.fontTheme = new Compartment
@ -91,7 +93,7 @@ export class HeynoteEditor {
this.themeCompartment.of(theme === "dark" ? heynoteDark : heynoteLight),
heynoteBase,
this.fontTheme.of(getFontTheme(fontFamily, fontSize)),
indentUnit.of(" "),
this.indentUnitCompartment.of(indentUnit.of(" ".repeat(tabSize))),
EditorView.scrollMargins.of(f => {
return {top: 80, bottom: 80}
}),
@ -417,6 +419,12 @@ export class HeynoteEditor {
selectAll() {
selectAll(this.view)
}
setTabSize(tabSize) {
this.view.dispatch({
effects: this.indentUnitCompartment.reconfigure(indentUnit.of(" ".repeat(tabSize)))
})
}
}

View File

@ -36,6 +36,7 @@ export const useEditorCacheStore = defineStore("editorCache", {
bracketClosing: settingsStore.settings.bracketClosing,
fontFamily: settingsStore.settings.fontFamily,
fontSize: settingsStore.settings.fontSize,
tabSize: settingsStore.settings.tabSize,
defaultBlockToken: settingsStore.settings.defaultBlockLanguage,
defaultBlockAutoDetect: settingsStore.settings.defaultBlockLanguageAutoDetect,
})
@ -137,6 +138,9 @@ export const useEditorCacheStore = defineStore("editorCache", {
case "fontSize":
editor.setFont(newSettings.fontFamily, newSettings.fontSize)
break
case "tabSize":
editor.setTabSize(newSettings.tabSize)
break
case "defaultBlockLanguage":
case "defaultBlockLanguageAutoDetect":
editor.setDefaultBlockLanguage(newSettings.defaultBlockLanguage, newSettings.defaultBlockLanguageAutoDetect)