mei-friend / mei-friend

The mei-friend Web Application: Editing MEI in the Browser
https://mei-friend.mdw.ac.at
GNU Affero General Public License v3.0
33 stars 18 forks source link

Loading a new document does not reset undo history #117

Open maxrothman opened 1 week ago

maxrothman commented 1 week ago

Describe the bug Undo history is kept when a new document is loaded, such that if you undo immediately after loading a document you replace the entire contents of the editor with the contents of the previous document

To Reproduce Steps to reproduce the behavior:

  1. Load a document (A)
  2. Load a different document (B)
  3. Undo

The contents of the editor will be replaced with those of doc A

Expected behavior Undo history is cleared when a document is loaded

Notes This should be pretty straightforward to fix, doc.clearHistory() just needs to be called when a document is loaded. I'm happy to look into making a PR for this.

wergo commented 4 days ago

Thanks for spotting this. Could you make a PR to develop?

maxrothman commented 4 days ago

I took a look into the places where this call could be added. My instinct was that the best place to add it would be in a single central function that handles file loading so that it always gets called whenever a file is loaded. Unfortunately there doesn't seem to be a clear candidate for such a function. Here are the candidates I found by looking through the imports of github-menu.js:

Or is there another approach for where to add the call to doc.clearHistory()? I could use a little guidance on this since I'm not super familiar with mei-friend's code.