keymaster icon indicating copy to clipboard operation
keymaster copied to clipboard

Also filter out keypresses when focused on contenteditable elements

Open crittermike opened this issue 12 years ago • 7 comments

I just overrode key.filter() to also ignore keypresses when the current element is contenteditable, using this code:

key.filter = function(event) {
  var tagName = (event.target || event.srcElement).tagName;
  var editable = (event.target || event.srcElement).getAttribute('contenteditable');
  return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA' || editable);
}

I'm not sure if that's the best way to implement it, but it seems like this would be a good default, no?

crittermike avatar Jun 20 '12 15:06 crittermike

The element's isContentEditable property is possibly a better source of information, though I don't know how widely supported it is.

key.filter = function(event) {
  var el = event.target || event.srcElement;
  return !(el.isContentEditable || el.tagName == 'INPUT' ||
           el.tagName == 'SELECT' || el.tagName == 'TEXTAREA');
}

davidchambers avatar Oct 05 '12 21:10 davidchambers

+1

focusaurus avatar Feb 01 '13 00:02 focusaurus

Would you accept a pull request for this change, @madrobby?

davidchambers avatar Jul 30 '13 22:07 davidchambers

:+1: is there any reason this has been open for a year and half? I'm happy to PR if that's all it needs.

ajb avatar Jan 07 '15 01:01 ajb

@ajb not everyone needs this, that's why the filter function is easily overridable. I'd merge a PR with extensive tests tho. It needs detection of the browser supports isContentEditable, I have no idea about how widespread support is. Remember that kemaster should work on older browsers.

madrobby avatar Jan 07 '15 02:01 madrobby

Thanks -- to your credit, key.filter is very-well documented :grinning:. I'll see if I can whip something together...

ajb avatar Jan 07 '15 02:01 ajb

@madrobby Awesome library so far. :+1: to add contenteditable elements in the default filter.

manoharank avatar Jan 12 '15 13:01 manoharank