j-ulrich / jquery-simulate-ext

jQuery simulate extended
https://j-ulrich.github.io/jquery-simulate-ext/
Other
146 stars 48 forks source link

Key-Sequence with delay doesn't insert spaces into DIV or P tags in Chrome #6

Closed mikegioia closed 11 years ago

mikegioia commented 11 years ago

I was successfully able to insert spaces into a textarea tag but the string "This is a test", when inserted into a DIV or P tag gave me "Thisisatest " with the spaces at the end instead of between the words.

I ran this using jQuery 1.7.2, and on Chrome Version 26.0.1410.63 (Ubuntu).

j-ulrich commented 11 years ago

Hmm.. it's working fine for me with jQuery 1.7.2, Chrome 26.0.1410.64 on Win7 x64. I don't have access to an Ubuntu installation at the moment. Could you please try it on the following fiddle (press the "Simulate key-sequence" button): http://jsfiddle.net/ZkKE3/ If the problem occurs on the fiddle as well, it seems to be a problem with bililiteRange.js in the Linux version of Chrome. But I'm afraid that I can't do much in that case except rewriting bililiteRange.js, which I currently don't have time to. :-/

mikegioia commented 11 years ago

It breaks for me when I add a delay (i.e. { delay: 10 } added to the options).

I'll try to see if I can trace it to bililiteRange or the plugin.

j-ulrich commented 11 years ago

I can reproduce it with the delay. It seems that spaces at the end are stripped away and I guess that this happens for every character in Chrome (which causes spaces to vanish). Need to dig into it... It seems to be a shortcoming of bililiteRange.js again. The spaces at the end of a DIV/P/... are ignored and therefore, the characters are inserted before them which causes that all spaces end up at the end of the simulated text.

j-ulrich commented 11 years ago

I found a workaround: make sure the simulated text is not inserted at the end of the content of the DIV/P/... by writing some character in there first and remove it afterwards:

$('#textInput').simulate("key-sequence", {sequence: "|{leftarrow}This is a test{del}", delay: 100});

Working example: http://jsfiddle.net/ZkKE3/3/

Depending on what you want to achieve and which delay you use, this might even be a nice effect (it looks like a text cursor). ;-P If you don't like that effect, use an invisible character instead:

$('#textInput').simulate("key-sequence", {sequence: "\xA0{leftarrow}This is a test{del}", delay: 100});

\xA0 is equivalent to the non-breaking space ( ) and interestingly, it doesn't suffer from the same problems as the normal space. Maybe I'll implement this workaround directly into the plugin...

mikegioia commented 11 years ago

That's nice, thanks. I think the cursor actually makes it look better.

j-ulrich commented 11 years ago

Nevertheless, fixed this in c345a26 (1.1.5): Added a feature/quirk detection and when the quirk is detected (should be the Webkit-based browsers), all spaces are "replaced" (not literally but logically) with "\xA0{leftarrow} {del}" when simulating in a non-input element.

noelboss commented 9 years ago

Doesn't work for me as well. Trying to simulate into a DIV... Safari Version 8.0.8 (10600.8.9) jQuery v1.11.2