Code block should auto-save contents #1148

Closed
opened 2026-02-04 23:59:53 +03:00 by OVERLORD · 2 comments
Owner

Originally created by @poliagos on GitHub (Apr 17, 2019).

Describe the bug
A click outside code block editor window silently discards all changes. I suggest changes shall be saved automatically OR there should be a confirmation dialog.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Go to page editor.
  2. Add a new code block and save it.
  3. Double click on the code block to open it for edit.
  4. Make some changes and click outside code block editor window.
  5. Changes will be lost without any confirmation.

Expected behavior
Code editor should auto-save contents OR confirmation dialog should pop-up.

Your Configuration (please complete the following information):

  • Exact BookStack Version (Found in settings): v0.25.2
  • PHP Version: don`t know
  • Hosting Method (Nginx/Apache/Docker): Docker image "solidnerd/bookstack" from dockerhub
Originally created by @poliagos on GitHub (Apr 17, 2019). **Describe the bug** A click outside code block editor window silently discards all changes. I suggest changes shall be saved automatically OR there should be a confirmation dialog. **Steps To Reproduce** Steps to reproduce the behavior: 1. Go to page editor. 2. Add a new code block and save it. 3. Double click on the code block to open it for edit. 4. Make some changes and click outside code block editor window. 5. Changes will be lost without any confirmation. **Expected behavior** Code editor should auto-save contents OR confirmation dialog should pop-up. **Your Configuration (please complete the following information):** - Exact BookStack Version (Found in settings): v0.25.2 - PHP Version: don`t know - Hosting Method (Nginx/Apache/Docker): Docker image "solidnerd/bookstack" from dockerhub
OVERLORD added the 🛠️ Enhancement💆 UX labels 2026-02-04 23:59:53 +03:00
Author
Owner

@TheDauntless commented on GitHub (Jun 3, 2020):

This is also triggered at mouse-up, so if you want to highlight a large part of the code block, and you stop the mouse-drag outside of the code window, all your edits are gone too.

@TheDauntless commented on GitHub (Jun 3, 2020): This is also triggered at mouse-up, so if you want to highlight a large part of the code block, and you stop the mouse-drag outside of the code window, all your edits are gone too.
Author
Owner

@ssddanbrown commented on GitHub (Jun 28, 2020):

Today I have made some changes to the code block editor & popups: a5fa745749

This does two things:

  • Updates the popup behaviour so background overlay clicks have to originate from the background overlay to actually close the popup. this prevents the scenario described by @TheDauntless.
  • Added a session storage level of auto-saving to code blocks. This will save the contents whenever the popup closes to ensure that accidental closures can be quickly recovered from. This looks like so:

image

Since this is only session storage it will only be saved for the lifetime of the tab (In most browsers). I didn't really want to do full-database-level saving as it adds a lot of complexities and I didn't want to use more long-term browser storage for security considerations, but I'm hoping this will still help in most accidental scenarios.

This will be part of the next feature release.
Since I hope the above solution will mostly alleviate this scenario, I'll close this off.

@ssddanbrown commented on GitHub (Jun 28, 2020): Today I have made some changes to the code block editor & popups: https://github.com/BookStackApp/BookStack/commit/a5fa74574919a491986f197d41a5f8186a45562f This does two things: * Updates the popup behaviour so background overlay clicks have to originate from the background overlay to actually close the popup. this prevents the scenario described by @TheDauntless. * Added a session storage level of auto-saving to code blocks. This will save the contents whenever the popup closes to ensure that accidental closures can be quickly recovered from. This looks like so: ![image](https://user-images.githubusercontent.com/8343178/85933976-e69f5280-b8d4-11ea-84de-25d5ea1fa640.png) Since this is only session storage it will only be saved for the lifetime of the tab (In most browsers). I didn't really want to do full-database-level saving as it adds a lot of complexities and I didn't want to use more long-term browser storage for security considerations, but I'm hoping this will still help in most accidental scenarios. This will be part of the next feature release. Since I hope the above solution will mostly alleviate this scenario, I'll close this off.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1148