【发布时间】:2018-03-23 21:03:40
【问题描述】:
如何在 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如何计算?
【问题讨论】:
标签: javascript typescript monaco-editor