Changeset 1394 for trunk/plugins


Ignore:
Timestamp:
02/10/18 06:36:44 (2 years ago)
Author:
gogo
Message:

Rewrite and standardise key events (see #1393), add onKeyDown, onKeyUp and also onShortCut

This commit rewrites much of the keyboard event handling, but it is (hopefully, in theory, as far as I can test) backwards compatible, in fact, it's so compatible it is used in the exact same way so far as plugins are concerned.

It adds events for plugins of onKeyDown, onKeyUp and also onShortCut

The existing onKeyPress is still fired - however with some caveat, namely the intention is that onKeyPress is only fired for the following classifications of key pressing...

"Adding Characters"

letters, numbers, space, punctuation, symbols, tab, enter

"Deleting Characters"

delete, backspace

"Shortcuts and Other Useful Things"

esc, ctrl-a, ctrl-b...


where previously under some browsers (WebKit?, IE) it would be fired for all keydown events, now it will only fire for "normally useful" events, and the event noise is reduced.

Also considerable work to make sure that the browsers are consistent, to ensure this some "keydown" events in some browsers also produce a "fake" keypress event, where in other browsers they would get a real keypress event (and we want them to).

getKey() hs been improved in Gecko and WebKit? and should be about the same for most uses (certainly all uses in the Xinha distribution), as it now uses the DOM3 keyboard event codes, special keys are now returned by name (where possible), eg tab is reported by getKey as "Tab", where previously, it would have been probably an actual tab character (but other special keys would have been pretty random incorrect characters).

Whew. This was a lot more work than I had anticipated. KeyboardEvent? across browsers is a mess.


Location:
trunk/plugins
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/Equation/ASCIIMathML.js

    r1342 r1394  
    23892389  src = src.replace(/height\s*=\s*\d+/,"height="+(factor*(pic.getAttribute("height")-0))); 
    23902390  document.getElementById(name+"input").value = src; 
    2391 //alert(getKey(evt.keycode)) 
    23922391  updatePicture(name); 
    23932392} 
  • trunk/plugins/GenericPlugin/GenericPlugin.js

    r1067 r1394  
    4646} 
    4747 
     48GenericPlugin.prototype.onKeyDown = function ( event ) 
     49{ 
     50  return false; 
     51} 
     52 
    4853GenericPlugin.prototype.onKeyPress = function ( event ) 
    4954{ 
    5055        return false; 
     56} 
     57 
     58GenericPlugin.prototype.onOnShortCut = function ( event , shortCut ) 
     59{ 
     60  // Where shortCut is a single character, eg if you press ctrl-a, then 
     61  //  shortCut == 'a' 
     62  return false; 
     63} 
     64 
     65GenericPlugin.prototype.onKeyUp = function ( event ) 
     66{ 
     67  return false; 
    5168} 
    5269 
  • trunk/plugins/InsertNote/InsertNote.js

    r1086 r1394  
    568568  // This seems a bit hacky, but I don't presently see 
    569569  // a better way. 
     570  //@NOTE: 8 = Backspace, 46 = Delete; this undocumented 
     571  //  function apears to be for handling delete note references 
     572  //  to have the note automatically deleted also 
    570573  if (event.keyCode == 8 || event.keyCode == 46) 
    571574  { 
  • trunk/plugins/ListOperations/ListOperations.js

    r1377 r1394  
    7777  } 
    7878 
    79   ev.preventDefault(); 
     79  Xinha._stopEvent(ev); 
    8080 
    8181  if( ev.shiftKey ) { 
  • trunk/plugins/TableOperations/TableOperations.js

    r1392 r1394  
    717717        Styler.applyStyleIfMatch(params, /border($|Color|Width|Style)/); 
    718718      } 
     719       
     720      // It is also friendly to remove table borders as it tends to override 
     721      // and this could be confusing when styling borders (user thinks it didn't work) 
     722      Xinha._removeClass(table, 'htmtableborders'); 
    719723    } 
    720724     
     
    883887  } 
    884888 
    885   ev.preventDefault(); 
     889  Xinha._stopEvent(ev); 
    886890     
    887891  // find the next cell, get all the cells (td/th) which are in this table 
Note: See TracChangeset for help on using the changeset viewer.