TerryMooreII / angular-wysiwyg

An AngularJS WYSIWYG directive that multiple instances and two-way data-binding.
MIT License
121 stars 75 forks source link

Formatting not applied until next keystroke or click #15

Closed ckames closed 9 years ago

ckames commented 9 years ago

I'm using your directive with bootstrap 3 and Angular 1.3. I've found that when I highlight text and click "Bold" (or any other formatting change) and then immediately save, the formatting changes are not saved.

Digging a little deeper, I noticed that clicking toolbar buttons does not trigger the event listener that copies changes back to the ng-model variable:

            textarea.on('keyup mouseup', function() {
                scope.$apply(function readViewText() {
                    var html = textarea.html();
                    if (html == '<br>') {
                        html = '';
                    }
                    ngModelController.$setViewValue(html);
                });
            });

That's find for command buttons that only set mode, but can lead to unexpected behavior for command buttons that modify text.

Changes are captured correctly as long as you click or type at least once inside the textarea before saving.

I'll keep messing with it and let you know if I find a fix before you have a chance to look at it.

TerryMooreII commented 9 years ago

Fixed in 1.1.4