Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nwpan
Copy link
Contributor

@nwpan nwpan commented Jan 26, 2016

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:

  1. Click the first link.
  2. Press either CTRL+Z or press the backarrow undo button within the toolbar.
  3. Notice that the text field becomes blank.

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

@nwpan nwpan changed the title Fix for an issue where initializing a empty model causes a push onto the Summernote History stack. Fix for an issue where initializing an (unintentional) empty model causes a push onto the Summernote History stack. Jan 26, 2016
@outsideris
Copy link
Owner

@nwpan Thank you for great PR. I can understand the issue easily because of you explanation. I'm reviewing your PR and consider your approach.

@outsideris
Copy link
Owner

Could you exclude all files in dist/ folder? I want to update it only when new version released.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you if-else statement as below form?

if (!ngModel) {
   ...
} else {
   ...
}

@nwpan
Copy link
Contributor Author

nwpan commented Jan 30, 2016

Thanks for reviewing the PR @outsideris -- I've addressed the issues you've raised. Cheers!

outsideris added a commit that referenced this pull request Feb 1, 2016
…_model

Fix for an issue where initializing an (unintentional) empty model causes a push onto the Summernote History stack.
@outsideris outsideris merged commit 88063d1 into outsideris:master Feb 1, 2016
@outsideris
Copy link
Owner

@nwpan Great! Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants