如何在 ios 的 Safari 中捕获 selectionStart 和 selectionEnd?

How to capture selectionStart and selectionEnd in Safari for ios?

我们有一个组件允许用户保存我们网站上某些文本的突出显示。它在我们所有其他浏览器中工作正常,但在 ios 的 Safari 中,它不捕获任何 selection.

我们正在使用 Vue,这是表单字段的代码。您可以看到我们对@select.native 事件做出反应。

<b-form-textarea
    v-show="!highlight || editing"
    v-model="highlightableText"
    @select.native="selectText"
    :readonly="true"
    :no-resize="true"
    rows="10"
    ref="highlightable_textarea"
    class="ubcgs-highlightable-text"
>
</b-form-textarea>

select文本方法是这样的:

selectText(e) {
    this.selecting = true;
    this.selectionStart = e.target.selectionStart;
    this.selectionEnd = e.target.selectionEnd;
},

在我的 iPhone 上,我可以 select 按常规方式复制一些文本,然后将其粘贴到另一个 window 中。但是,据我所知,从未调用 selectText 方法。例如,this.selecting 为真时显示一个单独的文本区域,它不显示。

我发现的各种答案和博客似乎都表明这种方法应该有效,但它们是几年前的事了,而且 Apple 喜欢更频繁地更改内容。有没有我应该监听的其他事件,或者其他获取 selection 的方法?

我发现添加事件 "touchend" 有效。工作版本:

<b-form-textarea
    v-show="!highlight || editing"
    v-model="highlightableText"
    @select.native="selectText"
    @touchend.native="selectText"
    :readonly="true"
    :no-resize="true"
    rows="10"
    ref="highlightable_textarea"
    class="ubcgs-highlightable-text"
>
</b-form-textarea>