javascriptruby-on-railstinymcetinymce-rails

tinymce wordcount is not working on BACKSPCAE


word count function is working fine only when I am typing something in text area when I try to delete words with backspace word count is not working.


Solution

  • From the wordcount plugin source you can see that the word count only gets updated on 'setContent', 'beforeaddUndo' and if the user types a space.

    editor.on('setcontent beforeaddundo', update);
    
    editor.on('keyup', function(e) {
        if (e.keyCode == 32) {
            update();
        }
    });
    

    To extend this behaviour you can update the count on other events too. To add the update of the wordcount on Delete and Backspace key use the tinymce config parameter as follows:

    setup: function(ed){
      ed.on('keyup', function(e) {
        if (e.keyCode == 46 || e.keyCode == 8)
        {
          var wc_bar = ed.theme.panel.find('#wordcount');
    
          if (wc_bar) {
              wc_bar.text(['Words: {0}', ed.plugins.wordcount.getCount()]);
          }
        }
      });
    
    }
    

    Here is a working tinymce fiddle: http://fiddle.tinymce.com/pnfaab