0

In my TinyMCE.init method, I have a setup function like this one :

setup: function(ed){
    ed.onKeyUp.add(function(ed, e){
        var count = ed.getBody().innerText.length;
        var key = e.keyCode || e.charCode;
        console.log(count);
        console.log(ed.getBody().innerText);
    });
}

If my textarea is empty, when I press Backspace (key = 8), count equals 0. When I press Delete (key = 46), count equals 1.

In both cases, console.log(ed.getBody().innerText); returns an empty string.

I want to use this to count (and limit) the size of my TinyMCE. Does anyone can illuminate me about that strange difference ?

VeZoul
  • 500
  • 6
  • 19

1 Answers1

1

Delete is character code 127 in the ASCII-Table. The delete char is written into the textinput and therefore counts to the length of it, but is not displayed, because control characters dont get displayed.

This is indeed strange behaviour, because actually the delete character should not be written into the text field, but it seems like it does

Tom Doodler
  • 1,471
  • 2
  • 15
  • 41