mirror of
https://github.com/heyman/heynote.git
synced 2024-12-22 23:00:38 +01:00
Change terminology Note -> Buffer
This commit is contained in:
parent
530a7efbf5
commit
b7a1b185a8
@ -2,17 +2,17 @@
|
|||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
|
|
||||||
import { mapWritableState } 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 { useErrorStore } from "../stores/error-store"
|
||||||
|
|
||||||
import StatusBar from './StatusBar.vue'
|
import StatusBar from './StatusBar.vue'
|
||||||
import Editor from './Editor.vue'
|
import Editor from './Editor.vue'
|
||||||
import LanguageSelector from './LanguageSelector.vue'
|
import LanguageSelector from './LanguageSelector.vue'
|
||||||
import NoteSelector from './NoteSelector.vue'
|
import BufferSelector from './BufferSelector.vue'
|
||||||
import Settings from './settings/Settings.vue'
|
import Settings from './settings/Settings.vue'
|
||||||
import ErrorMessages from './ErrorMessages.vue'
|
import ErrorMessages from './ErrorMessages.vue'
|
||||||
import NewNote from './NewNote.vue'
|
import NewBuffer from './NewBuffer.vue'
|
||||||
import EditNote from './EditNote.vue'
|
import EditBuffer from './EditBuffer.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -20,10 +20,10 @@
|
|||||||
StatusBar,
|
StatusBar,
|
||||||
LanguageSelector,
|
LanguageSelector,
|
||||||
Settings,
|
Settings,
|
||||||
NoteSelector,
|
BufferSelector,
|
||||||
ErrorMessages,
|
ErrorMessages,
|
||||||
NewNote,
|
NewBuffer,
|
||||||
EditNote,
|
EditBuffer,
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
@ -67,37 +67,37 @@
|
|||||||
watch: {
|
watch: {
|
||||||
// when a dialog is closed, we want to focus the editor
|
// when a dialog is closed, we want to focus the editor
|
||||||
showLanguageSelector(value) { this.dialogWatcher(value) },
|
showLanguageSelector(value) { this.dialogWatcher(value) },
|
||||||
showNoteSelector(value) { this.dialogWatcher(value) },
|
showBufferSelector(value) { this.dialogWatcher(value) },
|
||||||
showCreateNote(value) { this.dialogWatcher(value) },
|
showCreateBuffer(value) { this.dialogWatcher(value) },
|
||||||
showEditNote(value) { this.dialogWatcher(value) },
|
showEditBuffer(value) { this.dialogWatcher(value) },
|
||||||
|
|
||||||
currentNotePath() {
|
currentBufferPath() {
|
||||||
this.focusEditor()
|
this.focusEditor()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useNotesStore, [
|
...mapState(useHeynoteStore, [
|
||||||
"currentNotePath",
|
"currentBufferPath",
|
||||||
"showLanguageSelector",
|
"showLanguageSelector",
|
||||||
"showNoteSelector",
|
"showBufferSelector",
|
||||||
"showCreateNote",
|
"showCreateBuffer",
|
||||||
"showEditNote",
|
"showEditBuffer",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
editorInert() {
|
editorInert() {
|
||||||
return this.showCreateNote || this.showSettings || this.showEditNote
|
return this.showCreateBuffer || this.showSettings || this.showEditBuffer
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useNotesStore, [
|
...mapActions(useHeynoteStore, [
|
||||||
"openLanguageSelector",
|
"openLanguageSelector",
|
||||||
"openNoteSelector",
|
"openBufferSelector",
|
||||||
"openCreateNote",
|
"openCreateBuffer",
|
||||||
"closeDialog",
|
"closeDialog",
|
||||||
"closeNoteSelector",
|
"closeBufferSelector",
|
||||||
"openNote",
|
"openBuffer",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
// Used as a watcher for the booleans that control the visibility of editor dialogs.
|
// Used as a watcher for the booleans that control the visibility of editor dialogs.
|
||||||
@ -177,7 +177,7 @@
|
|||||||
<StatusBar
|
<StatusBar
|
||||||
:autoUpdate="settings.autoUpdate"
|
:autoUpdate="settings.autoUpdate"
|
||||||
:allowBetaVersions="settings.allowBetaVersions"
|
:allowBetaVersions="settings.allowBetaVersions"
|
||||||
@openNoteSelector="openNoteSelector"
|
@openBufferSelector="openBufferSelector"
|
||||||
@openLanguageSelector="openLanguageSelector"
|
@openLanguageSelector="openLanguageSelector"
|
||||||
@formatCurrentBlock="formatCurrentBlock"
|
@formatCurrentBlock="formatCurrentBlock"
|
||||||
@openSettings="showSettings = true"
|
@openSettings="showSettings = true"
|
||||||
@ -190,10 +190,10 @@
|
|||||||
@selectLanguage="onSelectLanguage"
|
@selectLanguage="onSelectLanguage"
|
||||||
@close="closeDialog"
|
@close="closeDialog"
|
||||||
/>
|
/>
|
||||||
<NoteSelector
|
<BufferSelector
|
||||||
v-if="showNoteSelector"
|
v-if="showBufferSelector"
|
||||||
@openNote="openNote"
|
@openBuffer="openBuffer"
|
||||||
@close="closeNoteSelector"
|
@close="closeBufferSelector"
|
||||||
/>
|
/>
|
||||||
<Settings
|
<Settings
|
||||||
v-if="showSettings"
|
v-if="showSettings"
|
||||||
@ -202,12 +202,12 @@
|
|||||||
@closeSettings="closeSettings"
|
@closeSettings="closeSettings"
|
||||||
@setTheme="setTheme"
|
@setTheme="setTheme"
|
||||||
/>
|
/>
|
||||||
<NewNote
|
<NewBuffer
|
||||||
v-if="showCreateNote"
|
v-if="showCreateBuffer"
|
||||||
@close="closeDialog"
|
@close="closeDialog"
|
||||||
/>
|
/>
|
||||||
<EditNote
|
<EditBuffer
|
||||||
v-if="showEditNote"
|
v-if="showEditBuffer"
|
||||||
@close="closeDialog"
|
@close="closeDialog"
|
||||||
/>
|
/>
|
||||||
<ErrorMessages />
|
<ErrorMessages />
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
import { toRaw } from 'vue';
|
import { toRaw } from 'vue';
|
||||||
import { SCRATCH_FILE_NAME } from "../common/constants"
|
import { SCRATCH_FILE_NAME } from "../common/constants"
|
||||||
import { useNotesStore } from "../stores/notes-store"
|
import { useHeynoteStore } from "../stores/heynote-store"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@ -19,7 +19,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
async mounted() {
|
async mounted() {
|
||||||
await this.updateNotes()
|
await this.updateBuffers()
|
||||||
this.$refs.container.focus()
|
this.$refs.container.focus()
|
||||||
this.$refs.input.focus()
|
this.$refs.input.focus()
|
||||||
this.buildItems()
|
this.buildItems()
|
||||||
@ -29,13 +29,13 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useNotesStore, [
|
...mapState(useHeynoteStore, [
|
||||||
"notes",
|
"buffers",
|
||||||
"recentNotePaths",
|
"recentBufferPaths",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
orderedItems() {
|
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 getSortScore = (item) => sortKeys[item.path] !== undefined ? sortKeys[item.path] : 1000
|
||||||
const compareFunc = (a, b) => {
|
const compareFunc = (a, b) => {
|
||||||
const sortScore = getSortScore(a) - getSortScore(b)
|
const sortScore = getSortScore(a) - getSortScore(b)
|
||||||
@ -90,16 +90,16 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useNotesStore, [
|
...mapActions(useHeynoteStore, [
|
||||||
"updateNotes",
|
"updateBuffers",
|
||||||
"editNote",
|
"editBufferMetadata",
|
||||||
"deleteNote",
|
"deleteBuffer",
|
||||||
"openCreateNote",
|
"openCreateBuffer",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
buildItems() {
|
buildItems() {
|
||||||
//console.log("buildItems", Object.entries(this.notes))
|
//console.log("buildItems", Object.entries(this.buffers))
|
||||||
this.items = Object.entries(this.notes).map(([path, metadata]) => {
|
this.items = Object.entries(this.buffers).map(([path, metadata]) => {
|
||||||
return {
|
return {
|
||||||
"path": path,
|
"path": path,
|
||||||
"name": metadata?.name || path,
|
"name": metadata?.name || path,
|
||||||
@ -158,7 +158,7 @@
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (this.actionButton === 1) {
|
if (this.actionButton === 1) {
|
||||||
//console.log("edit file:", path)
|
//console.log("edit file:", path)
|
||||||
this.editNote(item.path)
|
this.editBufferMetadata(item.path)
|
||||||
} else if (this.actionButton === 2) {
|
} else if (this.actionButton === 2) {
|
||||||
this.deleteConfirmNote(item.path)
|
this.deleteConfirmNote(item.path)
|
||||||
} else {
|
} else {
|
||||||
@ -170,12 +170,12 @@
|
|||||||
selectItem(item) {
|
selectItem(item) {
|
||||||
if (item.createNew) {
|
if (item.createNew) {
|
||||||
if (this.filteredItems.length === 1) {
|
if (this.filteredItems.length === 1) {
|
||||||
this.openCreateNote("new", this.filter)
|
this.openCreateBuffer("new", this.filter)
|
||||||
} else {
|
} else {
|
||||||
this.openCreateNote("new", "")
|
this.openCreateBuffer("new", "")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$emit("openNote", item.path)
|
this.$emit("openBuffer", item.path)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -220,7 +220,7 @@
|
|||||||
async deleteConfirmNote(path) {
|
async deleteConfirmNote(path) {
|
||||||
if (this.deleteConfirm) {
|
if (this.deleteConfirm) {
|
||||||
//console.log("delete file:", path)
|
//console.log("delete file:", path)
|
||||||
await this.deleteNote(path)
|
await this.deleteBuffer(path)
|
||||||
this.hideActionButtons()
|
this.hideActionButtons()
|
||||||
this.buildItems()
|
this.buildItems()
|
||||||
this.selected = Math.min(this.selected, this.items.length - 1)
|
this.selected = Math.min(this.selected, this.items.length - 1)
|
||||||
@ -264,7 +264,7 @@
|
|||||||
<button
|
<button
|
||||||
v-if="actionButton > 0 && idx === selected"
|
v-if="actionButton > 0 && idx === selected"
|
||||||
:class="{'selected':actionButton === 1}"
|
:class="{'selected':actionButton === 1}"
|
||||||
@click.stop.prevent="editNote(item.path)"
|
@click.stop.prevent="editBufferMetadata(item.path)"
|
||||||
>Edit</button>
|
>Edit</button>
|
||||||
<button
|
<button
|
||||||
v-if="actionButton > 0 && idx === selected"
|
v-if="actionButton > 0 && idx === selected"
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import { toRaw } from 'vue';
|
import { toRaw } from 'vue';
|
||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
import { useNotesStore } from "../stores/notes-store"
|
import { useHeynoteStore } from "../stores/heynote-store"
|
||||||
|
|
||||||
import FolderSelector from './folder-selector/FolderSelector.vue'
|
import FolderSelector from './folder-selector/FolderSelector.vue'
|
||||||
|
|
||||||
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
async mounted() {
|
async mounted() {
|
||||||
this.$refs.nameInput.focus()
|
this.$refs.nameInput.focus()
|
||||||
this.updateNotes()
|
this.updateBuffers()
|
||||||
|
|
||||||
console.log("EditNote mounted", this.currentNote)
|
console.log("EditNote mounted", this.currentNote)
|
||||||
this.name = this.currentNote.name
|
this.name = this.currentNote.name
|
||||||
@ -56,7 +56,7 @@
|
|||||||
name: part,
|
name: part,
|
||||||
children: [],
|
children: [],
|
||||||
path: currentPath,
|
path: currentPath,
|
||||||
open: this.currentNotePath.startsWith(currentPath),
|
open: this.currentBufferPath.startsWith(currentPath),
|
||||||
}
|
}
|
||||||
currentLevel.children.push(node)
|
currentLevel.children.push(node)
|
||||||
currentLevel = node
|
currentLevel = node
|
||||||
@ -68,17 +68,17 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useNotesStore, [
|
...mapState(useHeynoteStore, [
|
||||||
"notes",
|
"buffers",
|
||||||
"currentNotePath",
|
"currentBufferPath",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
currentNote() {
|
currentNote() {
|
||||||
return this.notes[this.currentNotePath]
|
return this.buffers[this.currentBufferPath]
|
||||||
},
|
},
|
||||||
|
|
||||||
currentNoteDirectory() {
|
currentNoteDirectory() {
|
||||||
return this.currentNotePath.split("/").slice(0, -1).join("/")
|
return this.currentBufferPath.split("/").slice(0, -1).join("/")
|
||||||
},
|
},
|
||||||
|
|
||||||
nameInputClass() {
|
nameInputClass() {
|
||||||
@ -90,9 +90,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useNotesStore, [
|
...mapActions(useHeynoteStore, [
|
||||||
"updateNotes",
|
"updateBuffers",
|
||||||
"updateNoteMetadata",
|
"updateBufferMetadata",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
onKeydown(event) {
|
onKeydown(event) {
|
||||||
@ -137,19 +137,19 @@
|
|||||||
for (let i=0; i<1000; i++) {
|
for (let i=0; i<1000; i++) {
|
||||||
let filename = slug + ".txt"
|
let filename = slug + ".txt"
|
||||||
path = parentPathPrefix + filename
|
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
|
// file name is ok if it's the current note, or if it doesn't exist
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
slug = slugify(this.name + "-" + i)
|
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)
|
console.error("Failed to edit note, path already exists", path)
|
||||||
this.errors.name = true
|
this.errors.name = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log("Update note", path)
|
console.log("Update note", path)
|
||||||
this.updateNoteMetadata(this.currentNotePath, this.name, path)
|
this.updateBufferMetadata(this.currentBufferPath, this.name, path)
|
||||||
this.$emit("close")
|
this.$emit("close")
|
||||||
//this.$emit("create", this.$refs.input.value)
|
//this.$emit("create", this.$refs.input.value)
|
||||||
},
|
},
|
@ -4,7 +4,7 @@
|
|||||||
import { toRaw } from 'vue';
|
import { toRaw } from 'vue';
|
||||||
import { mapState, mapWritableState, mapActions } from 'pinia'
|
import { mapState, mapWritableState, mapActions } from 'pinia'
|
||||||
import { useErrorStore } from "../stores/error-store"
|
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"
|
import { useEditorCacheStore } from "../stores/editor-cache"
|
||||||
|
|
||||||
const NUM_EDITOR_INSTANCES = 5
|
const NUM_EDITOR_INSTANCES = 5
|
||||||
@ -50,7 +50,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loadBuffer(this.currentNotePath)
|
this.loadBuffer(this.currentBufferPath)
|
||||||
|
|
||||||
// set up window close handler that will save the buffer and quit
|
// set up window close handler that will save the buffer and quit
|
||||||
window.heynote.onWindowClose(() => {
|
window.heynote.onWindowClose(() => {
|
||||||
@ -87,8 +87,8 @@
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
loadNewEditor() {
|
loadNewEditor() {
|
||||||
//console.log("currentNotePath changed to", path)
|
//console.log("currentBufferPath changed to", path)
|
||||||
this.loadBuffer(this.currentNotePath)
|
this.loadBuffer(this.currentBufferPath)
|
||||||
},
|
},
|
||||||
|
|
||||||
theme(newTheme) {
|
theme(newTheme) {
|
||||||
@ -150,17 +150,17 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useNotesStore, [
|
...mapState(useHeynoteStore, [
|
||||||
"currentNotePath",
|
"currentBufferPath",
|
||||||
"libraryId",
|
"libraryId",
|
||||||
]),
|
]),
|
||||||
...mapWritableState(useNotesStore, [
|
...mapWritableState(useHeynoteStore, [
|
||||||
"currentEditor",
|
"currentEditor",
|
||||||
"currentNoteName",
|
"currentBufferName",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
loadNewEditor() {
|
loadNewEditor() {
|
||||||
return `${this.currentNotePath}|${this.libraryId}`
|
return `${this.currentBufferPath}|${this.libraryId}`
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import slugify from '@sindresorhus/slugify';
|
import slugify from '@sindresorhus/slugify';
|
||||||
|
|
||||||
import { mapState, mapActions } from 'pinia'
|
import { mapState, mapActions } from 'pinia'
|
||||||
import { useNotesStore } from "../stores/notes-store"
|
import { useHeynoteStore } from "../stores/heynote-store"
|
||||||
|
|
||||||
import FolderSelector from './folder-selector/FolderSelector.vue'
|
import FolderSelector from './folder-selector/FolderSelector.vue'
|
||||||
|
|
||||||
@ -24,8 +24,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
async mounted() {
|
async mounted() {
|
||||||
if (!!this.createNoteParams.name) {
|
if (!!this.createBufferParams.name) {
|
||||||
this.name = this.createNoteParams.name
|
this.name = this.createBufferParams.name
|
||||||
this.$refs.nameInput.focus()
|
this.$refs.nameInput.focus()
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.nameInput.select()
|
this.$refs.nameInput.select()
|
||||||
@ -34,7 +34,7 @@
|
|||||||
this.$refs.nameInput.focus()
|
this.$refs.nameInput.focus()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateNotes()
|
this.updateBuffers()
|
||||||
|
|
||||||
// build directory tree
|
// build directory tree
|
||||||
const directories = await window.heynote.buffer.getDirectoryList()
|
const directories = await window.heynote.buffer.getDirectoryList()
|
||||||
@ -61,7 +61,7 @@
|
|||||||
name: part,
|
name: part,
|
||||||
children: [],
|
children: [],
|
||||||
path: currentPath,
|
path: currentPath,
|
||||||
open: this.currentNotePath.startsWith(currentPath),
|
open: this.currentBufferPath.startsWith(currentPath),
|
||||||
}
|
}
|
||||||
currentLevel.children.push(node)
|
currentLevel.children.push(node)
|
||||||
currentLevel = node
|
currentLevel = node
|
||||||
@ -73,14 +73,14 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useNotesStore, [
|
...mapState(useHeynoteStore, [
|
||||||
"notes",
|
"buffers",
|
||||||
"currentNotePath",
|
"currentBufferPath",
|
||||||
"createNoteParams",
|
"createBufferParams",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
currentNoteDirectory() {
|
currentNoteDirectory() {
|
||||||
return this.currentNotePath.split("/").slice(0, -1).join("/")
|
return this.currentBufferPath.split("/").slice(0, -1).join("/")
|
||||||
},
|
},
|
||||||
|
|
||||||
nameInputClass() {
|
nameInputClass() {
|
||||||
@ -91,15 +91,15 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
dialogTitle() {
|
dialogTitle() {
|
||||||
return this.createNoteParams.mode === "currentBlock" ? "New Note from Block" : "New Note"
|
return this.createBufferParams.mode === "currentBlock" ? "New Note from Block" : "New Note"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions(useNotesStore, [
|
...mapActions(useHeynoteStore, [
|
||||||
"updateNotes",
|
"updateBuffers",
|
||||||
"createNewNote",
|
"createNewBuffer",
|
||||||
"createNewNoteFromActiveBlock",
|
"createNewBufferFromActiveBlock",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
onKeydown(event) {
|
onKeydown(event) {
|
||||||
@ -145,23 +145,23 @@
|
|||||||
for (let i=0; i<1000; i++) {
|
for (let i=0; i<1000; i++) {
|
||||||
let filename = slug + ".txt"
|
let filename = slug + ".txt"
|
||||||
path = parentPathPrefix + filename
|
path = parentPathPrefix + filename
|
||||||
if (!this.notes[path]) {
|
if (!this.buffers[path]) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
slug = slugify(this.name + "-" + i)
|
slug = slugify(this.name + "-" + i)
|
||||||
}
|
}
|
||||||
if (this.notes[path]) {
|
if (this.buffers[path]) {
|
||||||
console.error("Failed to create note, path already exists", path)
|
console.error("Failed to create note, path already exists", path)
|
||||||
this.errors.name = true
|
this.errors.name = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log("Creating note", path)
|
//console.log("Creating note", path, this.createBufferParams)
|
||||||
if (this.createNoteParams.mode === "currentBlock") {
|
if (this.createBufferParams.mode === "currentBlock") {
|
||||||
this.createNewNoteFromActiveBlock(path, this.name)
|
this.createNewBufferFromActiveBlock(path, this.name)
|
||||||
} else if (this.createNoteParams.mode === "new") {
|
} else if (this.createBufferParams.mode === "new") {
|
||||||
this.createNewNote(path, this.name)
|
this.createNewBuffer(path, this.name)
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unknown createNote Mode: " + this.createNoteParams.mode)
|
throw new Error("Unknown createNote Mode: " + this.createBufferParams.mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$emit("close")
|
this.$emit("close")
|
@ -2,7 +2,7 @@
|
|||||||
import { mapState } from 'pinia'
|
import { mapState } from 'pinia'
|
||||||
import UpdateStatusItem from './UpdateStatusItem.vue'
|
import UpdateStatusItem from './UpdateStatusItem.vue'
|
||||||
import { LANGUAGES } from '../editor/languages.js'
|
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_MAP = Object.fromEntries(LANGUAGES.map(l => [l.token, l]))
|
||||||
const LANGUAGE_NAMES = Object.fromEntries(LANGUAGES.map(l => [l.token, l.name]))
|
const LANGUAGE_NAMES = Object.fromEntries(LANGUAGES.map(l => [l.token, l.name]))
|
||||||
@ -28,8 +28,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(useNotesStore, [
|
...mapState(useHeynoteStore, [
|
||||||
"currentNoteName",
|
"currentBufferName",
|
||||||
"currentCursorLine",
|
"currentCursorLine",
|
||||||
"currentLanguage",
|
"currentLanguage",
|
||||||
"currentSelectionSize",
|
"currentSelectionSize",
|
||||||
@ -84,11 +84,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
<div
|
<div
|
||||||
@click.stop="$emit('openNoteSelector')"
|
@click.stop="$emit('openBufferSelector')"
|
||||||
class="status-block note clickable"
|
class="status-block note clickable"
|
||||||
:title="changeNoteTitle"
|
:title="changeNoteTitle"
|
||||||
>
|
>
|
||||||
{{ currentNoteName }}
|
{{ currentBufferName }}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@click.stop="$emit('openLanguageSelector')"
|
@click.stop="$emit('openLanguageSelector')"
|
||||||
|
@ -4,7 +4,7 @@ import { EditorState, RangeSetBuilder, StateField, Facet , StateEffect, RangeSet
|
|||||||
import { syntaxTree, ensureSyntaxTree, syntaxTreeAvailable } from "@codemirror/language"
|
import { syntaxTree, ensureSyntaxTree, syntaxTreeAvailable } from "@codemirror/language"
|
||||||
import { Note, Document, NoteDelimiter } from "../lang-heynote/parser.terms.js"
|
import { Note, Document, NoteDelimiter } from "../lang-heynote/parser.terms.js"
|
||||||
import { IterMode } from "@lezer/common";
|
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 { heynoteEvent, LANGUAGE_CHANGE, CURSOR_CHANGE } from "../annotation.js";
|
||||||
import { mathBlock } from "./math.js"
|
import { mathBlock } from "./math.js"
|
||||||
import { emptyBlockSelected } from "./select-all.js";
|
import { emptyBlockSelected } from "./select-all.js";
|
||||||
@ -414,7 +414,7 @@ export function triggerCursorChange({state, dispatch}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const emitCursorChange = (editor) => {
|
const emitCursorChange = (editor) => {
|
||||||
const notesStore = useNotesStore()
|
const notesStore = useHeynoteStore()
|
||||||
return ViewPlugin.fromClass(
|
return ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
update(update) {
|
update(update) {
|
||||||
@ -434,7 +434,7 @@ const emitCursorChange = (editor) => {
|
|||||||
notesStore.currentSelectionSize = selectionSize
|
notesStore.currentSelectionSize = selectionSize
|
||||||
notesStore.currentLanguage = block.language.name
|
notesStore.currentLanguage = block.language.name
|
||||||
notesStore.currentLanguageAuto = block.language.auto
|
notesStore.currentLanguageAuto = block.language.auto
|
||||||
notesStore.currentNoteName = editor.name
|
notesStore.currentBufferName = editor.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import { todoCheckboxPlugin} from "./todo-checkbox.ts"
|
|||||||
import { links } from "./links.js"
|
import { links } from "./links.js"
|
||||||
import { NoteFormat } from "../common/note-format.js"
|
import { NoteFormat } from "../common/note-format.js"
|
||||||
import { AUTO_SAVE_INTERVAL } from "../common/constants.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";
|
import { useErrorStore } from "../stores/error-store.js";
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ export class HeynoteEditor {
|
|||||||
this.fontTheme = new Compartment
|
this.fontTheme = new Compartment
|
||||||
this.setDefaultBlockLanguage(defaultBlockToken, defaultBlockAutoDetect)
|
this.setDefaultBlockLanguage(defaultBlockToken, defaultBlockAutoDetect)
|
||||||
this.contentLoaded = false
|
this.contentLoaded = false
|
||||||
this.notesStore = useNotesStore()
|
this.notesStore = useHeynoteStore()
|
||||||
this.errorStore = useErrorStore()
|
this.errorStore = useErrorStore()
|
||||||
this.name = ""
|
this.name = ""
|
||||||
|
|
||||||
@ -269,40 +269,40 @@ export class HeynoteEditor {
|
|||||||
this.notesStore.openLanguageSelector()
|
this.notesStore.openLanguageSelector()
|
||||||
}
|
}
|
||||||
|
|
||||||
openNoteSelector() {
|
openBufferSelector() {
|
||||||
this.notesStore.openNoteSelector()
|
this.notesStore.openBufferSelector()
|
||||||
}
|
}
|
||||||
|
|
||||||
openCreateNote(createMode) {
|
openCreateBuffer(createMode) {
|
||||||
this.notesStore.openCreateNote(createMode)
|
this.notesStore.openCreateBuffer(createMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
async createNewNote(path, name) {
|
async createNewBuffer(path, name) {
|
||||||
const data = getBlockDelimiter(this.defaultBlockToken, this.defaultBlockAutoDetect)
|
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
|
// 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
|
// would fail if we immediately opened the new note (since the block UI wouldn't have time to update
|
||||||
// after the block was deleted)
|
// after the block was deleted)
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
this.notesStore.openNote(path)
|
this.notesStore.openBuffer(path)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async createNewNoteFromActiveBlock(path, name) {
|
async createNewBufferFromActiveBlock(path, name) {
|
||||||
const block = getActiveNoteBlock(this.view.state)
|
const block = getActiveNoteBlock(this.view.state)
|
||||||
if (!block) {
|
if (!block) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const data = this.view.state.sliceDoc(block.range.from, block.range.to)
|
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)
|
deleteBlock(this)(this.view)
|
||||||
|
|
||||||
// by using requestAnimationFrame we avoid a race condition where rendering the block backgrounds
|
// 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
|
// would fail if we immediately opened the new note (since the block UI wouldn't have time to update
|
||||||
// after the block was deleted)
|
// after the block was deleted)
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
this.notesStore.openNote(path)
|
this.notesStore.openBuffer(path)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ export function heynoteKeymap(editor) {
|
|||||||
["Alt-ArrowUp", moveLineUp],
|
["Alt-ArrowUp", moveLineUp],
|
||||||
["Alt-ArrowDown", moveLineDown],
|
["Alt-ArrowDown", moveLineDown],
|
||||||
["Mod-l", () => editor.openLanguageSelector()],
|
["Mod-l", () => editor.openLanguageSelector()],
|
||||||
["Mod-p", () => editor.openNoteSelector()],
|
["Mod-p", () => editor.openBufferSelector()],
|
||||||
["Mod-s", () => editor.openCreateNote("currentBlock")],
|
["Mod-s", () => editor.openCreateBuffer("currentBlock")],
|
||||||
["Mod-n", () => editor.openCreateNote("new")],
|
["Mod-n", () => editor.openCreateBuffer("new")],
|
||||||
["Mod-Shift-d", deleteBlock(editor)],
|
["Mod-Shift-d", deleteBlock(editor)],
|
||||||
["Alt-Shift-f", formatBlockContent],
|
["Alt-Shift-f", formatBlockContent],
|
||||||
["Mod-Alt-ArrowDown", newCursorBelow],
|
["Mod-Alt-ArrowDown", newCursorBelow],
|
||||||
|
@ -6,7 +6,7 @@ import { createPinia } from 'pinia'
|
|||||||
import App from './components/App.vue'
|
import App from './components/App.vue'
|
||||||
import { loadCurrencies } from './currency'
|
import { loadCurrencies } from './currency'
|
||||||
import { useErrorStore } from './stores/error-store'
|
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'
|
import { useEditorCacheStore } from './stores/editor-cache'
|
||||||
|
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ window.heynote.getInitErrors().then((errors) => {
|
|||||||
errors.forEach((e) => errorStore.addError(e))
|
errors.forEach((e) => errorStore.addError(e))
|
||||||
})
|
})
|
||||||
|
|
||||||
initNotesStore()
|
initHeynoteStore()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,97 +5,97 @@ import { useEditorCacheStore } from "./editor-cache"
|
|||||||
import { SCRATCH_FILE_NAME } from "../common/constants"
|
import { SCRATCH_FILE_NAME } from "../common/constants"
|
||||||
|
|
||||||
|
|
||||||
export const useNotesStore = defineStore("notes", {
|
export const useHeynoteStore = defineStore("heynote", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
notes: {},
|
buffers: {},
|
||||||
recentNotePaths: [SCRATCH_FILE_NAME],
|
recentBufferPaths: [SCRATCH_FILE_NAME],
|
||||||
|
|
||||||
currentEditor: null,
|
currentEditor: null,
|
||||||
currentNotePath: SCRATCH_FILE_NAME,
|
currentBufferPath: SCRATCH_FILE_NAME,
|
||||||
currentNoteName: null,
|
currentBufferName: null,
|
||||||
currentLanguage: null,
|
currentLanguage: null,
|
||||||
currentLanguageAuto: null,
|
currentLanguageAuto: null,
|
||||||
currentCursorLine: null,
|
currentCursorLine: null,
|
||||||
currentSelectionSize: null,
|
currentSelectionSize: null,
|
||||||
libraryId: 0,
|
libraryId: 0,
|
||||||
createNoteParams: {
|
createBufferParams: {
|
||||||
mode: "new",
|
mode: "new",
|
||||||
nameSuggestion: ""
|
nameSuggestion: ""
|
||||||
},
|
},
|
||||||
|
|
||||||
showNoteSelector: false,
|
showBufferSelector: false,
|
||||||
showLanguageSelector: false,
|
showLanguageSelector: false,
|
||||||
showCreateNote: false,
|
showCreateBuffer: false,
|
||||||
showEditNote: false,
|
showEditBuffer: false,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
async updateNotes() {
|
async updateBuffers() {
|
||||||
this.setNotes(await window.heynote.buffer.getList())
|
this.setBuffers(await window.heynote.buffer.getList())
|
||||||
},
|
},
|
||||||
|
|
||||||
setNotes(notes) {
|
setBuffers(buffers) {
|
||||||
this.notes = notes
|
this.buffers = buffers
|
||||||
},
|
},
|
||||||
|
|
||||||
openNote(path) {
|
openBuffer(path) {
|
||||||
this.closeDialog()
|
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)
|
recent.unshift(path)
|
||||||
this.recentNotePaths = recent.slice(0, 100)
|
this.recentBufferPaths = recent.slice(0, 100)
|
||||||
},
|
},
|
||||||
|
|
||||||
openLanguageSelector() {
|
openLanguageSelector() {
|
||||||
this.closeDialog()
|
this.closeDialog()
|
||||||
this.showLanguageSelector = true
|
this.showLanguageSelector = true
|
||||||
},
|
},
|
||||||
openNoteSelector() {
|
openBufferSelector() {
|
||||||
this.closeDialog()
|
this.closeDialog()
|
||||||
this.showNoteSelector = true
|
this.showBufferSelector = true
|
||||||
},
|
},
|
||||||
openCreateNote(createMode, nameSuggestion) {
|
openCreateBuffer(createMode, nameSuggestion) {
|
||||||
createMode = createMode || "new"
|
createMode = createMode || "new"
|
||||||
this.closeDialog()
|
this.closeDialog()
|
||||||
this.createNoteParams = {
|
this.createBufferParams = {
|
||||||
mode: createMode || "new",
|
mode: createMode || "new",
|
||||||
name: nameSuggestion || ""
|
name: nameSuggestion || ""
|
||||||
}
|
}
|
||||||
this.showCreateNote = true
|
this.showCreateBuffer = true
|
||||||
},
|
},
|
||||||
closeDialog() {
|
closeDialog() {
|
||||||
this.showCreateNote = false
|
this.showCreateBuffer = false
|
||||||
this.showNoteSelector = false
|
this.showBufferSelector = false
|
||||||
this.showLanguageSelector = false
|
this.showLanguageSelector = false
|
||||||
this.showEditNote = false
|
this.showEditBuffer = false
|
||||||
},
|
},
|
||||||
|
|
||||||
closeNoteSelector() {
|
closeBufferSelector() {
|
||||||
this.showNoteSelector = false
|
this.showBufferSelector = false
|
||||||
},
|
},
|
||||||
|
|
||||||
editNote(path) {
|
editBufferMetadata(path) {
|
||||||
if (this.currentNotePath !== path) {
|
if (this.currentBufferPath !== path) {
|
||||||
this.openNote(path)
|
this.openBuffer(path)
|
||||||
}
|
}
|
||||||
this.closeDialog()
|
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,
|
* Create a new note file at `path` with name `name` from the current block of the current open editor,
|
||||||
* and switch to it
|
* and switch to it
|
||||||
*/
|
*/
|
||||||
async createNewNoteFromActiveBlock(path, name) {
|
async createNewBufferFromActiveBlock(path, name) {
|
||||||
await toRaw(this.currentEditor).createNewNoteFromActiveBlock(path, name)
|
await toRaw(this.currentEditor).createNewBufferFromActiveBlock(path, name)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new empty note file at `path` with name `name`, and switch to it
|
* Create a new empty note file at `path` with name `name`, and switch to it
|
||||||
*/
|
*/
|
||||||
async createNewNote(path, name) {
|
async createNewBuffer(path, name) {
|
||||||
await toRaw(this.currentEditor).createNewNote(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 {*} name Name of the note
|
||||||
* @param {*} content Contents (without metadata)
|
* @param {*} content Contents (without metadata)
|
||||||
*/
|
*/
|
||||||
async saveNewNote(path, name, content) {
|
async saveNewBuffer(path, name, content) {
|
||||||
//window.heynote.buffer.save(path, content)
|
if (this.buffers[path]) {
|
||||||
//this.updateNotes()
|
|
||||||
|
|
||||||
if (this.notes[path]) {
|
|
||||||
throw new Error(`Note already exists: ${path}`)
|
throw new Error(`Note already exists: ${path}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const note = new NoteFormat()
|
const note = new NoteFormat()
|
||||||
note.content = content
|
note.content = content
|
||||||
note.metadata.name = name
|
note.metadata.name = name
|
||||||
console.log("saving", path, note.serialize())
|
//console.log("saving", path, note.serialize())
|
||||||
await window.heynote.buffer.create(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()
|
const editorCacheStore = useEditorCacheStore()
|
||||||
|
|
||||||
if (this.currentEditor.path !== path) {
|
if (this.currentEditor.path !== path) {
|
||||||
@ -133,40 +130,40 @@ export const useNotesStore = defineStore("notes", {
|
|||||||
//console.log("moving note", path, newPath)
|
//console.log("moving note", path, newPath)
|
||||||
editorCacheStore.freeEditor(path)
|
editorCacheStore.freeEditor(path)
|
||||||
await window.heynote.buffer.move(path, newPath)
|
await window.heynote.buffer.move(path, newPath)
|
||||||
this.openNote(newPath)
|
this.openBuffer(newPath)
|
||||||
this.updateNotes()
|
this.updateBuffers()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async deleteNote(path) {
|
async deleteBuffer(path) {
|
||||||
if (path === SCRATCH_FILE_NAME) {
|
if (path === SCRATCH_FILE_NAME) {
|
||||||
throw new Error("Can't delete scratch file")
|
throw new Error("Can't delete scratch file")
|
||||||
}
|
}
|
||||||
const editorCacheStore = useEditorCacheStore()
|
const editorCacheStore = useEditorCacheStore()
|
||||||
if (this.currentEditor.path === path) {
|
if (this.currentEditor.path === path) {
|
||||||
this.currentEditor = null
|
this.currentEditor = null
|
||||||
this.currentNotePath = SCRATCH_FILE_NAME
|
this.currentBufferPath = SCRATCH_FILE_NAME
|
||||||
}
|
}
|
||||||
editorCacheStore.freeEditor(path)
|
editorCacheStore.freeEditor(path)
|
||||||
await window.heynote.buffer.delete(path)
|
await window.heynote.buffer.delete(path)
|
||||||
await this.updateNotes()
|
await this.updateBuffers()
|
||||||
},
|
},
|
||||||
|
|
||||||
async reloadLibrary() {
|
async reloadLibrary() {
|
||||||
const editorCacheStore = useEditorCacheStore()
|
const editorCacheStore = useEditorCacheStore()
|
||||||
await this.updateNotes()
|
await this.updateBuffers()
|
||||||
editorCacheStore.clearCache(false)
|
editorCacheStore.clearCache(false)
|
||||||
this.currentEditor = null
|
this.currentEditor = null
|
||||||
this.currentNotePath = SCRATCH_FILE_NAME
|
this.currentBufferPath = SCRATCH_FILE_NAME
|
||||||
this.libraryId++
|
this.libraryId++
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export async function initNotesStore() {
|
export async function initHeynoteStore() {
|
||||||
const notesStore = useNotesStore()
|
const heynoteStore = useHeynoteStore()
|
||||||
window.heynote.buffer.setLibraryPathChangeCallback(() => {
|
window.heynote.buffer.setLibraryPathChangeCallback(() => {
|
||||||
notesStore.reloadLibrary()
|
heynoteStore.reloadLibrary()
|
||||||
})
|
})
|
||||||
await notesStore.updateNotes()
|
await heynoteStore.updateBuffers()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user