Add cursor blink rate setting

This commit is contained in:
Jonatan Heyman 2025-12-26 17:27:13 +01:00
parent b0e2513805
commit 0a446049d6
6 changed files with 35 additions and 3 deletions

View File

@ -36,6 +36,7 @@ prefer the old behaviour, can add a key binding for the `Add new block after la
- Fix issue where the wrong locale was used for formatting dates on MacOS on systems using a locale such as "en-SE"
- Fix issue with folded Math blocks where the results from the first and last line would still be visible
- Always use 2-digit notation for hours when displaying time
- Add setting for configuring the cursor blink rate (or turning off the blinking)
## 2.6.2

View File

@ -56,6 +56,7 @@ const schema = {
"defaultBlockLanguageAutoDetect": {type: "boolean"},
"spellcheckEnabled": {type: "boolean", default:false},
"showWhitespace": {type:"boolean", default:false},
"cursorBlinkRate": {type: "integer", default: 1000},
// when default font settings are used, fontFamily and fontSize is not specified in the
// settings file, so that it's possible for us to change the default settings in the
@ -131,6 +132,7 @@ const defaults = {
},
spellcheckEnabled: false,
showWhitespace: false,
cursorBlinkRate: 1000,
},
theme: "system",
}

View File

@ -56,6 +56,7 @@
bufferPath: this.initialSettings.bufferPath,
fontFamily: this.initialSettings.fontFamily || defaultFontFamily,
fontSize: this.initialSettings.fontSize || defaultFontSize,
cursorBlinkRate: this.initialSettings.cursorBlinkRate ?? 1000,
languageOptions: LANGUAGES.map(l => {
return {
"value": l.token,
@ -135,6 +136,7 @@
bufferPath: this.bufferPath,
fontFamily: this.fontFamily === defaultFontFamily ? undefined : this.fontFamily,
fontSize: this.fontSize === defaultFontSize ? undefined : this.fontSize,
cursorBlinkRate: this.cursorBlinkRate,
defaultBlockLanguage: this.defaultBlockLanguage === "text" ? undefined : this.defaultBlockLanguage,
defaultBlockLanguageAutoDetect: this.defaultBlockLanguageAutoDetect === true ? undefined : this.defaultBlockLanguageAutoDetect,
})
@ -400,6 +402,21 @@
</select>
</div>
</div>
<div class="row">
<div class="entry">
<h2>Cursor Blink Rate</h2>
<select v-model.number="cursorBlinkRate" @change="updateSettings" class="cursor-blink-rate">
<option :value="0">Off</option>
<option :value="250">250 ms</option>
<option :value="500">500 ms</option>
<option :value="750">750 ms</option>
<option :value="1000">1000 ms (default)</option>
<option :value="1250">1250 ms</option>
<option :value="1500">1500 ms</option>
<option :value="2000">2000 ms</option>
</select>
</div>
</div>
<div class="row">
<div class="entry">

View File

@ -60,6 +60,7 @@ export class HeynoteEditor {
keyBindings,
spellcheckEnabled=false,
showWhitespace=false,
cursorBlinkRate=1000,
}) {
this.element = element
this.path = path
@ -72,6 +73,7 @@ export class HeynoteEditor {
this.closeBracketsCompartment = new Compartment
this.indentUnitCompartment = new Compartment
this.highlightWhitespaceCompartment = new Compartment
this.cursorBlinkCompartment = new Compartment
this.deselectOnCopy = keymap === "emacs"
this.emacsMetaKey = emacsMetaKey
this.fontTheme = new Compartment
@ -109,8 +111,7 @@ export class HeynoteEditor {
noteBlockExtension(this),
languageDetection(path, () => this),
// set cursor blink rate to 1 second
drawSelection({cursorBlinkRate:1000}),
this.cursorBlinkCompartment.of(drawSelection({cursorBlinkRate})),
// add CSS class depending on dark/light theme
EditorView.editorAttributes.of((view) => {
@ -323,6 +324,13 @@ export class HeynoteEditor {
})
}
setCursorBlinkRate(cursorBlinkRate) {
const rate = typeof cursorBlinkRate === "number" ? cursorBlinkRate : 1000
this.view.dispatch({
effects: this.cursorBlinkCompartment.reconfigure(drawSelection({cursorBlinkRate: rate})),
})
}
async createNewBuffer(path, name) {
const data = getBlockDelimiter(this.defaultBlockToken, this.defaultBlockAutoDetect)
await this.notesStore.saveNewBuffer(path, name, data)
@ -486,4 +494,3 @@ editor.update([
annotations: heynoteEvent.of(INITIAL_DATA),
})
])*/

View File

@ -47,6 +47,7 @@ export const useEditorCacheStore = defineStore("editorCache", {
keyBindings: settingsStore.settings.keyBindings,
spellcheckEnabled: settingsStore.settings.spellcheckEnabled,
showWhitespace: settingsStore.settings.showWhitespace,
cursorBlinkRate: settingsStore.settings.cursorBlinkRate,
})
} catch (e) {
errorStore.addError("Error! " + e.message)
@ -186,6 +187,9 @@ export const useEditorCacheStore = defineStore("editorCache", {
case "showWhitespace":
editor.setShowWhitespace(newSettings.showWhitespace)
break;
case "cursorBlinkRate":
editor.setCursorBlinkRate(newSettings.cursorBlinkRate)
break;
}
})
}

View File

@ -91,6 +91,7 @@ let initialSettings = {
keyBindings: [],
showTabs: true,
showTabsInFullscreen: true,
cursorBlinkRate: 1000,
}
if (settingsData !== null) {
initialSettings = Object.assign(initialSettings, JSON.parse(settingsData))