const doc = this.activeDocument;
WoxClass.clearCacheValue(doc,"ActiveWindow");
const activeWindow = await doc.ActiveWindow;
WoxClass.clearCacheValue(activeWindow,"Selection");
const selection = await activeWindow.Selection;
const range = await selection.Range;
const start = await range.Start; // 光标的起始位置
const end = await range.End;     // 光标的结束位置
console.log(光标起始位置:${start},结束位置:${end});
const woxDoc = new WoxDocument(doc, this.fileId, this.wpsApp);
const woxRange = await WoxRange.create(range, woxDoc);
const control = await woxRange.getTopContentControl();
if (!control) {
return;
}
上面返回的开始、结束位置,在第2次调用后,始终返回1,不管光标在哪里。中间有过重新加载文档window.location.reload(), 而手动F5刷新后,返回的起始位置又正确了。