如何在Monaco编辑器中获取鼠标悬停的单词?
我想显示保存在我的数组中的特定值,以覆盖用户悬停在的单词。因此,当用户悬停在单词上时,我想将该单词与保存在我的数组中的单词进行比较,然后显示该单词的保存值。
我知道以下两种方法:
model.getValue() // gets all the text stored in the model
model.getValueInRange({startLineNumber, startColumn, endLineNumber, endColumn}) // gets the value in Range, but I don't now the start and end column.
以下是我的代码,我只需要在方法getValueInRange上的帮助:
public variableHoverProvider = <monaco.languages.HoverProvider>{
// this is for getting the values on hover over context variables and shortcuts
provideHover: (model, position, token) => {
if (model.getLineContent(position.lineNumber).trim() !== '') { // if only whitespace don't do anything
let current = this.store[this.store.length - 1]; // just the place where I store my words and there values
console.log(model.getValueInRange({
startLineNumber: position.lineNumber,
startColumn: 1, // this is the information I am missing
endLineNumber: position.lineNumber,
endColumn: 5 // this is the information I am missing
}));
// TODO: I have to find somehow the word the mouse is hovering over
// let getMatchingContextVariableValue = current.contextVariables.map(ctxVariable=>{
// if(ctxVariable)
// });
let test = current.contextVariables[22].value;
return {
contents: [
{ value: test }
],
};
}
}
};
有没有人有好的想法,可以告诉我如何获取我正在悬停的文本?或者如何在getvalueInRange方法中计算startColumn和endColumn?