mirror of
https://github.com/heyman/heynote.git
synced 2025-02-17 18:51:07 +01:00
Implement functionality for deleting notes
This commit is contained in:
parent
c010df083c
commit
b1746c58cb
@ -96,6 +96,14 @@ export class FileLibrary {
|
|||||||
await this.jetpack.moveAsync(fullOldPath, fullNewPath)
|
await this.jetpack.moveAsync(fullOldPath, fullNewPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async delete(path) {
|
||||||
|
if (path === SCRATCH_FILE_NAME) {
|
||||||
|
throw new Error("Can't delete scratch file")
|
||||||
|
}
|
||||||
|
const fullPath = join(this.basePath, path)
|
||||||
|
await this.jetpack.removeAsync(fullPath)
|
||||||
|
}
|
||||||
|
|
||||||
async getList() {
|
async getList() {
|
||||||
//console.log("Listing notes")
|
//console.log("Listing notes")
|
||||||
const notes = {}
|
const notes = {}
|
||||||
@ -262,6 +270,10 @@ export function setupFileLibraryEventHandlers(win) {
|
|||||||
return await library.move(path, newPath)
|
return await library.move(path, newPath)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ipcMain.handle('buffer:delete', async (event, path) => {
|
||||||
|
return await library.delete(path)
|
||||||
|
});
|
||||||
|
|
||||||
ipcMain.handle("library:selectLocation", async () => {
|
ipcMain.handle("library:selectLocation", async () => {
|
||||||
let result = await dialog.showOpenDialog({
|
let result = await dialog.showOpenDialog({
|
||||||
title: "Select directory to store buffer",
|
title: "Select directory to store buffer",
|
||||||
|
@ -77,6 +77,10 @@ contextBridge.exposeInMainWorld("heynote", {
|
|||||||
return await ipcRenderer.invoke("buffer:save", path, content)
|
return await ipcRenderer.invoke("buffer:save", path, content)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async delete(path) {
|
||||||
|
return await ipcRenderer.invoke("buffer:delete", path)
|
||||||
|
},
|
||||||
|
|
||||||
async move(path, newPath) {
|
async move(path, newPath) {
|
||||||
return await ipcRenderer.invoke("buffer:move", path, newPath)
|
return await ipcRenderer.invoke("buffer:move", path, newPath)
|
||||||
},
|
},
|
||||||
|
@ -22,14 +22,7 @@
|
|||||||
await this.updateNotes()
|
await this.updateNotes()
|
||||||
this.$refs.container.focus()
|
this.$refs.container.focus()
|
||||||
this.$refs.input.focus()
|
this.$refs.input.focus()
|
||||||
this.items = Object.entries(this.notes).map(([path, metadata]) => {
|
this.buildItems()
|
||||||
return {
|
|
||||||
"path": path,
|
|
||||||
"name": metadata?.name || path,
|
|
||||||
"folder": path.split("/").slice(0, -1).join("/"),
|
|
||||||
"scratch": path === SCRATCH_FILE_NAME,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if (this.items.length > 1) {
|
if (this.items.length > 1) {
|
||||||
this.selected = 1
|
this.selected = 1
|
||||||
}
|
}
|
||||||
@ -89,8 +82,21 @@
|
|||||||
...mapActions(useNotesStore, [
|
...mapActions(useNotesStore, [
|
||||||
"updateNotes",
|
"updateNotes",
|
||||||
"editNote",
|
"editNote",
|
||||||
|
"deleteNote",
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
buildItems() {
|
||||||
|
//console.log("buildItems", Object.entries(this.notes))
|
||||||
|
this.items = Object.entries(this.notes).map(([path, metadata]) => {
|
||||||
|
return {
|
||||||
|
"path": path,
|
||||||
|
"name": metadata?.name || path,
|
||||||
|
"folder": path.split("/").slice(0, -1).join("/"),
|
||||||
|
"scratch": path === SCRATCH_FILE_NAME,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
onKeydown(event) {
|
onKeydown(event) {
|
||||||
if (this.filteredItems.length === 0) {
|
if (this.filteredItems.length === 0) {
|
||||||
return
|
return
|
||||||
@ -185,9 +191,13 @@
|
|||||||
this.deleteConfirm = false
|
this.deleteConfirm = false
|
||||||
},
|
},
|
||||||
|
|
||||||
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)
|
||||||
|
this.hideActionButtons()
|
||||||
|
this.buildItems()
|
||||||
|
this.selected = Math.min(this.selected, this.items.length - 1)
|
||||||
} else {
|
} else {
|
||||||
this.deleteConfirm = true
|
this.deleteConfirm = true
|
||||||
this.actionButton = 2
|
this.actionButton = 2
|
||||||
|
@ -325,8 +325,10 @@ export const deleteBlock = (editor) => ({state, dispatch}) => {
|
|||||||
const block = getActiveNoteBlock(state)
|
const block = getActiveNoteBlock(state)
|
||||||
const blocks = state.facet(blockState)
|
const blocks = state.facet(blockState)
|
||||||
let replace = ""
|
let replace = ""
|
||||||
|
let newSelection = block.delimiter.from
|
||||||
if (blocks.length == 1) {
|
if (blocks.length == 1) {
|
||||||
replace = getBlockDelimiter(editor.defaultBlockToken, editor.defaultBlockAutoDetect)
|
replace = getBlockDelimiter(editor.defaultBlockToken, editor.defaultBlockAutoDetect)
|
||||||
|
newSelection = replace.length
|
||||||
}
|
}
|
||||||
dispatch(state.update({
|
dispatch(state.update({
|
||||||
changes: {
|
changes: {
|
||||||
@ -334,7 +336,7 @@ export const deleteBlock = (editor) => ({state, dispatch}) => {
|
|||||||
to: block.range.to,
|
to: block.range.to,
|
||||||
insert: replace,
|
insert: replace,
|
||||||
},
|
},
|
||||||
selection: EditorSelection.cursor(block.delimiter.from),
|
selection: EditorSelection.cursor(newSelection),
|
||||||
annotations: [heynoteEvent.of(DELETE_BLOCK)],
|
annotations: [heynoteEvent.of(DELETE_BLOCK)],
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -109,11 +109,11 @@ export const useNotesStore = defineStore("notes", {
|
|||||||
if (this.currentEditor.path !== path) {
|
if (this.currentEditor.path !== path) {
|
||||||
throw new Error(`Can't update note (${path}) since it's not the active one (${this.currentEditor.path})`)
|
throw new Error(`Can't update note (${path}) since it's not the active one (${this.currentEditor.path})`)
|
||||||
}
|
}
|
||||||
console.log("currentEditor", this.currentEditor)
|
//console.log("currentEditor", this.currentEditor)
|
||||||
toRaw(this.currentEditor).setName(name)
|
toRaw(this.currentEditor).setName(name)
|
||||||
await (toRaw(this.currentEditor)).save()
|
await (toRaw(this.currentEditor)).save()
|
||||||
if (newPath && path !== newPath) {
|
if (newPath && path !== newPath) {
|
||||||
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.openNote(newPath)
|
||||||
@ -121,6 +121,20 @@ export const useNotesStore = defineStore("notes", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async deleteNote(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
|
||||||
|
}
|
||||||
|
editorCacheStore.freeEditor(path)
|
||||||
|
await window.heynote.buffer.delete(path)
|
||||||
|
await this.updateNotes()
|
||||||
|
},
|
||||||
|
|
||||||
async reloadLibrary() {
|
async reloadLibrary() {
|
||||||
const editorCacheStore = useEditorCacheStore()
|
const editorCacheStore = useEditorCacheStore()
|
||||||
await this.updateNotes()
|
await this.updateNotes()
|
||||||
|
Loading…
Reference in New Issue
Block a user