mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-30 20:41:33 +08:00 
			
		
		
		
	chore(ckeditor5/plugins): integrate indent block shortcut
This commit is contained in:
		
							parent
							
								
									afb987d4dd
								
							
						
					
					
						commit
						2f09411c0d
					
				| @ -1,37 +0,0 @@ | |||||||
| /** |  | ||||||
|  * https://github.com/zadam/trilium/issues/978
 |  | ||||||
|  */ |  | ||||||
| export default function indentBlockShortcutPlugin(editor) { |  | ||||||
| 	editor.keystrokes.set( 'Tab', ( data, cancel ) => { |  | ||||||
| 		const command = editor.commands.get( 'indentBlock' ); |  | ||||||
| 
 |  | ||||||
| 		if ( command.isEnabled && !isInTable() ) { |  | ||||||
| 			command.execute(); |  | ||||||
| 			cancel(); |  | ||||||
| 		} |  | ||||||
| 	} ); |  | ||||||
| 
 |  | ||||||
| 	editor.keystrokes.set( 'Shift+Tab', ( data, cancel ) => { |  | ||||||
| 		const command = editor.commands.get( 'outdentBlock' ); |  | ||||||
| 
 |  | ||||||
| 		if ( command.isEnabled && !isInTable() ) { |  | ||||||
| 			command.execute(); |  | ||||||
| 			cancel(); |  | ||||||
| 		} |  | ||||||
| 	} ); |  | ||||||
| 
 |  | ||||||
| 	// in table TAB should switch cells
 |  | ||||||
| 	function isInTable() { |  | ||||||
| 		let el = editor.model.document.selection.getFirstPosition(); |  | ||||||
| 
 |  | ||||||
| 		while (el) { |  | ||||||
| 			if (el.name === 'tableCell') { |  | ||||||
| 				return true; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			el = el.parent; |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		return false; |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| @ -8,6 +8,7 @@ import InternalLinkPlugin from "./plugins/internallink.js"; | |||||||
| import ReferenceLink from "./plugins/referencelink.js"; | import ReferenceLink from "./plugins/referencelink.js"; | ||||||
| import RemoveFormatLinksPlugin from "./plugins/remove_format_links.js"; | import RemoveFormatLinksPlugin from "./plugins/remove_format_links.js"; | ||||||
| import SpecialCharactersEmojiPlugin from "./plugins/special_characters_emoji.js"; | import SpecialCharactersEmojiPlugin from "./plugins/special_characters_emoji.js"; | ||||||
|  | import IndentBlockShortcutPlugin from "./plugins/indent_block_shortcut.js"; | ||||||
| 
 | 
 | ||||||
| const TRILIUM_PLUGINS: typeof Plugin[] = [ | const TRILIUM_PLUGINS: typeof Plugin[] = [ | ||||||
|     CutToNotePlugin, |     CutToNotePlugin, | ||||||
| @ -17,7 +18,8 @@ const TRILIUM_PLUGINS: typeof Plugin[] = [ | |||||||
|     UploadimagePlugin, |     UploadimagePlugin, | ||||||
|     InternalLinkPlugin, |     InternalLinkPlugin, | ||||||
|     RemoveFormatLinksPlugin, |     RemoveFormatLinksPlugin, | ||||||
|     SpecialCharactersEmojiPlugin |     SpecialCharactersEmojiPlugin, | ||||||
|  |     IndentBlockShortcutPlugin | ||||||
| ]; | ]; | ||||||
| 
 | 
 | ||||||
| export const COMMON_PLUGINS: typeof Plugin[] = [ | export const COMMON_PLUGINS: typeof Plugin[] = [ | ||||||
| @ -78,7 +80,6 @@ export const COMMON_PLUGINS: typeof Plugin[] = [ | |||||||
| 	// MarkdownImportPlugin,
 | 	// MarkdownImportPlugin,
 | ||||||
| 	// MentionCustomization,
 | 	// MentionCustomization,
 | ||||||
| 	// IncludeNote,
 | 	// IncludeNote,
 | ||||||
| 	// indentBlockShortcutPlugin,
 |  | ||||||
| 	PageBreak, | 	PageBreak, | ||||||
| 	GeneralHtmlSupport, | 	GeneralHtmlSupport, | ||||||
| 	TextPartLanguage, | 	TextPartLanguage, | ||||||
|  | |||||||
							
								
								
									
										44
									
								
								packages/ckeditor5/src/plugins/indent_block_shortcut.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								packages/ckeditor5/src/plugins/indent_block_shortcut.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | |||||||
|  | /** | ||||||
|  |  * https://github.com/zadam/trilium/issues/978
 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | import { DocumentFragment, Element, Plugin, Position } from "ckeditor5"; | ||||||
|  | 
 | ||||||
|  | export default class IndentBlockShortcutPlugin extends Plugin { | ||||||
|  | 
 | ||||||
|  |     init() { | ||||||
|  |         this.editor.keystrokes.set( 'Tab', ( _, cancel ) => { | ||||||
|  |             const command = this.editor.commands.get( 'indentBlock' ); | ||||||
|  | 
 | ||||||
|  |             if (command && command.isEnabled && !this.isInTable() ) { | ||||||
|  |                 command.execute(); | ||||||
|  |                 cancel(); | ||||||
|  |             } | ||||||
|  |         } ); | ||||||
|  | 
 | ||||||
|  |         this.editor.keystrokes.set( 'Shift+Tab', ( _, cancel ) => { | ||||||
|  |             const command = this.editor.commands.get( 'outdentBlock' ); | ||||||
|  | 
 | ||||||
|  |             if (command && command.isEnabled && !this.isInTable() ) { | ||||||
|  |                 command.execute(); | ||||||
|  |                 cancel(); | ||||||
|  |             } | ||||||
|  |         } ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // in table TAB should switch cells
 | ||||||
|  |     isInTable() { | ||||||
|  |         let el: Position | Element | DocumentFragment | null = this.editor.model.document.selection.getFirstPosition(); | ||||||
|  | 
 | ||||||
|  |         while (el) { | ||||||
|  |             if ("name" in el && el.name === 'tableCell') { | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             el = "parent" in el ? el.parent : null; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran