nytimes / ice

track changes with javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iPhone

jamienk opened this issue · comments

When using ICE on an iPhone, the auto-correct features don't work, including double-space for period, auto-SHIFT for first letter of new sentences, correcting spelling, etc.

Any ideas about how to begin to tackle this or where the problem might stem from?

It seems that this code (line 268 of DEV branch) is causing the problem:

 else if (e.type == 'keypress') {
        var needsToBubble = this.keyPress(e);
        if (!needsToBubble) e.preventDefault();
        return needsToBubble;
      }else if (e.type == 'keydown') {
        var needsToBubble = this.keyDown(e);
        if (!needsToBubble) e.preventDefault();
        return needsToBubble;
      }

It seems when either keypress or keydown is intercepted, auto correct stops working in mobile Safari (I tried apple and Chrome varieties).

Any tips on how to continue to investigate would be much appreciated!

OK I've further narrowed it down (starting line 1508 in DEV branch):

        case 32:
          preventDefault = true;
          var range = this.getCurrentRange();
          this._moveRangeToValidTrackingPos(range, range.startContainer);
          this.insert('\u00A0' , range);
          break;

This is where the SPACE key is detected. It seems to stop the space key, track-delete the selection, jump to before the now-deleted part, and insert a space. Mobile Safari autocorrect doesn't like this.

This gets autocorrect to work:

        case 32:
          //preventDefault = true;
          preventDefault = false;
          var range = this.getCurrentRange();
          this._moveRangeToValidTrackingPos(range, range.startContainer);
          //this.insert('\u00A0' , range);
          break;

but it makes the space bar delete the selected text instead of marking it deleted.

This:

        case 32:
          //preventDefault = true;
          preventDefault = false;
          var range = this.getCurrentRange();
          this._moveRangeToValidTrackingPos(range, range.startContainer);
          this.insert('\u00A0' , range);
          break;

keeps auto correct broken but obviously adds multiple spaces for each press.

Perhaps we need to somehow pass the keyPress and keyDown (or maybe just one or the other?) for the space bar back to the browser but with a flag to tell it not to _handleAncillaryKey again...?

How's something like this? Seems to work:

case 32:
          //preventDefault = true;
          if(this._preventHandle == true)
          {
                     this._preventHandle=false;         
                     return;
          }
          preventDefault = false;
          var range = this.getCurrentRange();
          this._moveRangeToValidTrackingPos(range, range.startContainer);
          //this.insert('\u00A0' , range);
          this._preventHandle = true;
          $(this).trigger($.Event('keypress', {keycode:32, shiftKey: false}));
          $(this).trigger($.Event('keydown', {keycode:32, shiftKey: false}));
          break;

EDIT: no I'm wrong...I've obviously now lost the ability for "space" to mean "strike the selection and move the front of it..."

It also doesn't work (no autcorrect) to do "this.insert('\u00A0' , range);" and then trigger the space event...

How about this:

case 32:            
          var range = this.getCurrentRange();
          if(!range.collapsed)
          {
              preventDefault = true;
              this._moveRangeToValidTrackingPos(range, range.startContainer);
              this.insert('\u00A0' , range);
          }
          else
          {
            preventDefault = false;
          }

If text is selected, prevent the default, STRIKE the range, add a space before the STRIKEN text. Otherwise, just send the SPACE event tot he browser so that Mobile Safari can use it to do autocorrect...