(data = {})
| 5042 | $("mentionSuggestions").hidden = true; |
| 5043 | return; |
| 5044 | } |
| 5045 | const token = ++state.mentionSearchToken; |
| 5046 | const data = await api(`/api/wiki/mentions?user_id=${encodeURIComponent(currentUser())}&q=${encodeURIComponent(context.query)}&limit=6`); |
| 5047 | if (token !== state.mentionSearchToken) return; |
| 5048 | renderMentionSuggestions(data.nodes || []); |
| 5049 | } |
| 5050 | |
| 5051 | function scheduleMentionSearch() { |
| 5052 | window.clearTimeout(state.mentionSearchTimer); |
| 5053 | state.mentionSearchTimer = window.setTimeout(() => { |
| 5054 | searchMentionSuggestions().catch((error) => console.warn("Mention search failed.", error)); |
| 5055 | }, 160); |
| 5056 | } |
| 5057 | |
| 5058 | function insertMention(node) { |
| 5059 | const input = $("chatInput"); |
| 5060 | const context = mentionQueryAtCursor(); |
| 5061 | const title = node.title || node.node_id || "Wiki"; |
| 5062 | const nodeId = node.node_id || node.id || title; |
| 5063 | const mentionText = `@[${title}](${nodeId})`; |
| 5064 | const start = context?.start ?? input.selectionStart ?? input.value.length; |
| 5065 | const end = context?.end ?? input.selectionEnd ?? input.value.length; |
| 5066 | input.value = `${input.value.slice(0, start)}${mentionText} ${input.value.slice(end)}`; |
no test coverage detected