HTML 范围构造问题

HTML Range Construction Issue

提问人:Raphael10 提问时间:8/28/2023 更新时间:8/28/2023 访问量:36

问:

使用功能 : ( https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPointCaretPositionFromPoint )

let range = document.caretPositionFromPoint(selectionRectX, selectionRectY)

SelectionRectX = params.x,selectionRectY = params.y 是 Electron BrowserView 的矩形角度的坐标:https://www.electronjs.org/docs/latest/api/web-contents#event-context-menucontext-menu

BrowserView.webContents.on('context-menu', (e, params) => {

输出:params

{
    "x": 782,
    "y": 419,
    "selectionText": "than",
        "web_view_bounds": {
        "x": 0,
        "y": 70,
        "width": 1850,
        "height": 1016
},

我收到此错误:

TS2339: Property 'caretPositionFromPoint' does not exist on type 'Document'

错误,已经为TypeScript打开了错误报告:https://github.com/microsoft/TypeScript/issues/49931,目前似乎卡住了

如果我使用函数:( https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPointcaretRangeFromPoint )

let range = document.caretRangeFromPoint(selectionRectX, selectionRectY)

我得到这个范围:

enter image description here

哪个是折叠的

如何从 BrowserView 的上下文菜单的输出中构建一个未折叠 () 的范围?range.collapsed ==== false

打字稿 DOM 电子 范围

评论


答: 暂无答案