New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add private method _getSelection #219
Conversation
I really should've squashed them. 👎 to me. |
Meh, personally I like the history there instead. So, 👍 to you! For now, my main use case is–as I said–to simply save the position on preview as is then return to that state when you flip back to the editor. Since nothing is changing between editing and previewing–and if someone did I dont mind it not being in the same place–this should suffice, right? I'm still battling my way through, but do you know offhand how to set the cursor after getting it from this in a cross browser way? If you're busy, no worries :) |
Also, you wont see this merge until I fix the bug, but this is merged into my local branch. Huge thanks! |
Last question, did you check this in Firefox? Probably just me, but it seems to always be giving me a "0" as the selection location. |
I have a feeling its related to this: bug. Can you give me a bit of context as to where/how you're using
Feel free to share branch code, I would love to help and get this caret stuff going too. |
Here's my WIP: 2d8bf2b A couple things.
|
This appears like a bug with Firefox and same bug here. It does not look like this bug is going to get fixed any time soon judging from Boris' comment on the second bug. If we cannot maintain reference to: selection.anchorNode
selection.anchorOffset After the iframe is hidden, this is not going to work in Firefox. There are some ugly hacks which I suspect can solve this in Firefox... :sigh: |
@hongymagic there's a couple things I can think of. The easiest, in theory, would be to save the index (number) before going to preview. When you flip back manually set the cursor to that place. The problem tho was I can't move the cursor at all, displayed or not, in Firefox. second, we could not display none it and instead maybe visibility hidden and lower z index? Maybe -99999999px it to the left? Would these work you think? |
The reason why it doesn't work on Firefox is because the index (number) depends on a node/element. In Firefox, the element becomes UPDATE: here's an example of setting the caret position in Firefox So this leaves us with the second solution. I think the second solution will work. And the best thing about this second way is that you won't need |
Yeah, I think the second makes sense, but im not sure I follow on why number 1 wouldn't work: http://jsbin.com/exofub/1/edit display'd none, then display'd block and it worked. |
It needs to be in the |
@hongymagic for my own knowledge, why the hell doesn't this work on chrome even? http://jsbin.com/exofub/2/edit |
See: revised version which works on both Chrome and Firefox. In short: HTML Elements that we know and use ( <body>1234567</body> But here's how the DOM may look like:
So if you want to set the caret between 1 and 2, then I need to tell the browser to set cursor position at 1 starting from the It gets worse obviously as the HTML grows. This is part of the reason why I wanted to remove browser generate HTML tags (like |
Daaaaammmmmnnnnn. Im glad you gave me this super minimal version so I could visualize this better. This isn't going to be fun once we start doing more DOM editing stuff. Thanks man! |
Reading these comments I'm not entirely clear on where we are vis-a-vis this feature or pull-request. If I tackle this, is there a "good" branch to base my work off of? Should all work on this just be scraped...? |
I'm not sure where @hongymagic is at this point with his work locally, but the "bug" I'm talking about in these comments I fixed and its in develop: dd4dc1b The changes in this PR tho are pretty minimal. |
So what's blocking this pull now? |
Mostly that it'd be unused code as of now. There's nothing that'd really use it yet, and I wasn't sure when I'd be able to get to implementing all the selection API stuff. |
I started digging into how to implement the rest of the proposed API-- oh god the selection API and specs are horrible. |
Yeah... browser selection APIs are kinda a cluster. |
Since there hasn't been any progress in over 2 months now it looks like, I'm going to close this. @hongymagic, feel free to reopen if you're still working on this. |
Adds private method
_getSelection(iframe)
as requested in this comment.Will return a native Selection object. There are a couple of things to note going forward, I'll keep them short here:
if (selection.rangeCount > 0) range = selection.getRangeAt(0)
could also be extracted out as a private function. I will leave that out for now