javascript - how to detect if cursor text selection is visible on mobile browser? - Stack Overflow

admin2025-04-26  2

I'm trying to add update the jQuery Terminal cursor position when text selection cursor is visible. This is my code:

function update_mobile_cursor() {
    if (is_mobile) {
        var selection = document.getSelection();
        console.log(selection);
        if (selection.anchorNode === selection.focusNode) {
            var range = selection.getRangeAt(0);
            console.log(range);
            self.position(range.endOffset);
        }
    }
}

But both selection and range exists even when the selection cursor is not visible. When I type something, the endOffset points into the last typed character.

Is there a way to detect the visibility of the selection cursor on a mobile Browser?

I have a testing webpage: .php when You press backspace it jumps to the beginning.

NOTE: that the function don't trigger when text selection is changed, I've asked about it here: Listen to cursor change on mobile browser

I test this with Chromium based Brave.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745630686a310997.html

最新回复(0)