| 
									
										
										
										
											2025-05-04 14:38:37 +03:00
										 |  |  | import { AttributeCommand, Plugin } from "ckeditor5"; | 
					
						
							| 
									
										
										
										
											2020-04-09 23:40:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | const KBD = 'kbd'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * The keyboard shortcut (`kbd`) editing feature. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * It registers the `'kbd'` command, associated keystroke and introduces the | 
					
						
							|  |  |  |  * `kbd` attribute in the model which renders to the view as a `<kbd>` element. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export default class KbdEditing extends Plugin { | 
					
						
							| 
									
										
										
										
											2025-05-04 14:38:37 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public static get pluginName() { | 
					
						
							|  |  |  | 		return 'KbdEditing' as const; | 
					
						
							| 
									
										
										
										
											2020-04-09 23:40:58 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @inheritDoc | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	init() { | 
					
						
							|  |  |  | 		const editor = this.editor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Allow kbd attribute on text nodes.
 | 
					
						
							|  |  |  | 		editor.model.schema.extend( '$text', { allowAttributes: KBD } ); | 
					
						
							|  |  |  | 		editor.model.schema.setAttributeProperties( KBD, { | 
					
						
							|  |  |  | 			isFormatting: true, | 
					
						
							|  |  |  | 			copyOnEnter: true | 
					
						
							|  |  |  | 		} ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		editor.conversion.attributeToElement( { | 
					
						
							|  |  |  | 			model: KBD, | 
					
						
							|  |  |  | 			view: KBD | 
					
						
							|  |  |  | 		} ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		editor.commands.add( KBD, new AttributeCommand( editor, KBD ) ); | 
					
						
							| 
									
										
										
										
											2020-04-10 00:13:08 +02:00
										 |  |  | 		editor.keystrokes.set( 'CTRL+ALT+K', KBD ); | 
					
						
							| 
									
										
										
										
											2020-04-09 23:40:58 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |