Change terminology Note -> Buffer

This commit is contained in:
Jonatan Heyman 2024-12-06 14:42:47 +01:00
parent 530a7efbf5
commit b7a1b185a8
11 changed files with 172 additions and 175 deletions

View File

@ -2,17 +2,17 @@
import { mapState, mapActions } from 'pinia'
import { mapWritableState } from 'pinia'
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
import { useErrorStore } from "../stores/error-store"
import StatusBar from './StatusBar.vue'
import Editor from './Editor.vue'
import LanguageSelector from './LanguageSelector.vue'
import NoteSelector from './NoteSelector.vue'
import BufferSelector from './BufferSelector.vue'
import Settings from './settings/Settings.vue'
import ErrorMessages from './ErrorMessages.vue'
import NewNote from './NewNote.vue'
import EditNote from './EditNote.vue'
import NewBuffer from './NewBuffer.vue'
import EditBuffer from './EditBuffer.vue'
export default {
components: {
@ -20,10 +20,10 @@
StatusBar,
LanguageSelector,
Settings,
NoteSelector,
BufferSelector,
ErrorMessages,
NewNote,
EditNote,
NewBuffer,
EditBuffer,
},
data() {
@ -67,37 +67,37 @@
watch: {
// when a dialog is closed, we want to focus the editor
showLanguageSelector(value) { this.dialogWatcher(value) },
showNoteSelector(value) { this.dialogWatcher(value) },
showCreateNote(value) { this.dialogWatcher(value) },
showEditNote(value) { this.dialogWatcher(value) },
showBufferSelector(value) { this.dialogWatcher(value) },
showCreateBuffer(value) { this.dialogWatcher(value) },
showEditBuffer(value) { this.dialogWatcher(value) },
currentNotePath() {
currentBufferPath() {
this.focusEditor()
},
},
computed: {
...mapState(useNotesStore, [
"currentNotePath",
...mapState(useHeynoteStore, [
"currentBufferPath",
"showLanguageSelector",
"showNoteSelector",
"showCreateNote",
"showEditNote",
"showBufferSelector",
"showCreateBuffer",
"showEditBuffer",
]),
editorInert() {
return this.showCreateNote || this.showSettings || this.showEditNote
return this.showCreateBuffer || this.showSettings || this.showEditBuffer
},
},
methods: {
...mapActions(useNotesStore, [
...mapActions(useHeynoteStore, [
"openLanguageSelector",
"openNoteSelector",
"openCreateNote",
"openBufferSelector",
"openCreateBuffer",
"closeDialog",
"closeNoteSelector",
"openNote",
"closeBufferSelector",
"openBuffer",
]),
// Used as a watcher for the booleans that control the visibility of editor dialogs.
@ -177,7 +177,7 @@
<StatusBar
:autoUpdate="settings.autoUpdate"
:allowBetaVersions="settings.allowBetaVersions"
@openNoteSelector="openNoteSelector"
@openBufferSelector="openBufferSelector"
@openLanguageSelector="openLanguageSelector"
@formatCurrentBlock="formatCurrentBlock"
@openSettings="showSettings = true"
@ -190,10 +190,10 @@
@selectLanguage="onSelectLanguage"
@close="closeDialog"
/>
<NoteSelector
v-if="showNoteSelector"
@openNote="openNote"
@close="closeNoteSelector"
<BufferSelector
v-if="showBufferSelector"
@openBuffer="openBuffer"
@close="closeBufferSelector"
/>
<Settings
v-if="showSettings"
@ -202,12 +202,12 @@
@closeSettings="closeSettings"
@setTheme="setTheme"
/>
<NewNote
v-if="showCreateNote"
<NewBuffer
v-if="showCreateBuffer"
@close="closeDialog"
/>
<EditNote
v-if="showEditNote"
<EditBuffer
v-if="showEditBuffer"
@close="closeDialog"
/>
<ErrorMessages />

View File

@ -4,7 +4,7 @@
import { mapState, mapActions } from 'pinia'
import { toRaw } from 'vue';
import { SCRATCH_FILE_NAME } from "../common/constants"
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
export default {
data() {
@ -19,7 +19,7 @@
},
async mounted() {
await this.updateNotes()
await this.updateBuffers()
this.$refs.container.focus()
this.$refs.input.focus()
this.buildItems()
@ -29,13 +29,13 @@
},
computed: {
...mapState(useNotesStore, [
"notes",
"recentNotePaths",
...mapState(useHeynoteStore, [
"buffers",
"recentBufferPaths",
]),
orderedItems() {
const sortKeys = Object.fromEntries(this.recentNotePaths.map((item, idx) => [item, idx]))
const sortKeys = Object.fromEntries(this.recentBufferPaths.map((item, idx) => [item, idx]))
const getSortScore = (item) => sortKeys[item.path] !== undefined ? sortKeys[item.path] : 1000
const compareFunc = (a, b) => {
const sortScore = getSortScore(a) - getSortScore(b)
@ -90,16 +90,16 @@
},
methods: {
...mapActions(useNotesStore, [
"updateNotes",
"editNote",
"deleteNote",
"openCreateNote",
...mapActions(useHeynoteStore, [
"updateBuffers",
"editBufferMetadata",
"deleteBuffer",
"openCreateBuffer",
]),
buildItems() {
//console.log("buildItems", Object.entries(this.notes))
this.items = Object.entries(this.notes).map(([path, metadata]) => {
//console.log("buildItems", Object.entries(this.buffers))
this.items = Object.entries(this.buffers).map(([path, metadata]) => {
return {
"path": path,
"name": metadata?.name || path,
@ -158,7 +158,7 @@
event.preventDefault()
if (this.actionButton === 1) {
//console.log("edit file:", path)
this.editNote(item.path)
this.editBufferMetadata(item.path)
} else if (this.actionButton === 2) {
this.deleteConfirmNote(item.path)
} else {
@ -170,12 +170,12 @@
selectItem(item) {
if (item.createNew) {
if (this.filteredItems.length === 1) {
this.openCreateNote("new", this.filter)
this.openCreateBuffer("new", this.filter)
} else {
this.openCreateNote("new", "")
this.openCreateBuffer("new", "")
}
} else {
this.$emit("openNote", item.path)
this.$emit("openBuffer", item.path)
}
},
@ -220,7 +220,7 @@
async deleteConfirmNote(path) {
if (this.deleteConfirm) {
//console.log("delete file:", path)
await this.deleteNote(path)
await this.deleteBuffer(path)
this.hideActionButtons()
this.buildItems()
this.selected = Math.min(this.selected, this.items.length - 1)
@ -264,7 +264,7 @@
<button
v-if="actionButton > 0 && idx === selected"
:class="{'selected':actionButton === 1}"
@click.stop.prevent="editNote(item.path)"
@click.stop.prevent="editBufferMetadata(item.path)"
>Edit</button>
<button
v-if="actionButton > 0 && idx === selected"

View File

@ -3,7 +3,7 @@
import { toRaw } from 'vue';
import { mapState, mapActions } from 'pinia'
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
import FolderSelector from './folder-selector/FolderSelector.vue'
@ -26,7 +26,7 @@
async mounted() {
this.$refs.nameInput.focus()
this.updateNotes()
this.updateBuffers()
console.log("EditNote mounted", this.currentNote)
this.name = this.currentNote.name
@ -56,7 +56,7 @@
name: part,
children: [],
path: currentPath,
open: this.currentNotePath.startsWith(currentPath),
open: this.currentBufferPath.startsWith(currentPath),
}
currentLevel.children.push(node)
currentLevel = node
@ -68,17 +68,17 @@
},
computed: {
...mapState(useNotesStore, [
"notes",
"currentNotePath",
...mapState(useHeynoteStore, [
"buffers",
"currentBufferPath",
]),
currentNote() {
return this.notes[this.currentNotePath]
return this.buffers[this.currentBufferPath]
},
currentNoteDirectory() {
return this.currentNotePath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split("/").slice(0, -1).join("/")
},
nameInputClass() {
@ -90,9 +90,9 @@
},
methods: {
...mapActions(useNotesStore, [
"updateNotes",
"updateNoteMetadata",
...mapActions(useHeynoteStore, [
"updateBuffers",
"updateBufferMetadata",
]),
onKeydown(event) {
@ -137,19 +137,19 @@
for (let i=0; i<1000; i++) {
let filename = slug + ".txt"
path = parentPathPrefix + filename
if (path === this.currentNotePath || !this.notes[path]) {
if (path === this.currentBufferPath || !this.buffers[path]) {
// file name is ok if it's the current note, or if it doesn't exist
break
}
slug = slugify(this.name + "-" + i)
}
if (path !== this.currentNotePath && this.notes[path]) {
if (path !== this.currentBufferPath && this.buffers[path]) {
console.error("Failed to edit note, path already exists", path)
this.errors.name = true
return
}
console.log("Update note", path)
this.updateNoteMetadata(this.currentNotePath, this.name, path)
this.updateBufferMetadata(this.currentBufferPath, this.name, path)
this.$emit("close")
//this.$emit("create", this.$refs.input.value)
},

View File

@ -4,7 +4,7 @@
import { toRaw } from 'vue';
import { mapState, mapWritableState, mapActions } from 'pinia'
import { useErrorStore } from "../stores/error-store"
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store.js"
import { useEditorCacheStore } from "../stores/editor-cache"
const NUM_EDITOR_INSTANCES = 5
@ -50,7 +50,7 @@
},
mounted() {
this.loadBuffer(this.currentNotePath)
this.loadBuffer(this.currentBufferPath)
// set up window close handler that will save the buffer and quit
window.heynote.onWindowClose(() => {
@ -87,8 +87,8 @@
watch: {
loadNewEditor() {
//console.log("currentNotePath changed to", path)
this.loadBuffer(this.currentNotePath)
//console.log("currentBufferPath changed to", path)
this.loadBuffer(this.currentBufferPath)
},
theme(newTheme) {
@ -150,17 +150,17 @@
},
computed: {
...mapState(useNotesStore, [
"currentNotePath",
...mapState(useHeynoteStore, [
"currentBufferPath",
"libraryId",
]),
...mapWritableState(useNotesStore, [
...mapWritableState(useHeynoteStore, [
"currentEditor",
"currentNoteName",
"currentBufferName",
]),
loadNewEditor() {
return `${this.currentNotePath}|${this.libraryId}`
return `${this.currentBufferPath}|${this.libraryId}`
},
},

View File

@ -2,7 +2,7 @@
import slugify from '@sindresorhus/slugify';
import { mapState, mapActions } from 'pinia'
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
import FolderSelector from './folder-selector/FolderSelector.vue'
@ -24,8 +24,8 @@
},
async mounted() {
if (!!this.createNoteParams.name) {
this.name = this.createNoteParams.name
if (!!this.createBufferParams.name) {
this.name = this.createBufferParams.name
this.$refs.nameInput.focus()
this.$nextTick(() => {
this.$refs.nameInput.select()
@ -34,7 +34,7 @@
this.$refs.nameInput.focus()
}
this.updateNotes()
this.updateBuffers()
// build directory tree
const directories = await window.heynote.buffer.getDirectoryList()
@ -61,7 +61,7 @@
name: part,
children: [],
path: currentPath,
open: this.currentNotePath.startsWith(currentPath),
open: this.currentBufferPath.startsWith(currentPath),
}
currentLevel.children.push(node)
currentLevel = node
@ -73,14 +73,14 @@
},
computed: {
...mapState(useNotesStore, [
"notes",
"currentNotePath",
"createNoteParams",
...mapState(useHeynoteStore, [
"buffers",
"currentBufferPath",
"createBufferParams",
]),
currentNoteDirectory() {
return this.currentNotePath.split("/").slice(0, -1).join("/")
return this.currentBufferPath.split("/").slice(0, -1).join("/")
},
nameInputClass() {
@ -91,15 +91,15 @@
},
dialogTitle() {
return this.createNoteParams.mode === "currentBlock" ? "New Note from Block" : "New Note"
return this.createBufferParams.mode === "currentBlock" ? "New Note from Block" : "New Note"
},
},
methods: {
...mapActions(useNotesStore, [
"updateNotes",
"createNewNote",
"createNewNoteFromActiveBlock",
...mapActions(useHeynoteStore, [
"updateBuffers",
"createNewBuffer",
"createNewBufferFromActiveBlock",
]),
onKeydown(event) {
@ -145,23 +145,23 @@
for (let i=0; i<1000; i++) {
let filename = slug + ".txt"
path = parentPathPrefix + filename
if (!this.notes[path]) {
if (!this.buffers[path]) {
break
}
slug = slugify(this.name + "-" + i)
}
if (this.notes[path]) {
if (this.buffers[path]) {
console.error("Failed to create note, path already exists", path)
this.errors.name = true
return
}
console.log("Creating note", path)
if (this.createNoteParams.mode === "currentBlock") {
this.createNewNoteFromActiveBlock(path, this.name)
} else if (this.createNoteParams.mode === "new") {
this.createNewNote(path, this.name)
//console.log("Creating note", path, this.createBufferParams)
if (this.createBufferParams.mode === "currentBlock") {
this.createNewBufferFromActiveBlock(path, this.name)
} else if (this.createBufferParams.mode === "new") {
this.createNewBuffer(path, this.name)
} else {
throw new Error("Unknown createNote Mode: " + this.createNoteParams.mode)
throw new Error("Unknown createNote Mode: " + this.createBufferParams.mode)
}
this.$emit("close")

View File

@ -2,7 +2,7 @@
import { mapState } from 'pinia'
import UpdateStatusItem from './UpdateStatusItem.vue'
import { LANGUAGES } from '../editor/languages.js'
import { useNotesStore } from "../stores/notes-store"
import { useHeynoteStore } from "../stores/heynote-store"
const LANGUAGE_MAP = Object.fromEntries(LANGUAGES.map(l => [l.token, l]))
const LANGUAGE_NAMES = Object.fromEntries(LANGUAGES.map(l => [l.token, l.name]))
@ -28,8 +28,8 @@
},
computed: {
...mapState(useNotesStore, [
"currentNoteName",
...mapState(useHeynoteStore, [
"currentBufferName",
"currentCursorLine",
"currentLanguage",
"currentSelectionSize",
@ -84,11 +84,11 @@
</div>
<div class="spacer"></div>
<div
@click.stop="$emit('openNoteSelector')"
@click.stop="$emit('openBufferSelector')"
class="status-block note clickable"
:title="changeNoteTitle"
>
{{ currentNoteName }}
{{ currentBufferName }}
</div>
<div
@click.stop="$emit('openLanguageSelector')"

View File

@ -4,7 +4,7 @@ import { EditorState, RangeSetBuilder, StateField, Facet , StateEffect, RangeSet
import { syntaxTree, ensureSyntaxTree, syntaxTreeAvailable } from "@codemirror/language"
import { Note, Document, NoteDelimiter } from "../lang-heynote/parser.terms.js"
import { IterMode } from "@lezer/common";
import { useNotesStore } from "../../stores/notes-store.js"
import { useHeynoteStore } from "../../stores/heynote-store.js"
import { heynoteEvent, LANGUAGE_CHANGE, CURSOR_CHANGE } from "../annotation.js";
import { mathBlock } from "./math.js"
import { emptyBlockSelected } from "./select-all.js";
@ -414,7 +414,7 @@ export function triggerCursorChange({state, dispatch}) {
}
const emitCursorChange = (editor) => {
const notesStore = useNotesStore()
const notesStore = useHeynoteStore()
return ViewPlugin.fromClass(
class {
update(update) {
@ -434,7 +434,7 @@ const emitCursorChange = (editor) => {
notesStore.currentSelectionSize = selectionSize
notesStore.currentLanguage = block.language.name
notesStore.currentLanguageAuto = block.language.auto
notesStore.currentNoteName = editor.name
notesStore.currentBufferName = editor.name
}
}
}

View File

@ -23,7 +23,7 @@ import { todoCheckboxPlugin} from "./todo-checkbox.ts"
import { links } from "./links.js"
import { NoteFormat } from "../common/note-format.js"
import { AUTO_SAVE_INTERVAL } from "../common/constants.js"
import { useNotesStore } from "../stores/notes-store.js";
import { useHeynoteStore } from "../stores/heynote-store.js";
import { useErrorStore } from "../stores/error-store.js";
@ -67,7 +67,7 @@ export class HeynoteEditor {
this.fontTheme = new Compartment
this.setDefaultBlockLanguage(defaultBlockToken, defaultBlockAutoDetect)
this.contentLoaded = false
this.notesStore = useNotesStore()
this.notesStore = useHeynoteStore()
this.errorStore = useErrorStore()
this.name = ""
@ -269,40 +269,40 @@ export class HeynoteEditor {
this.notesStore.openLanguageSelector()
}
openNoteSelector() {
this.notesStore.openNoteSelector()
openBufferSelector() {
this.notesStore.openBufferSelector()
}
openCreateNote(createMode) {
this.notesStore.openCreateNote(createMode)
openCreateBuffer(createMode) {
this.notesStore.openCreateBuffer(createMode)
}
async createNewNote(path, name) {
async createNewBuffer(path, name) {
const data = getBlockDelimiter(this.defaultBlockToken, this.defaultBlockAutoDetect)
await this.notesStore.saveNewNote(path, name, data)
await this.notesStore.saveNewBuffer(path, name, data)
// by using requestAnimationFrame we avoid a race condition where rendering the block backgrounds
// would fail if we immediately opened the new note (since the block UI wouldn't have time to update
// after the block was deleted)
requestAnimationFrame(() => {
this.notesStore.openNote(path)
this.notesStore.openBuffer(path)
})
}
async createNewNoteFromActiveBlock(path, name) {
async createNewBufferFromActiveBlock(path, name) {
const block = getActiveNoteBlock(this.view.state)
if (!block) {
return
}
const data = this.view.state.sliceDoc(block.range.from, block.range.to)
await this.notesStore.saveNewNote(path, name, data)
await this.notesStore.saveNewBuffer(path, name, data)
deleteBlock(this)(this.view)
// by using requestAnimationFrame we avoid a race condition where rendering the block backgrounds
// would fail if we immediately opened the new note (since the block UI wouldn't have time to update
// after the block was deleted)
requestAnimationFrame(() => {
this.notesStore.openNote(path)
this.notesStore.openBuffer(path)
})
}

View File

@ -58,9 +58,9 @@ export function heynoteKeymap(editor) {
["Alt-ArrowUp", moveLineUp],
["Alt-ArrowDown", moveLineDown],
["Mod-l", () => editor.openLanguageSelector()],
["Mod-p", () => editor.openNoteSelector()],
["Mod-s", () => editor.openCreateNote("currentBlock")],
["Mod-n", () => editor.openCreateNote("new")],
["Mod-p", () => editor.openBufferSelector()],
["Mod-s", () => editor.openCreateBuffer("currentBlock")],
["Mod-n", () => editor.openCreateBuffer("new")],
["Mod-Shift-d", deleteBlock(editor)],
["Alt-Shift-f", formatBlockContent],
["Mod-Alt-ArrowDown", newCursorBelow],

View File

@ -6,7 +6,7 @@ import { createPinia } from 'pinia'
import App from './components/App.vue'
import { loadCurrencies } from './currency'
import { useErrorStore } from './stores/error-store'
import { useNotesStore, initNotesStore } from './stores/notes-store'
import { useHeynoteStore, initHeynoteStore } from './stores/heynote-store'
import { useEditorCacheStore } from './stores/editor-cache'
@ -26,7 +26,7 @@ window.heynote.getInitErrors().then((errors) => {
errors.forEach((e) => errorStore.addError(e))
})
initNotesStore()
initHeynoteStore()

View File

@ -5,97 +5,97 @@ import { useEditorCacheStore } from "./editor-cache"
import { SCRATCH_FILE_NAME } from "../common/constants"
export const useNotesStore = defineStore("notes", {
export const useHeynoteStore = defineStore("heynote", {
state: () => ({
notes: {},
recentNotePaths: [SCRATCH_FILE_NAME],
buffers: {},
recentBufferPaths: [SCRATCH_FILE_NAME],
currentEditor: null,
currentNotePath: SCRATCH_FILE_NAME,
currentNoteName: null,
currentBufferPath: SCRATCH_FILE_NAME,
currentBufferName: null,
currentLanguage: null,
currentLanguageAuto: null,
currentCursorLine: null,
currentSelectionSize: null,
libraryId: 0,
createNoteParams: {
createBufferParams: {
mode: "new",
nameSuggestion: ""
},
showNoteSelector: false,
showBufferSelector: false,
showLanguageSelector: false,
showCreateNote: false,
showEditNote: false,
showCreateBuffer: false,
showEditBuffer: false,
}),
actions: {
async updateNotes() {
this.setNotes(await window.heynote.buffer.getList())
async updateBuffers() {
this.setBuffers(await window.heynote.buffer.getList())
},
setNotes(notes) {
this.notes = notes
setBuffers(buffers) {
this.buffers = buffers
},
openNote(path) {
openBuffer(path) {
this.closeDialog()
this.currentNotePath = path
this.currentBufferPath = path
const recent = this.recentNotePaths.filter((p) => p !== path)
const recent = this.recentBufferPaths.filter((p) => p !== path)
recent.unshift(path)
this.recentNotePaths = recent.slice(0, 100)
this.recentBufferPaths = recent.slice(0, 100)
},
openLanguageSelector() {
this.closeDialog()
this.showLanguageSelector = true
},
openNoteSelector() {
openBufferSelector() {
this.closeDialog()
this.showNoteSelector = true
this.showBufferSelector = true
},
openCreateNote(createMode, nameSuggestion) {
openCreateBuffer(createMode, nameSuggestion) {
createMode = createMode || "new"
this.closeDialog()
this.createNoteParams = {
this.createBufferParams = {
mode: createMode || "new",
name: nameSuggestion || ""
}
this.showCreateNote = true
this.showCreateBuffer = true
},
closeDialog() {
this.showCreateNote = false
this.showNoteSelector = false
this.showCreateBuffer = false
this.showBufferSelector = false
this.showLanguageSelector = false
this.showEditNote = false
this.showEditBuffer = false
},
closeNoteSelector() {
this.showNoteSelector = false
closeBufferSelector() {
this.showBufferSelector = false
},
editNote(path) {
if (this.currentNotePath !== path) {
this.openNote(path)
editBufferMetadata(path) {
if (this.currentBufferPath !== path) {
this.openBuffer(path)
}
this.closeDialog()
this.showEditNote = true
this.showEditBuffer = true
},
/**
* Create a new note file at `path` with name `name` from the current block of the current open editor,
* and switch to it
*/
async createNewNoteFromActiveBlock(path, name) {
await toRaw(this.currentEditor).createNewNoteFromActiveBlock(path, name)
async createNewBufferFromActiveBlock(path, name) {
await toRaw(this.currentEditor).createNewBufferFromActiveBlock(path, name)
},
/**
* Create a new empty note file at `path` with name `name`, and switch to it
*/
async createNewNote(path, name) {
await toRaw(this.currentEditor).createNewNote(path, name)
async createNewBuffer(path, name) {
await toRaw(this.currentEditor).createNewBuffer(path, name)
},
/**
@ -104,23 +104,20 @@ export const useNotesStore = defineStore("notes", {
* @param {*} name Name of the note
* @param {*} content Contents (without metadata)
*/
async saveNewNote(path, name, content) {
//window.heynote.buffer.save(path, content)
//this.updateNotes()
if (this.notes[path]) {
async saveNewBuffer(path, name, content) {
if (this.buffers[path]) {
throw new Error(`Note already exists: ${path}`)
}
const note = new NoteFormat()
note.content = content
note.metadata.name = name
console.log("saving", path, note.serialize())
//console.log("saving", path, note.serialize())
await window.heynote.buffer.create(path, note.serialize())
this.updateNotes()
this.updateBuffers()
},
async updateNoteMetadata(path, name, newPath) {
async updateBufferMetadata(path, name, newPath) {
const editorCacheStore = useEditorCacheStore()
if (this.currentEditor.path !== path) {
@ -133,40 +130,40 @@ export const useNotesStore = defineStore("notes", {
//console.log("moving note", path, newPath)
editorCacheStore.freeEditor(path)
await window.heynote.buffer.move(path, newPath)
this.openNote(newPath)
this.updateNotes()
this.openBuffer(newPath)
this.updateBuffers()
}
},
async deleteNote(path) {
async deleteBuffer(path) {
if (path === SCRATCH_FILE_NAME) {
throw new Error("Can't delete scratch file")
}
const editorCacheStore = useEditorCacheStore()
if (this.currentEditor.path === path) {
this.currentEditor = null
this.currentNotePath = SCRATCH_FILE_NAME
this.currentBufferPath = SCRATCH_FILE_NAME
}
editorCacheStore.freeEditor(path)
await window.heynote.buffer.delete(path)
await this.updateNotes()
await this.updateBuffers()
},
async reloadLibrary() {
const editorCacheStore = useEditorCacheStore()
await this.updateNotes()
await this.updateBuffers()
editorCacheStore.clearCache(false)
this.currentEditor = null
this.currentNotePath = SCRATCH_FILE_NAME
this.currentBufferPath = SCRATCH_FILE_NAME
this.libraryId++
},
},
})
export async function initNotesStore() {
const notesStore = useNotesStore()
export async function initHeynoteStore() {
const heynoteStore = useHeynoteStore()
window.heynote.buffer.setLibraryPathChangeCallback(() => {
notesStore.reloadLibrary()
heynoteStore.reloadLibrary()
})
await notesStore.updateNotes()
await heynoteStore.updateBuffers()
}