mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 01:25:39 -05:00
Add Keybindings for some Markdown Toolbar Actions (#17198)
* Add Keybindings for some markdown toolbar * add extension registry * when in text cell stopPropagation to only trigger one command
This commit is contained in:
@@ -70,17 +70,33 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
@HostListener('document:keydown', ['$event'])
|
||||
onkeydown(e: KeyboardEvent) {
|
||||
if (DOM.getActiveElement() === this.output?.nativeElement && this.isActive() && this.cellModel?.currentMode === CellEditModes.WYSIWYG) {
|
||||
// select the active .
|
||||
// Select all text
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
|
||||
preventDefaultAndExecCommand(e, 'selectAll');
|
||||
// Redo text
|
||||
} else if ((e.metaKey && e.shiftKey && e.key === 'z') || (e.ctrlKey && e.key === 'y') && !this.markdownMode) {
|
||||
this.redoRichTextChange();
|
||||
// Undo text
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.key === 'z') {
|
||||
this.undoRichTextChange();
|
||||
// Outdent text
|
||||
} else if (e.shiftKey && e.key === 'Tab') {
|
||||
preventDefaultAndExecCommand(e, 'outdent');
|
||||
// Indent text
|
||||
} else if (e.key === 'Tab') {
|
||||
preventDefaultAndExecCommand(e, 'indent');
|
||||
// Bold text
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.key === 'b') {
|
||||
preventDefaultAndExecCommand(e, 'bold');
|
||||
// Italicize text
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.key === 'i') {
|
||||
preventDefaultAndExecCommand(e, 'italic');
|
||||
// Underline text
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.key === 'u') {
|
||||
preventDefaultAndExecCommand(e, 'underline');
|
||||
// Code Block
|
||||
} else if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'k') {
|
||||
preventDefaultAndExecCommand(e, 'formatBlock', false, 'pre');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -583,10 +599,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
function preventDefaultAndExecCommand(e: KeyboardEvent, commandId: string) {
|
||||
// use preventDefault() to avoid invoking the editor's select all
|
||||
function preventDefaultAndExecCommand(e: KeyboardEvent, commandId: string, showUI?: boolean, value?: string) {
|
||||
// Use preventDefault() to avoid invoking the editor's select all and stopPropagation to prevent further propagation of the current event
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
document.execCommand(commandId);
|
||||
document.execCommand(commandId, showUI, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user