mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
refactor mention setup
This commit is contained in:
parent
fdb8959aa1
commit
b821ed28fc
@ -3,6 +3,40 @@ import treeService from './tree.js';
|
|||||||
import noteAutocompleteService from './note_autocomplete.js';
|
import noteAutocompleteService from './note_autocomplete.js';
|
||||||
import mimeTypesService from './mime_types.js';
|
import mimeTypesService from './mime_types.js';
|
||||||
|
|
||||||
|
const mentionSetup = {
|
||||||
|
feeds: [
|
||||||
|
{
|
||||||
|
marker: '@',
|
||||||
|
feed: queryText => {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
noteAutocompleteService.autocompleteSource(queryText, rows => {
|
||||||
|
if (rows.length === 1 && rows[0].title === 'No results') {
|
||||||
|
rows = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const row of rows) {
|
||||||
|
row.text = row.name = row.noteTitle;
|
||||||
|
row.id = '@' + row.text;
|
||||||
|
row.link = '#' + row.path;
|
||||||
|
}
|
||||||
|
|
||||||
|
res(rows);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
itemRenderer: item => {
|
||||||
|
const itemElement = document.createElement('span');
|
||||||
|
|
||||||
|
itemElement.classList.add('mentions-item');
|
||||||
|
itemElement.innerHTML = `${item.highlightedTitle} `;
|
||||||
|
|
||||||
|
return itemElement;
|
||||||
|
},
|
||||||
|
minimumCharacters: 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
class NoteDetailText {
|
class NoteDetailText {
|
||||||
/**
|
/**
|
||||||
* @param {TabContext} ctx
|
* @param {TabContext} ctx
|
||||||
@ -54,41 +88,7 @@ class NoteDetailText {
|
|||||||
if (!this.textEditor) {
|
if (!this.textEditor) {
|
||||||
this.textEditor = await BalloonEditor.create(this.$editorEl[0], {
|
this.textEditor = await BalloonEditor.create(this.$editorEl[0], {
|
||||||
placeholder: "Type the content of your note here ...",
|
placeholder: "Type the content of your note here ...",
|
||||||
mention: {
|
mention: mentionSetup,
|
||||||
feeds: [
|
|
||||||
{
|
|
||||||
marker: '@',
|
|
||||||
feed: queryText => {
|
|
||||||
return new Promise((res, rej) => {
|
|
||||||
noteAutocompleteService.autocompleteSource(queryText, rows => {
|
|
||||||
if (rows.length === 1 && rows[0].title === 'No results') {
|
|
||||||
rows = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const row of rows) {
|
|
||||||
row.text = row.name = row.noteTitle;
|
|
||||||
row.id = '@' + row.text;
|
|
||||||
row.link = '#' + row.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(rows.slice(0, Math.min(5, rows.length)));
|
|
||||||
|
|
||||||
res(rows);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
itemRenderer: item => {
|
|
||||||
const itemElement = document.createElement('span');
|
|
||||||
|
|
||||||
itemElement.classList.add('mentions-item');
|
|
||||||
itemElement.innerHTML = `${item.highlightedTitle} `;
|
|
||||||
|
|
||||||
return itemElement;
|
|
||||||
},
|
|
||||||
minimumCharacters: 0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
codeBlock: {
|
codeBlock: {
|
||||||
languages: codeBlockLanguages
|
languages: codeBlockLanguages
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user