Skip to content
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

IE 8 Bug #7

Open
wahtherewahhere opened this issue Nov 18, 2014 · 3 comments
Open

IE 8 Bug #7

wahtherewahhere opened this issue Nov 18, 2014 · 3 comments

Comments

@wahtherewahhere
Copy link

Firstly, thanks this awesome tool helping my day.
Here is a bug report, hopes it can help others.

In IE 8, the return object of $().getSelection().text is buggy.
I found out the reason.
The reason is the new-line symbol in IE8 is \r\n and IE11 or FF or Chrome is \n
This makes setSelection() and getSelection() buggy.

/*
<textarea id="area"> a
b</textarea>
*/
$("#area").setSelection(1,3);
$("#area").getSelection();

Thanks.

@wahtherewahhere
Copy link
Author

https://github.com/timdown/rangyinputs/blob/master/rangyinputs-jquery-src.js#L161-L168
variable val need adding val = val.replace(/\r/g,"")

https://github.com/timdown/rangyinputs/blob/master/rangyinputs-jquery-src.js#L56-L63
need changing to

function makeSelection(el, start, end) {
        var escapeIE = el.value.replace(/\r/g,""); // here
        console.log("I'm here?");
        return {
            start: start,
            end: end,
            length: end - start,
            text: escapeIE.slice(start, end)  // and here
        };
    }

@timdown
Copy link
Owner

timdown commented Nov 18, 2014

This is by design. The selection offsets are relative to the value of the textarea in all cases. It does mean that offsets can vary between browsers but I think this is preferable to the alternative, which is having selection offsets that are relative to a string that isn't necessarily the same as the textarea's value and therefore needing to normalize the textarea's value before using the offsets.

Having said that, I agree that it would be useful to be able to set a selection reliably with the same offsets in all browsers. I'm not sure what the best API for that is but I'll have a think and get back to you.

@wahtherewahhere
Copy link
Author

sorry,
API is correct, I'm wrong.

jQuery val() return the string with new-line symbol \n , even if it's \r\n it will help us turn into \n.
At mean time, I use getSelection()'s position , which was calculated base on \r\n , spliting the val()'s string then that makes everything mess up.

Sorry, plz close this issue, and thanks for response !

p.s. If it can be normalize, it'll be great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants