Fix undo on text editor.

This commit is contained in:
Paulo Gustavo Veiga 2023-02-03 04:00:12 -08:00
parent 36f435099d
commit 44a6c19912
2 changed files with 9 additions and 7 deletions

View File

@ -36,24 +36,24 @@ describe('Node manager', () => {
it('undo changes', () => { it('undo changes', () => {
cy.get('body').type('{enter}').type('Mind Mapping rocks!!').type('{enter}'); cy.get('body').type('{enter}').type('Mind Mapping rocks!!').type('{enter}');
cy.focusTopicByText('Mind Mapping rocks!!');
cy.triggerUndo(); cy.triggerUndo();
cy.focusTopicById(36);
cy.matchImageSnapshot('undoChange'); cy.matchImageSnapshot('undoChange');
}); });
it('redo changes', () => { it('redo changes', () => {
cy.get('body').type('{enter}').type('Mind Mapping rocks!!').type('{enter}'); cy.get('body').type('{enter}').type('Mind Mapping rocks!!').type('{enter}');
cy.triggerUndo(); cy.focusTopicByText('Mind Mapping rocks!!');
cy.focusTopicById(36);
cy.triggerUndo();
cy.triggerRedo(); cy.triggerRedo();
cy.focusTopicById(36); cy.focusTopicByText('Mind Mapping rocks!!');
cy.matchImageSnapshot('redoChange'); cy.matchImageSnapshot('redoChange');
}); });
it('Save changes', () => { it('save changes', () => {
cy.get('body').type('{ctrl}s'); cy.get('body').type('{ctrl}s');
cy.matchImageSnapshot('saveChagesShortcut'); cy.matchImageSnapshot('saveChagesShortcut');
}); });

View File

@ -70,8 +70,6 @@ class EditorComponent extends Events {
switch (event.code) { switch (event.code) {
case 'Escape': case 'Escape':
// Revert to previous text ... // Revert to previous text ...
this._topic.setText(this._oldText);
this.resize();
this.close(false); this.close(false);
break; break;
case 'Enter': { case 'Enter': {
@ -253,6 +251,8 @@ class EditorComponent extends Events {
} }
close(update: boolean): void { close(update: boolean): void {
this._topic.setText(this._oldText);
if (update) { if (update) {
this.updateModel(); this.updateModel();
} }
@ -261,6 +261,8 @@ class EditorComponent extends Events {
// Restore topoc share visibility ... // Restore topoc share visibility ...
this._topic.getOrBuildTextShape().setVisibility(true); this._topic.getOrBuildTextShape().setVisibility(true);
this.resize();
} }
} }