Autocomplete blob refs. That's too cool.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4467 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
e1383e3903
commit
9fecbd97e8
@ -237,12 +237,47 @@ class TfComposeElement extends LitElement {
|
|||||||
input.click();
|
input.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async autocomplete(text, callback) {
|
||||||
|
this.last_autocomplete = text;
|
||||||
|
let results = [];
|
||||||
|
try {
|
||||||
|
let rows = await tfrpc.rpc.query(`
|
||||||
|
SELECT messages.content FROM messages_fts(?)
|
||||||
|
JOIN messages ON messages.rowid = messages_fts.rowid
|
||||||
|
WHERE messages.content LIKE ?
|
||||||
|
ORDER BY timestamp DESC LIMIT 10
|
||||||
|
`, ['"' + text.replace('"', '""') + '"', `%![%${text}%](%)%`]);
|
||||||
|
for (let row of rows) {
|
||||||
|
for (let match of row.content.matchAll(/!\[([^\]]*)\]\((&.*?)\)/g)) {
|
||||||
|
if (match[1].toLowerCase().indexOf(text) != -1) {
|
||||||
|
results.push({key: match[1], value: match[2]});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (this.last_autocomplete === text) {
|
||||||
|
callback(results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
firstUpdated() {
|
firstUpdated() {
|
||||||
let tribute = new Tribute({
|
let tribute = new Tribute({
|
||||||
|
collection: [
|
||||||
|
{
|
||||||
values: Object.entries(this.users).map(x => ({key: x[1].name, value: x[0]})),
|
values: Object.entries(this.users).map(x => ({key: x[1].name, value: x[0]})),
|
||||||
selectTemplate: function(item) {
|
selectTemplate: function(item) {
|
||||||
return `[@${item.original.key}](${item.original.value})`;
|
return `[@${item.original.key}](${item.original.value})`;
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
trigger: '&',
|
||||||
|
values: this.autocomplete,
|
||||||
|
selectTemplate: function(item) {
|
||||||
|
return `![${item.original.key}](${item.original.value})`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
tribute.attach(this.renderRoot.getElementById('edit'));
|
tribute.attach(this.renderRoot.getElementById('edit'));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user