diff --git a/ka-note/client/src/lib/actions/mention.ts b/ka-note/client/src/lib/actions/mention.ts index 1df69dc..50ff46f 100644 --- a/ka-note/client/src/lib/actions/mention.ts +++ b/ka-note/client/src/lib/actions/mention.ts @@ -82,10 +82,13 @@ export function mention(node: HTMLInputElement | HTMLTextAreaElement) { } async function selectItem(index: number) { + console.log('[mention-action] selectItem', index, 'items:', items.length, 'create:', createOptions.length, 'mentionStart:', mentionStart, 'value:', JSON.stringify(node.value)); suppressInput = true; try { if (index < items.length) { + console.log('[mention-action] inserting:', items[index].insertText); insertText(items[index].insertText); + console.log('[mention-action] after insert, value:', JSON.stringify(node.value)); } else { const opt = createOptions[index - items.length]; if (!opt) return; diff --git a/ka-note/client/src/lib/actions/mentionCore.ts b/ka-note/client/src/lib/actions/mentionCore.ts index 04fcaaf..6d66947 100644 --- a/ka-note/client/src/lib/actions/mentionCore.ts +++ b/ka-note/client/src/lib/actions/mentionCore.ts @@ -96,8 +96,10 @@ export function renderDropdown( row.className = 'mention-item' + (i === selectedIndex ? ' mention-item-active' : ''); row.textContent = `${item.icon} ${item.mentionName}`; row.classList.add(item.context.type === 'company' ? 'mention-company' : item.context.type === 'person' ? 'mention-person' : 'mention-project'); - row.addEventListener('mousedown', (e) => { + row.addEventListener('pointerdown', (e) => { e.preventDefault(); + e.stopPropagation(); + console.log('[mention] pointerdown item', i, item.mentionName); onSelect(i); }); row.addEventListener('mouseenter', () => onHover(i)); @@ -109,8 +111,10 @@ export function renderDropdown( const row = document.createElement('div'); row.className = 'mention-item mention-create' + (idx === selectedIndex ? ' mention-item-active' : ''); row.textContent = opt.label; - row.addEventListener('mousedown', (e) => { + row.addEventListener('pointerdown', (e) => { e.preventDefault(); + e.stopPropagation(); + console.log('[mention] pointerdown create', idx, opt.label); onSelect(idx); }); row.addEventListener('mouseenter', () => onHover(idx)); diff --git a/ka-note/client/src/lib/components/DashboardView.svelte b/ka-note/client/src/lib/components/DashboardView.svelte index 97d3c60..b1373f6 100644 --- a/ka-note/client/src/lib/components/DashboardView.svelte +++ b/ka-note/client/src/lib/components/DashboardView.svelte @@ -235,8 +235,7 @@ upsertContext({ id: context.id, meta }); } - // Local state for meta notes (needed for bind:value + mention support) - // Only sync from DB on context switch, not on every liveQuery refire + // Local state for meta notes — only sync from DB on context switch let metaNotes = $state(''); let metaNotesContextId = ''; $effect(() => { @@ -245,8 +244,11 @@ metaNotes = (context.meta as any)?.notes ?? ''; } }); - function saveMetaNotes() { - updateMeta('notes', metaNotes); + let metaNotesTimer: ReturnType; + function handleMetaNotesChange(md: string) { + metaNotes = md; + clearTimeout(metaNotesTimer); + metaNotesTimer = setTimeout(() => updateMeta('notes', md), 500); } @@ -351,13 +353,12 @@
- +
{:else} {@const meta = (context.meta ?? { fullName: '', email: '', phone: '', duSince: '' }) as PersonMeta} @@ -394,13 +395,12 @@
- +
{/if} diff --git a/ka-note/client/src/lib/editor/tiptapMention.ts b/ka-note/client/src/lib/editor/tiptapMention.ts index 9cc1b96..7915bc4 100644 --- a/ka-note/client/src/lib/editor/tiptapMention.ts +++ b/ka-note/client/src/lib/editor/tiptapMention.ts @@ -76,13 +76,16 @@ export const TiptapMention = Extension.create({ } async function selectItem(index: number) { + console.log('[tiptap-mention] selectItem', index, 'items:', items.length, 'create:', createOptions.length, 'mentionFrom:', mentionFrom); try { if (index < items.length) { const text = items[index].insertText; + console.log('[tiptap-mention] inserting:', text, 'deleteRange:', mentionFrom, '->', editor.state.selection.from); editor.chain().focus() .deleteRange({ from: mentionFrom, to: editor.state.selection.from }) .insertContent(text + ' ') .run(); + console.log('[tiptap-mention] after insert, content:', editor.storage.markdown.getMarkdown().slice(0, 100)); } else { const opt = createOptions[index - items.length]; if (!opt) return;