mirror of
https://github.com/zadam/trilium.git
synced 2026-02-27 09:03:36 +01:00
fix(ckeditor5): cursor jumping on Tab for other widgets such as separators or footnote
Some checks failed
Checks / main (push) Has been cancelled
Some checks failed
Checks / main (push) Has been cancelled
This commit is contained in:
parent
51325e2f4a
commit
f4b6c65bad
@ -2,40 +2,28 @@
|
||||
* https://github.com/zadam/trilium/issues/978
|
||||
*/
|
||||
|
||||
import { ModelDocumentFragment, ModelElement, Plugin, ModelPosition } from "ckeditor5";
|
||||
import { ModelDocumentFragment, ModelElement, Plugin, ModelPosition, ViewDocumentTabEvent, isWidget } from "ckeditor5";
|
||||
|
||||
export default class IndentBlockShortcutPlugin extends Plugin {
|
||||
|
||||
init() {
|
||||
this.editor.keystrokes.set( 'Tab', ( _, cancel ) => {
|
||||
this.listenTo<ViewDocumentTabEvent>(this.editor.editing.view.document, "tab", (ev, data) => {
|
||||
// In tables, allow default Tab behavior for cell navigation
|
||||
if (this.isInTable()) {
|
||||
return;
|
||||
}
|
||||
if (this.isInTable()) return;
|
||||
|
||||
const command = this.editor.commands.get( 'indentBlock' );
|
||||
// Always cancel in non-table contexts to prevent widget navigation
|
||||
data.preventDefault();
|
||||
ev.stop();
|
||||
|
||||
const commandName = data.shiftKey ? "outdentBlock" : "indentBlock";
|
||||
const command = this.editor.commands.get(commandName);
|
||||
if (command?.isEnabled) {
|
||||
command.execute();
|
||||
}
|
||||
|
||||
// Always cancel in non-table contexts to prevent widget navigation
|
||||
cancel();
|
||||
} );
|
||||
|
||||
this.editor.keystrokes.set( 'Shift+Tab', ( _, cancel ) => {
|
||||
// In tables, allow default Shift+Tab behavior for cell navigation
|
||||
if (this.isInTable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const command = this.editor.commands.get( 'outdentBlock' );
|
||||
if (command?.isEnabled) {
|
||||
command.execute();
|
||||
}
|
||||
|
||||
// Always cancel in non-table contexts to prevent widget navigation
|
||||
cancel();
|
||||
} );
|
||||
}, {
|
||||
priority: "highest",
|
||||
context: node => isWidget( node ) || node.is( 'editableElement' ),
|
||||
});
|
||||
}
|
||||
|
||||
// in table TAB should switch cells
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user