Use synonyms in Tooltip

This commit is contained in:
Alexandre G.-Raymond 2023-11-11 14:23:30 +01:00
parent e4b00117c3
commit bbc292561f
No known key found for this signature in database
GPG Key ID: 97BA9F51695B5C7B

View File

@ -31,6 +31,9 @@ window.addEventListener(
export const strudelTooltip = hoverTooltip(
(view, pos, side) => {
// Word selection from CodeMirror Hover Tooltip example https://codemirror.net/examples/tooltip/#hover-tooltips
if (!ctrlDown) {
return null;
}
let { from, to, text } = view.state.doc.lineAt(pos);
let start = pos,
end = pos;
@ -47,11 +50,14 @@ export const strudelTooltip = hoverTooltip(
// Get entry from Strudel documentation
let entry = jsdoc.docs.filter((doc) => getDocLabel(doc) === word)[0];
if (!entry) {
return null;
}
if (!ctrlDown) {
return null;
// Try for synonyms
entry = jsdoc.docs.filter((doc) => doc.synonyms && doc.synonyms.includes(word))[0];
if (!entry) {
return null;
}
entry.name = word;
}
return {
pos: start,
end,