-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-save changes #4305
Auto-save changes #4305
Conversation
👍 |
Unfortunately the test failures are real. It's the auto-saving on focus-out that's doing it. In the tests, there are a bunch of "go to the editor and then make sure we're at the right URL" assertions. Casper is triggering a focus out on the title and then the route transitions and the URL changes. Not sure what to do about that other than adapting the tests to be ok with |
One more bug, I think, populating the title field with (untitled) is breaking the focus on the body. So:
|
@jaswilli the changes to the tests sound fine ;) |
I'm going to give it a shot. I have a bad feeling that if focus out is always triggered that it's going to cause a bunch of other tests to fail as well. I guess we'll find out. |
Refs #4259 - Auto-save new post when title loses focus. - If a post has '(Untitled)' for a title, regenerate slugs on all title changes--same behavior as a new post that does not yet have a slug. - Adjust some functional tests to handle the automatic transition from editor/new to editor/editor and the URL changes that go along with it.
So the problem with the editor losing focus is much bigger than it might first appear. It's nothing to do with the introduction of autosave, however the change to making autosave happen when the title loses focus is causing this bug to become much, much more apparent than it is in Ghost at present. Try the following:
You'll notice you lose your focus. This happens no-matter-what on the initial save because of the transition from This change to triggering that initial save on defocus of the title field makes this really super obvious because the defocus now happens just as you try to focus and start typing, rather than it happening as a result of you pressing cmd/ctrl+s (which is jarring) or pressing the button (if you press the button you defocus anyway). I don't know what a solution to this might look like - we can't be the first people to have experienced this so perhaps there is a nice way to restore the correct focus after a transition? Alternatively as we now know the initial save will now always happen on defocus of the title we could have the 'edit' form of the editor always load with focus in the editor same as the 'new' one loads with focus in the title area - but I think that might still provide a jarring experience. The tests are currently highlighting this issue I think - because some of the keys don't get sent to the correct location because of the focus being messed around with. Is there any way to transition the route without reloading the editor part of the template? |
By the way - I've been working on this for a few hours and almost have it all straightened out including tests |
Awesome! Do you want me to back out the changes to the tests? |
So there are a couple of pretty major bugs with the suggested idea of autosave-once on focusOut of the title field - namely that if you type a title and hit save there's a great big horrible error (which I think is why that particular test was failing) and also, if you open the editor and then navigate somewhere else you end up with an (Untitled) draft with nothing in it. Soooo.... rather than doing autosave-once (or autosave if new) when focusing out from the title, I've moved it to when focusing into the codemirror textarea. So if you hit tab or click to edit, the route transition happens then. I've also changed the edit route such that when you load it, focus is in the editor. This seems to work ok. This means that the one case where you won't get an autosave is if you go straight from the title to the tags and add a tag. If you enter a title and/or tags and then try to navigate away you still get the nag-to-save. As soon as you go to start creating content, you get an autosave, which I think is reasonably nice. |
That all sounds good to me. Just as a note, you can probably just update the
|
👍 I was going to propose doing it that way as working off the title was just too problematic. If you have it sorted feel free to close this and open a new PR. 💃 |
I've got a new PR (#4307) open with your commit + my own. |
issue TryGhost#4305, issue TryGhost#4259, issue TryGhost#1413 - change new->edit transitionToRoute to be replaceRoute - auto focus in the editor on transition to the edit route - change the one-time autosave to happen on codemirror focusin instead of title focusout - re-add removed tests, and reorder broken test
Refs #4259
on all title changes--same behavior as a new post that does
not yet have a slug.