Skip to content

Commit

Permalink
Release 0.0.19-accelo.3
Browse files Browse the repository at this point in the history
Fix (based on angular-ui#230)

- Only save editor when editor is marked as stale (like done in debounce, which should really be using the same code)
- Listen to keyup for new keystrokes that are sometimes missed by changes event
- Do not file events when updating model
  • Loading branch information
KurtWagner committed Feb 22, 2018
1 parent 4e7180a commit 8eaafc4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.0.19-accelo.3

Fix (based on https://github.com/angular-ui/ui-tinymce/pull/230)

- Only save editor when editor is marked as stale (like done in debounce, which should really be using the same code)
- Listen to keyup for new keystrokes that are sometimes missed by changes event
- Do not file events when updating model

## 0.0.19-accelo.2

Improvement
Expand Down
2 changes: 1 addition & 1 deletion dist/tinymce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-ui-tinymce",
"version": "0.0.19-accelo.2",
"version": "0.0.19-accelo.3",
"descriptin": "This directive allows you to add a tinymce to your form elements.",
"author": "https://github.com/angular-ui/ui-tinymce/graphs/contributors",
"license": "MIT",
Expand Down
10 changes: 7 additions & 3 deletions src/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ angular.module('ui.tinymce', [])
}, tinyInstance,
updateView = function(editor) {
// don't jump into any digest if the content is the same
var content = editor.getContent({format: options.format}).trim();
var content = editor.getContent({format: options.format, no_events: true}).trim();
if (lastSeenContent === content) {
return;
}
Expand Down Expand Up @@ -70,8 +70,8 @@ angular.module('ui.tinymce', [])
return (function(debouncedEditor) {
if (debouncedEditor.isDirty()) {
debouncedEditor.save();
updateView(debouncedEditor);
}
updateView(debouncedEditor);
})(ed);
}, debouncedUpdateDelay);
};
Expand All @@ -92,11 +92,15 @@ angular.module('ui.tinymce', [])

// Update model when:
// - a button has been clicked [ExecCommand]
// - the editor content has been with keystroke [KeyUp]
// - the editor content has been modified [change]
// - the node has changed [NodeChange]
// - an object has been resized (table, image) [ObjectResized]
ed.on('ExecCommand change NodeChange ObjectResized', function() {
ed.on('ExecCommand change NodeChange ObjectResized KeyUp', function() {
if (!options.debounce) {
if (ed.isDirty()) {
ed.save();
}
updateView(ed);
return;
}
Expand Down
24 changes: 24 additions & 0 deletions test/tinymce.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ describe('uiTinymce', function () {
expect(directiveElement.controller('ngModel').$touched).toBe(true);
});

// TODO: get these 2 tests working - https://github.com/angular-ui/ui-tinymce/pull/230/files
xit('should not trigger event on KeyUp', function() {
compile();

var editor = tinymce.editors[1];
spyOn(editor, 'getContent').and.callThrough();
editor.fire('KeyUp');
$timeout.flush();

expect(editor.getContent.calls.count()).toEqual(1);
expect(editor.getContent.calls.argsFor(0)[0].no_events).toBe(true);
});
xit('should not trigger event on ExecCommand', function() {
compile();

var editor = tinymce.editors[1];
spyOn(editor, 'getContent').and.callThrough();
editor.fire('ExecCommand');
$timeout.flush();

expect(editor.getContent.calls.count()).toEqual(1);
expect(editor.getContent.calls.argsFor(0)[0].no_events).toBe(true);
});

it('should remove tinymce instance on $scope destruction', function() {
compile();
expect(tinymce.get(element.attr('id'))).toBeDefined();
Expand Down

0 comments on commit 8eaafc4

Please sign in to comment.