Skip to content

Commit

Permalink
fix(ngModel): use paste/cut events in IE to support context menu
Browse files Browse the repository at this point in the history
In IE the model is not updated when the input value is modified using the context
menu, e.g. pasting from the clipboard, or cutting all or part of the current value.
To capture these changes, we bind to the proprietary 'paste' and 'cut' events.

Closes angular#1462
  • Loading branch information
markdalgleish committed Mar 21, 2013
1 parent 23abb99 commit 47569cb
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,32 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
} else {
var timeout;

var deferListener = function() {
if (!timeout) {
timeout = $browser.defer(function() {
listener();
timeout = null;
});
}
};

element.bind('keydown', function(event) {
var key = event.keyCode;

// ignore
// command modifiers arrows
if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return;

if (!timeout) {
timeout = $browser.defer(function() {
listener();
timeout = null;
});
}
deferListener();
});

// if user paste into input using mouse, we need "change" event to catch it
element.bind('change', listener);

// if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it
if ($sniffer.hasEvent('paste')) {
element.bind('paste cut', deferListener);
}
}


Expand Down

0 comments on commit 47569cb

Please sign in to comment.