Skip to content
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

✨ Limit undo stack to latest 10 changes #963

Merged
merged 2 commits into from
Aug 26, 2022
Merged

✨ Limit undo stack to latest 10 changes #963

merged 2 commits into from
Aug 26, 2022

Conversation

jinh0
Copy link
Contributor

@jinh0 jinh0 commented Aug 19, 2022

No description provided.

function handle (evt: MessageEvent): void {
function handle (this: NeonCore, evt: MessageEvent): void {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding typing for this keyword. This doesn't actually add a new argument for the function, it's just for TypeScript to type this properly.

Comment on lines -352 to +362
this.undoStacks.get(pageURI).push(currentMEI);

// Add to undo stack:
// Remove the bottommost MEI string on the stack
// if the stack is > 10 strings
const undoStack = this.undoStacks.get(pageURI);
const len = undoStack.push(currentMEI);

if (len > 10)
this.undoStacks.set(pageURI, undoStack.slice(1));

// Clear redo stack:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new logic limiting undo stack to 10 strings

@@ -451,20 +461,18 @@ class NeonCore {
* @returns If the action was undone.
*/
undo (pageURI: string): Promise<boolean> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored undo and redo while fixing the undo stack because I realized that we weren't actually resolving the promise in some conditions. The code works functionally the same as before.

Copy link
Member

@yinanazhou yinanazhou left a comment

Choose a reason for hiding this comment

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

Add notifications that explain undo/redo failures, then you can merge this PR.

Also make our console.error into a console.warn since undo/redo fails only when there is nothing on the stack (which isn't that big of a deal).
@@ -2,7 +2,6 @@ import * as Notification from './Notification';
import NeonView from '../NeonView';
import { convertStaffToSb } from './ConvertMei';
import { EditorAction } from '../Types';
import ZoomHandler from '../SingleView/Zoom';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use this import

@jinh0 jinh0 merged commit f9ece0c into develop Aug 26, 2022
@yinanazhou yinanazhou deleted the undo-stack-fix branch October 2, 2022 20:33
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