Fix auto mention on person detail

This commit is contained in:
Jonathan Staab 2023-04-10 10:13:53 -05:00
parent 35f1431ae2
commit 72203afb94
2 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,5 @@
<script lang="ts">
import {nip19} from "nostr-tools"
import user from "src/agent/user"
import {modal, location} from "src/app/ui"
@ -7,7 +8,8 @@
const {canPublish} = user
const createNote = () => {
const pubkey = null // TODO use $location.pathname
const matches = $location.pathname.match(/people\/(npub1[0-9a-z]+)/)
const pubkey = matches ? nip19.decode(matches[1]).data : null
modal.set({type: "note/create", pubkey})
}

View File

@ -43,7 +43,7 @@
return {selection, node, offset, word}
}
const autocomplete = ({person}) => {
const autocomplete = ({person, force = false}) => {
const {selection, node, offset, word} = getInfo()
const annotate = (prefix, text, value) => {
@ -70,12 +70,12 @@
}
// Mentions
if (word.length > 1 && word.startsWith("@")) {
if ((force || word.length > 1) && word.startsWith("@")) {
annotate("@", displayPerson(person).trim(), pubkeyEncoder.encode(person.pubkey))
}
// Topics
if (word.length > 1 && word.startsWith("#")) {
if ((force || word.length > 1) && word.startsWith("#")) {
annotate("#", word.slice(1), word.slice(1))
}
@ -139,7 +139,7 @@
selection.getRangeAt(0).insertNode(spaceNode)
selection.collapse(input, 1)
autocomplete({person})
autocomplete({person, force: true})
}
const createNewLines = (n = 1) => {