Commit 9766d2f2 authored by Sean Roberts's avatar Sean Roberts Committed by GitHub

Merge pull request #148 from hypothesis/fix-editor-formatting-actions

Fix formatting changes made via toolbar buttons not persisting
parents 9126b3c6 3e084ccb
...@@ -41,6 +41,8 @@ module.exports = function($sanitize) { ...@@ -41,6 +41,8 @@ module.exports = function($sanitize) {
// changed. This re-focuses the input field but really it should // changed. This re-focuses the input field but really it should
// happen automatically. // happen automatically.
input.focus(); input.focus();
scope.onEditText({text: input.value});
} }
function focusInput() { function focusInput() {
......
...@@ -19,6 +19,10 @@ describe('markdown', function () { ...@@ -19,6 +19,10 @@ describe('markdown', function () {
return editor[0].querySelector('.markdown-body'); return editor[0].querySelector('.markdown-body');
} }
function toolbarButtons(editor) {
return Array.from(editor[0].querySelectorAll('.markdown-tools-button'));
}
function getRenderedHTML(editor) { function getRenderedHTML(editor) {
var contentElement = viewElement(editor); var contentElement = viewElement(editor);
if (isHidden(contentElement)) { if (isHidden(contentElement)) {
...@@ -140,12 +144,28 @@ describe('markdown', function () { ...@@ -140,12 +144,28 @@ describe('markdown', function () {
text: 'Hello World', text: 'Hello World',
}); });
var input = inputElement(editor); var input = inputElement(editor);
var buttons = editor[0].querySelectorAll('.markdown-tools-button'); toolbarButtons(editor).forEach(function (button) {
for (var i=0; i < buttons.length; i++) {
input.value = 'original text'; input.value = 'original text';
angular.element(buttons[i]).click(); angular.element(button).click();
assert.equal(input.value, mockFormattingCommand().text); assert.equal(input.value, mockFormattingCommand().text);
} });
});
it('should notify parent that the text changed', function () {
var onEditText = sinon.stub();
var editor = util.createDirective(document, 'markdown', {
readOnly: false,
text: 'Hello World',
onEditText: {
args: ['text'],
callback: onEditText,
},
});
toolbarButtons(editor).forEach(function (button) {
onEditText.reset();
angular.element(button).click();
assert.calledWith(onEditText, inputElement(editor).value);
});
}); });
}); });
......
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