Commit 32e8fcb8 authored by Robert Knight's avatar Robert Knight Committed by Nick Stenning

Fix redundant calls to onEditText() (#3541)

This fixes an issue where onEditText() would be called unnecessarily
when the markdown editor lost focus.

Simplify the code by just listening for the 'input' event, which all our
target browsers support.
parent 206278e6
...@@ -22,7 +22,6 @@ module.exports = function($sanitize) { ...@@ -22,7 +22,6 @@ module.exports = function($sanitize) {
controller: function () {}, controller: function () {},
link: function(scope, elem) { link: function(scope, elem) {
var input = elem[0].querySelector('.js-markdown-input'); var input = elem[0].querySelector('.js-markdown-input');
var inputEl = angular.element(input);
var output = elem[0].querySelector('.js-markdown-preview'); var output = elem[0].querySelector('.js-markdown-preview');
/** /**
...@@ -133,13 +132,12 @@ module.exports = function($sanitize) { ...@@ -133,13 +132,12 @@ module.exports = function($sanitize) {
scope.preview = !scope.preview; scope.preview = !scope.preview;
}; };
// React to the changes to the input
var handleInputChange = debounce(function () { var handleInputChange = debounce(function () {
scope.$apply(function () { scope.$apply(function () {
scope.onEditText({text: input.value}); scope.onEditText({text: input.value});
}); });
}, 100); }, 100);
inputEl.bind('blur change keyup', handleInputChange); input.addEventListener('input', handleInputChange);
// Re-render the markdown when the view needs updating. // Re-render the markdown when the view needs updating.
scope.$watch('text', function () { scope.$watch('text', function () {
......
...@@ -181,7 +181,7 @@ describe('markdown', function () { ...@@ -181,7 +181,7 @@ describe('markdown', function () {
}); });
var input = inputElement(editor); var input = inputElement(editor);
input.value = 'new text'; input.value = 'new text';
util.sendEvent(input, 'change'); util.sendEvent(input, 'input');
assert.called(onEditText); assert.called(onEditText);
assert.calledWith(onEditText, 'new text'); assert.calledWith(onEditText, 'new text');
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment