- From: abhish-shrivastava <notifications@github.com>
- Date: Sun, 06 Oct 2024 23:40:54 -0700
- To: w3c/selection-api <selection-api@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/selection-api/issues/337/2396029701@github.com>
Sure, here is simple example- <p>....some text...</p> <ul> <li>list 1....</li> <li>list 2...</li> . . . </ul> When a cursor is placed at the start of 1st li (list 1), ideally the startContainer should point to that li with offset 0, Same for endContainer. And that is how it is on desktop browsers. But on mobile (checked this one android/chrome), endContainer points correctly but startContainer points to the text from previous the paragraph block and takes offset from there. Just like that if I place cursor at the beginning of the second li (list 2), startContainer this time points to the 1st list item and takes offset from there. Thus wrongly, selection.isCollapsed returns false and selection.type as 'range'. Also selection's range object's range.collapsed also returns wrongly as false. This is due to faulty implementation by browsers. But here can be an alternate solution to find isCollapsed property instead of checking startContainer and endContainer and their offsets- 1. We can check selection's range object's range.getBoundingClientRect().width. If it is 0 then it is a cursor else it is a range. or 2. To be more comprehensive, we can get selected contents using selection's range objects range.cloneContents() and check if it is empty (not containing any text or image etc.). -- Reply to this email directly or view it on GitHub: https://github.com/w3c/selection-api/issues/337#issuecomment-2396029701 You are receiving this because you are subscribed to this thread. Message ID: <w3c/selection-api/issues/337/2396029701@github.com>
Received on Monday, 7 October 2024 06:40:58 UTC