GetmeUK / ContentTools

A JS library for building WYSIWYG editors for HTML content.
http://getcontenttools.com
MIT License
3.95k stars 395 forks source link

Editor loses focus on save calls #467

Closed darksnake747 closed 6 years ago

darksnake747 commented 6 years ago

While editing a page's content, I noticed that the editor would keep losing focus. After a few of them, I decided it wasn't my imagination and dug into the code. I have an auto save process that calls every 30 seconds and that seemed to be the frequency of my interruptions so I started there and ended up finding that in content-tools.js, on line 8824, there is the following code snippet...

root = ContentEdit.Root.get(); if (root.focused()) { root.focused().blur(); }

...which seemed like it would be specifically, and intentionally, causing these interruptions. I commented the blur call out and tested it. Seems to have fixed the problem for me, but I hate directly editing 3rd party tools like that. Plus, not knowing every in and out of ContentTools, I can't say this is a real fix.

So, am I doing something wrong? Or is this a bug; and if not, why is this code there?

anthonyjb commented 6 years ago

Hi @darksnake747 - Thanks for flagging this, sounds like this is a bug when auto saving. I need to cater for passive saves better (saves that take place in the background like autosaves).

The reason we're blur any focused element is to ensure that if the element is empty it's removed from the page before saving, however this isn't necessary in passive saves so I just need to add a check for the passive flag into the if test in your comment.

I've got another bug I'm looking to fix today so I'll get this one resolved at the same time and push a new release shortly.

anthonyjb commented 6 years ago

Resolved in 1.6.2

darksnake747 commented 6 years ago

Awesome! Thanks a lot Anthony.