Fix for an issue where initializing an (unintentional) empty model causes a push onto the Summernote History stack. #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As per my issue post:
Hey all -- I've ran into a bug that affects the the first "undo" of Summernote. When you trigger an "undo" upon loading, the text gets set to a blank value. This affects the History stack of Summernote, causing a strange behaviour. I'm proposing this PR as a fix.
For a example, I've provided two scripts below... First is the original directive (loading Angular Summernote from CDN). The second is my modified fix, proposed at the above PR. Please see here:
Steps to reproduce:
This issue affects when you select a text range, then bold the text, then press undo. In the native demo (without Angular), you are also not able to undo to a blank space.
Specifically, this problem has to do with using the [transclude: 'element']: here. As per this StackOverflow discussion (here), we cannot have access to the scope because it hasn't been created yet. Specifically in the link function, we're passing an empty model into this function. Then we continue and activate the SummernoteController.
Instead, we need to yield and wait until the scope gets created. In my proposed change, I have checked if there is a model provided (a blank one), then watch for a change. I've also added a unit test to check when the Summernote element's HTML is blank. Please let me know what you guys think, or if there's a better approach to this.
Cheers,
Nick
☕