2025-05-03 17:20:14 +03:00
|
|
|
/**
|
|
|
|
|
* https://github.com/zadam/trilium/issues/978
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-12 19:40:24 +03:00
|
|
|
import { DocumentFragment, ModelElement, Plugin, Position } from "ckeditor5";
|
2025-05-03 17:20:14 +03:00
|
|
|
|
|
|
|
|
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() {
|
2025-07-12 19:40:24 +03:00
|
|
|
let el: Position | ModelElement | DocumentFragment | null = this.editor.model.document.selection.getFirstPosition();
|
2025-05-03 17:20:14 +03:00
|
|
|
|
|
|
|
|
while (el) {
|
|
|
|
|
if ("name" in el && el.name === 'tableCell') {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
el = "parent" in el ? el.parent : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|