create note on click if does not exist
This commit is contained in:
@@ -13,7 +13,7 @@ import ListPlugin from '@ckeditor/ckeditor5-list/src/list'
|
||||
import AutoformatPlugin from '@ckeditor/ckeditor5-autoformat/src/autoformat'
|
||||
import ContextedPlugin from '@/ckeditor/ContextedPlugin'
|
||||
import { mdToHtml, htmlToMd } from '@/utils/markdown'
|
||||
import { getNoteByTitle, setActiveNote } from '@/composables/useNotes'
|
||||
import { getNoteByTitle, setActiveNote, addNote } from '@/composables/useNotes'
|
||||
import Autocomplete from '@/components/Autocomplete.vue'
|
||||
|
||||
const props = defineProps<{ note: Note }>()
|
||||
@@ -62,9 +62,11 @@ watch(editorData, () => emit('update', htmlToMd(editorData.value)))
|
||||
let editorInstance: any
|
||||
|
||||
const handleClick = ({ data }: { data: any }) => {
|
||||
if (!data.domTarget.hasAttribute('data-contexted-link')) return
|
||||
const noteTitle = data.domTarget.textContent as string
|
||||
const note = getNoteByTitle(noteTitle)
|
||||
if (note) setActiveNote(note.id)
|
||||
let note: BaseNote | Note | undefined = getNoteByTitle(noteTitle)
|
||||
if (!note) note = addNote(noteTitle, '')
|
||||
setActiveNote(note.id)
|
||||
}
|
||||
|
||||
const autocompleteRef = ref<InstanceType<typeof Autocomplete> | null>(null)
|
||||
|
||||
@@ -104,6 +104,7 @@ export const addNote = (title: string, content: string, goToNote: boolean = fals
|
||||
}
|
||||
baseNotes[id] = newNote
|
||||
if (goToNote) setActiveNote(id)
|
||||
return newNote
|
||||
}
|
||||
|
||||
export const deleteNote = (noteId: string) => {
|
||||
|
||||
Reference in New Issue
Block a user