0
我正在尝试从DevTools的codeeditor中获取选定的文本。我可以在onSelectionChanged处理程序中获取selectionInfo,但我不知道如何获取文本。如何从DevTools代码编辑器中获取选定的文本?
如何在onSelectionChanged之前获取selectionInfo(当前选择)?
chrome.devtools.panels.sources.createSidebarPane(
"title",
function(sidebar) {
function update(selectionInfo) {
//alert([selectionInfo.url, selectionInfo.startLine, selectionInfo.endLine, selectionInfo.startColumn, selectionInfo.endColumn]);
sidebar.setObject(JSON.parse(JSON.stringify(selectionInfo)));
// How to extract text using data from selectionInfo ???
}
update(/*selectionInfo should be there*/);
chrome.devtools.panels.sources.onSelectionChanged.addListener(update);
}
);
chrome.devtools.panels.sources存在并允许附加在代码管理器中更改选择的监听器。 (也许你正在使用一些旧的浏览器...我使用Chrome 32.0.1671.3?) selectionInfo也被定义并包含5个属性: selectionInfo.url, selectionInfo.startLine, selectionInfo.endLine, selectionInfo .startColumn, selectionInfo.endColumn。 但selectionInfo.selectedText是真的错过了... – user2916617
我使用Chrome 30.0.1599.101(稳定通道),所以我错过了那一个。查看Chromium源代码,它看起来不像selectionInfo具有selectionText属性,请参阅https://chromiumcodereview.appspot.com/23904024。 –