Search code examples
javascriptmacosmediawikiimewysiwym

Differency normal characters and half characters on keydown


We forked experimental Mediawiki VisualEditor. This WYSIWYM editor work with a hidden textarea and a representation of the content in DOM. When you focus the view, the focus is given to the textarea, and the view listen to keydown event to add each typed characters to the content, then empty the textarea's value.

The problem occurs with half characters on Mac OS X only. If you type ^or ¨ or any characters which need a second character to be printed, keydown event is fired. So, when user want a 'ê', he types '^'. View get the textarea value ('^') and clean the textarea value. Then, the user type 'e'. The view display '^e'. And as bonus, on Chrome (Firefox is better in this case), user will never be able to type any accents on the current page in any inputs without reloading the window.

Is there any way to make the difference between a real character and a half one ?


Solution

  • Just found a workaround. By listening to keyup event, dead keys returns a keyIdentifier property set to Unidentified.

    So :

    keyuphandler = function(e)
    {
        if (e.keyIdentifier === 'Unidentified')
        {
            return;
        }
        doSomething();
    }