Merge pull request #16533 from calixteman/fix_freetext_undo
[Editor] Fix test failures in m-c because of the new FreeText undo/redo stuff
This commit is contained in:
		
						commit
						f2a29e858f
					
				| @ -330,36 +330,6 @@ class AnnotationEditorLayer { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |  | ||||||
|    * Add a new editor and make this addition undoable. |  | ||||||
|    * @param {AnnotationEditor} editor |  | ||||||
|    */ |  | ||||||
|   addANewEditor(editor) { |  | ||||||
|     const cmd = () => { |  | ||||||
|       this.addOrRebuild(editor); |  | ||||||
|     }; |  | ||||||
|     const undo = () => { |  | ||||||
|       editor.remove(); |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     this.addCommands({ cmd, undo, mustExec: true }); |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** |  | ||||||
|    * Add a new editor and make this addition undoable. |  | ||||||
|    * @param {AnnotationEditor} editor |  | ||||||
|    */ |  | ||||||
|   addUndoableEditor(editor) { |  | ||||||
|     const cmd = () => { |  | ||||||
|       this.addOrRebuild(editor); |  | ||||||
|     }; |  | ||||||
|     const undo = () => { |  | ||||||
|       editor.remove(); |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     this.addCommands({ cmd, undo, mustExec: false }); |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   /** |   /** | ||||||
|    * Get an id for an editor. |    * Get an id for an editor. | ||||||
|    * @returns {string} |    * @returns {string} | ||||||
|  | |||||||
| @ -472,6 +472,7 @@ class AnnotationEditor { | |||||||
|    */ |    */ | ||||||
|   rebuild() { |   rebuild() { | ||||||
|     this.div?.addEventListener("focusin", this.#boundFocusin); |     this.div?.addEventListener("focusin", this.#boundFocusin); | ||||||
|  |     this.div?.addEventListener("focusout", this.#boundFocusout); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|  | |||||||
| @ -46,8 +46,6 @@ class FreeTextEditor extends AnnotationEditor { | |||||||
| 
 | 
 | ||||||
|   #editorDivId = `${this.id}-editor`; |   #editorDivId = `${this.id}-editor`; | ||||||
| 
 | 
 | ||||||
|   #hasAlreadyBeenCommitted = false; |  | ||||||
| 
 |  | ||||||
|   #fontSize; |   #fontSize; | ||||||
| 
 | 
 | ||||||
|   static _freeTextDefaultContent = ""; |   static _freeTextDefaultContent = ""; | ||||||
| @ -355,13 +353,6 @@ class FreeTextEditor extends AnnotationEditor { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     super.commit(); |     super.commit(); | ||||||
|     if (!this.#hasAlreadyBeenCommitted) { |  | ||||||
|       // This editor has something and it's the first time
 |  | ||||||
|       // it's commited so we can add it in the undo/redo stack.
 |  | ||||||
|       this.#hasAlreadyBeenCommitted = true; |  | ||||||
|       this.parent.addUndoableEditor(this); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     this.disableEditMode(); |     this.disableEditMode(); | ||||||
|     const savedText = this.#content; |     const savedText = this.#content; | ||||||
|     const newText = (this.#content = this.#extractText().trimEnd()); |     const newText = (this.#content = this.#extractText().trimEnd()); | ||||||
| @ -371,7 +362,12 @@ class FreeTextEditor extends AnnotationEditor { | |||||||
| 
 | 
 | ||||||
|     const setText = text => { |     const setText = text => { | ||||||
|       this.#content = text; |       this.#content = text; | ||||||
|  |       if (!text) { | ||||||
|  |         this.remove(); | ||||||
|  |         return; | ||||||
|  |       } | ||||||
|       this.#setContent(); |       this.#setContent(); | ||||||
|  |       this.rebuild(); | ||||||
|       this.#setEditorDimensions(); |       this.#setEditorDimensions(); | ||||||
|     }; |     }; | ||||||
|     this.addCommands({ |     this.addCommands({ | ||||||
|  | |||||||
| @ -418,6 +418,51 @@ describe("Editor", () => { | |||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|         expect(text).withContext(`In ${browserName}`).toEqual("AAAA"); |         expect(text).withContext(`In ${browserName}`).toEqual("AAAA"); | ||||||
|  | 
 | ||||||
|  |         for (let i = 0; i < 4; i++) { | ||||||
|  |           await page.keyboard.down("Control"); | ||||||
|  |           await page.keyboard.press("z"); | ||||||
|  |           await page.keyboard.up("Control"); | ||||||
|  |           await page.waitForTimeout(10); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         expect(await getSelectedEditors(page)) | ||||||
|  |           .withContext(`In ${browserName}`) | ||||||
|  |           .toEqual([]); | ||||||
|  | 
 | ||||||
|  |         await page.keyboard.down("Control"); | ||||||
|  |         await page.keyboard.press("y"); | ||||||
|  |         await page.keyboard.up("Control"); | ||||||
|  |         await page.waitForTimeout(10); | ||||||
|  | 
 | ||||||
|  |         text = await page.$eval(`${getEditorSelector(9)} .internal`, el => { | ||||||
|  |           return el.innerText; | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         expect(text).withContext(`In ${browserName}`).toEqual("A"); | ||||||
|  | 
 | ||||||
|  |         // Add a new A.
 | ||||||
|  |         const editorRect = await page.$eval(getEditorSelector(9), el => { | ||||||
|  |           const { x, y, width, height } = el.getBoundingClientRect(); | ||||||
|  |           return { x, y, width, height }; | ||||||
|  |         }); | ||||||
|  |         await page.mouse.click( | ||||||
|  |           editorRect.x + editorRect.width / 2, | ||||||
|  |           editorRect.y + editorRect.height / 2, | ||||||
|  |           { clickCount: 2 } | ||||||
|  |         ); | ||||||
|  |         await page.type(`${getEditorSelector(9)} .internal`, "A"); | ||||||
|  | 
 | ||||||
|  |         // Commit.
 | ||||||
|  |         await page.mouse.click( | ||||||
|  |           editorRect.x, | ||||||
|  |           editorRect.y + 2 * editorRect.height | ||||||
|  |         ); | ||||||
|  | 
 | ||||||
|  |         text = await page.$eval(`${getEditorSelector(9)} .internal`, el => { | ||||||
|  |           return el.innerText; | ||||||
|  |         }); | ||||||
|  |         expect(text).withContext(`In ${browserName}`).toEqual("AA"); | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user