diff --git a/src/components/NewNote.vue b/src/components/NewNote.vue index 96bc77a..b05a1d0 100644 --- a/src/components/NewNote.vue +++ b/src/components/NewNote.vue @@ -67,6 +67,7 @@ ...mapState(useNotesStore, [ "notes", "currentNotePath", + "createNoteMode", ]), currentNoteDirectory() { @@ -78,12 +79,17 @@ "name-input": true, "error": this.errors.name, } - } + }, + + dialogTitle() { + return this.createNoteMode === "currentBlock" ? "New Note from Block" : "New Note" + }, }, methods: { ...mapActions(useNotesStore, [ "updateNotes", + "createNewNote", "createNewNoteFromActiveBlock", ]), @@ -141,7 +147,14 @@ return } console.log("Creating note", path) - this.createNewNoteFromActiveBlock(path, this.name) + if (this.createNoteMode === "currentBlock") { + this.createNewNoteFromActiveBlock(path, this.name) + } else if (this.createNoteMode === "new") { + this.createNewNote(path, this.name) + } else { + throw new Error("Unknown createNoteMode: " + this.createNoteMode) + } + this.$emit("close") //this.$emit("create", this.$refs.input.value) }, @@ -153,7 +166,7 @@
-

New Note from Block

+

{{ dialogTitle }}

{ + this.notesStore.openNote(path) + }) } async createNewNoteFromActiveBlock(path, name) { diff --git a/src/editor/keymap.js b/src/editor/keymap.js index 9b077b1..eb7a229 100644 --- a/src/editor/keymap.js +++ b/src/editor/keymap.js @@ -59,7 +59,8 @@ export function heynoteKeymap(editor) { ["Alt-ArrowDown", moveLineDown], ["Mod-l", () => editor.openLanguageSelector()], ["Mod-p", () => editor.openNoteSelector()], - ["Mod-s", () => editor.openCreateNote()], + ["Mod-s", () => editor.openCreateNote("currentBlock")], + ["Mod-n", () => editor.openCreateNote("new")], ["Mod-Shift-d", deleteBlock(editor)], ["Alt-Shift-f", formatBlockContent], ["Mod-Alt-ArrowDown", newCursorBelow], diff --git a/src/stores/notes-store.js b/src/stores/notes-store.js index 5f815d8..4f46437 100644 --- a/src/stores/notes-store.js +++ b/src/stores/notes-store.js @@ -18,6 +18,7 @@ export const useNotesStore = defineStore("notes", { currentCursorLine: null, currentSelectionSize: null, libraryId: 0, + createNoteMode: "new", showNoteSelector: false, showLanguageSelector: false, @@ -51,8 +52,10 @@ export const useNotesStore = defineStore("notes", { this.closeDialog() this.showNoteSelector = true }, - openCreateNote() { + openCreateNote(createMode) { + createMode = createMode || "new" this.closeDialog() + this.createNoteMode = createMode this.showCreateNote = true }, closeDialog() { @@ -75,12 +78,20 @@ export const useNotesStore = defineStore("notes", { }, /** - * 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 */ async createNewNoteFromActiveBlock(path, name) { await toRaw(this.currentEditor).createNewNoteFromActiveBlock(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) + }, + /** * Create a new note file at path, with name `name`, and content content * @param {*} path: File path relative to Heynote root diff --git a/tests/buffer-creation.spec.js b/tests/buffer-creation.spec.js index a42705c..61b94b6 100644 --- a/tests/buffer-creation.spec.js +++ b/tests/buffer-creation.spec.js @@ -54,7 +54,6 @@ test("create new buffer from block", async ({page}) => { const defaultBuffer = NoteFormat.load(await heynotePage.getStoredBuffer("scratch.txt")) const newBuffer = NoteFormat.load(await heynotePage.getStoredBuffer("my-new-buffer.txt")) - expect(defaultBuffer.content).toBe(` ∞∞∞text Block A @@ -67,3 +66,32 @@ Block C New buffer content`) }) + + +test("create new empty note", async ({page}) => { + await page.locator("body").press("Enter") + await page.locator("body").press("Backspace") + await page.locator("body").press(heynotePage.agnosticKey("Mod+N")) + await page.locator("body").pressSequentially("New Empty Buffer") + await page.locator("body").press("Enter") + await page.waitForTimeout(AUTO_SAVE_INTERVAL + 50); + + const buffers = Object.keys(await heynotePage.getStoredBufferList()) + expect(buffers).toContain("scratch.txt") + expect(buffers).toContain("new-empty-buffer.txt") + + const defaultBuffer = NoteFormat.load(await heynotePage.getStoredBuffer("scratch.txt")) + const newBuffer = NoteFormat.load(await heynotePage.getStoredBuffer("new-empty-buffer.txt")) + + expect(defaultBuffer.content).toBe(` +∞∞∞text +Block A +∞∞∞text +Block B +∞∞∞text +Block C`) + + expect(newBuffer.content).toBe(` +∞∞∞text-a +`) +})