diff --git a/src/components/NewNote.vue b/src/components/NewNote.vue
index b05a1d0d..8998ae7b 100644
--- a/src/components/NewNote.vue
+++ b/src/components/NewNote.vue
@@ -24,7 +24,16 @@
},
async mounted() {
- this.$refs.nameInput.focus()
+ if (!!this.createNoteParams.name) {
+ this.name = this.createNoteParams.name
+ this.$refs.nameInput.focus()
+ this.$nextTick(() => {
+ this.$refs.nameInput.select()
+ })
+ } else {
+ this.$refs.nameInput.focus()
+ }
+
this.updateNotes()
// build directory tree
@@ -67,7 +76,7 @@
...mapState(useNotesStore, [
"notes",
"currentNotePath",
- "createNoteMode",
+ "createNoteParams",
]),
currentNoteDirectory() {
@@ -82,7 +91,7 @@
},
dialogTitle() {
- return this.createNoteMode === "currentBlock" ? "New Note from Block" : "New Note"
+ return this.createNoteParams.mode === "currentBlock" ? "New Note from Block" : "New Note"
},
},
@@ -147,12 +156,12 @@
return
}
console.log("Creating note", path)
- if (this.createNoteMode === "currentBlock") {
+ if (this.createNoteParams.mode === "currentBlock") {
this.createNewNoteFromActiveBlock(path, this.name)
- } else if (this.createNoteMode === "new") {
+ } else if (this.createNoteParams.mode === "new") {
this.createNewNote(path, this.name)
} else {
- throw new Error("Unknown createNoteMode: " + this.createNoteMode)
+ throw new Error("Unknown createNote Mode: " + this.createNoteParams.mode)
}
this.$emit("close")
diff --git a/src/components/NoteSelector.vue b/src/components/NoteSelector.vue
index 8b8b474c..de36b5d2 100644
--- a/src/components/NoteSelector.vue
+++ b/src/components/NoteSelector.vue
@@ -60,13 +60,15 @@
},
filteredItems() {
+ let items
if (this.filter === "") {
- return this.orderedItems
+ items = this.orderedItems
+
} else {
const searchResults = fuzzysort.go(this.filter, this.items, {
keys: ["name", "folder"],
})
- return searchResults.map((result) => {
+ items = searchResults.map((result) => {
const obj = {...result.obj}
const nameHighlight = result[0].highlight("", "")
const folderHighlight = result[1].highlight("", "")
@@ -75,6 +77,15 @@
return obj
})
}
+
+ const newNoteItem = {
+ name: "Create new…",
+ createNew:true,
+ }
+ return [
+ ...items,
+ newNoteItem,
+ ]
},
},
@@ -83,6 +94,7 @@
"updateNotes",
"editNote",
"deleteNote",
+ "openCreateNote",
]),
buildItems() {
@@ -99,7 +111,6 @@
onKeydown(event) {
if (event.key === "Escape") {
- console.log("escape")
event.preventDefault()
if (this.actionButton !== 0) {
this.hideActionButtons()
@@ -112,8 +123,8 @@
if (this.filteredItems.length === 0) {
return
}
-
- const path = this.filteredItems[this.selected].path
+
+ const item = this.filteredItems[this.selected]
if (event.key === "ArrowDown") {
if (this.selected === this.filteredItems.length - 1) {
this.selected = 0
@@ -121,11 +132,9 @@
this.selected = Math.min(this.selected + 1, this.filteredItems.length - 1)
}
event.preventDefault()
- if (this.selected === this.filteredItems.length - 1) {
- this.$refs.container.scrollIntoView({block: "end"})
- } else {
- this.$refs.item[this.selected].scrollIntoView({block: "nearest"})
- }
+ this.$nextTick(() => {
+ this.$refs.container.querySelector(".selected").scrollIntoView({block: "nearest"})
+ })
this.actionButton = 0
} else if (event.key === "ArrowUp") {
if (this.selected === 0) {
@@ -134,28 +143,32 @@
this.selected = Math.max(this.selected - 1, 0)
}
event.preventDefault()
- if (this.selected === 0) {
- this.$refs.container.scrollIntoView({block: "start"})
- } else {
- this.$refs.item[this.selected].scrollIntoView({block: "nearest"})
- }
+ this.$nextTick(() => {
+ this.$refs.container.querySelector(".selected").scrollIntoView({block: "nearest"})
+ })
this.actionButton = 0
- } else if (event.key === "ArrowRight" && path !== SCRATCH_FILE_NAME) {
+ } else if (event.key === "ArrowRight" && this.itemHasActionButtons(item)) {
event.preventDefault()
this.actionButton = Math.min(2, this.actionButton + 1)
- } else if (event.key === "ArrowLeft" && path !== SCRATCH_FILE_NAME) {
+ } else if (event.key === "ArrowLeft" && this.itemHasActionButtons(item)) {
event.preventDefault()
this.actionButton = Math.max(0, this.actionButton - 1)
this.deleteConfirm = false
} else if (event.key === "Enter") {
event.preventDefault()
- if (this.actionButton === 1) {
- console.log("edit file:", path)
- this.editNote(path)
+ if (item.createNew) {
+ if (this.filteredItems.length === 1) {
+ this.openCreateNote("new", this.filter)
+ } else {
+ this.openCreateNote("new", "")
+ }
+ } else if (this.actionButton === 1) {
+ //console.log("edit file:", path)
+ this.editNote(item.path)
} else if (this.actionButton === 2) {
- this.deleteConfirmNote(path)
+ this.deleteConfirmNote(item.path)
} else {
- this.selectItem(path)
+ this.selectItem(item.path)
}
}
},
@@ -164,6 +177,10 @@
this.$emit("openNote", path)
},
+ itemHasActionButtons(item) {
+ return !item.createNew && item.path !== SCRATCH_FILE_NAME
+ },
+
onInput(event) {
// reset selection
this.selected = 0
@@ -178,9 +195,11 @@
getItemClass(item, idx) {
return {
+ "item": true,
"selected": idx === this.selected,
"action-buttons-visible": this.actionButton > 0,
"scratch": item.scratch,
+ "new-note": item.createNew,
}
},
@@ -198,7 +217,7 @@
async deleteConfirmNote(path) {
if (this.deleteConfirm) {
- console.log("delete file:", path)
+ //console.log("delete file:", path)
await this.deleteNote(path)
this.hideActionButtons()
this.buildItems()
@@ -214,8 +233,8 @@
-