Merge pull request #16528 from calixteman/bug1831574
[Editor] Commit the text when the user hits ctrl+s (bug 1831574)
This commit is contained in:
		
						commit
						22d350cae6
					
				| @ -65,6 +65,14 @@ class FreeTextEditor extends AnnotationEditor { | |||||||
|       this, |       this, | ||||||
|       "_keyboardManager", |       "_keyboardManager", | ||||||
|       new KeyboardManager([ |       new KeyboardManager([ | ||||||
|  |         [ | ||||||
|  |           // Commit the text in case the user use ctrl+s to save the document.
 | ||||||
|  |           // The event must bubble in order to be caught by the viewer.
 | ||||||
|  |           // See bug 1831574.
 | ||||||
|  |           ["ctrl+s", "mac+meta+s", "ctrl+p", "mac+meta+p"], | ||||||
|  |           FreeTextEditor.prototype.commitOrRemove, | ||||||
|  |           /* bubbles = */ true, | ||||||
|  |         ], | ||||||
|         [ |         [ | ||||||
|           ["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], |           ["ctrl+Enter", "mac+meta+Enter", "Escape", "mac+Escape"], | ||||||
|           FreeTextEditor.prototype.commitOrRemove, |           FreeTextEditor.prototype.commitOrRemove, | ||||||
|  | |||||||
| @ -213,14 +213,14 @@ class KeyboardManager { | |||||||
|     this.allKeys = new Set(); |     this.allKeys = new Set(); | ||||||
| 
 | 
 | ||||||
|     const { isMac } = FeatureTest.platform; |     const { isMac } = FeatureTest.platform; | ||||||
|     for (const [keys, callback] of callbacks) { |     for (const [keys, callback, bubbles = false] of callbacks) { | ||||||
|       for (const key of keys) { |       for (const key of keys) { | ||||||
|         const isMacKey = key.startsWith("mac+"); |         const isMacKey = key.startsWith("mac+"); | ||||||
|         if (isMac && isMacKey) { |         if (isMac && isMacKey) { | ||||||
|           this.callbacks.set(key.slice(4), callback); |           this.callbacks.set(key.slice(4), { callback, bubbles }); | ||||||
|           this.allKeys.add(key.split("+").at(-1)); |           this.allKeys.add(key.split("+").at(-1)); | ||||||
|         } else if (!isMac && !isMacKey) { |         } else if (!isMac && !isMacKey) { | ||||||
|           this.callbacks.set(key, callback); |           this.callbacks.set(key, { callback, bubbles }); | ||||||
|           this.allKeys.add(key.split("+").at(-1)); |           this.allKeys.add(key.split("+").at(-1)); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| @ -264,15 +264,21 @@ class KeyboardManager { | |||||||
|     if (!this.allKeys.has(event.key)) { |     if (!this.allKeys.has(event.key)) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     const callback = this.callbacks.get(this.#serialize(event)); |     const info = this.callbacks.get(this.#serialize(event)); | ||||||
|     if (!callback) { |     if (!info) { | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |     const { callback, bubbles } = info; | ||||||
|     callback.bind(self)(); |     callback.bind(self)(); | ||||||
|  | 
 | ||||||
|  |     // For example, ctrl+s in a FreeText must be handled by the viewer, hence
 | ||||||
|  |     // the event must bubble.
 | ||||||
|  |     if (!bubbles) { | ||||||
|       event.stopPropagation(); |       event.stopPropagation(); | ||||||
|       event.preventDefault(); |       event.preventDefault(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| class ColorManager { | class ColorManager { | ||||||
|   static _colorsMapping = new Map([ |   static _colorsMapping = new Map([ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user