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