mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Notebooks: Ensure WYSIWYG Mode for Keyboard Shortcuts (#14416)
* Ensure WYSIWYG Mode for kb shortcuts * Move logic down to cell model
This commit is contained in:
@@ -22,7 +22,7 @@ import { IMarkdownRenderResult } from 'vs/editor/browser/core/markdownRenderer';
|
|||||||
|
|
||||||
import { NotebookMarkdownRenderer } from 'sql/workbench/contrib/notebook/browser/outputs/notebookMarkdown';
|
import { NotebookMarkdownRenderer } from 'sql/workbench/contrib/notebook/browser/outputs/notebookMarkdown';
|
||||||
import { CellView } from 'sql/workbench/contrib/notebook/browser/cellViews/interfaces';
|
import { CellView } from 'sql/workbench/contrib/notebook/browser/cellViews/interfaces';
|
||||||
import { ICellModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
import { CellEditModes, ICellModel } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||||
import { ISanitizer, defaultSanitizer } from 'sql/workbench/services/notebook/browser/outputs/sanitizer';
|
import { ISanitizer, defaultSanitizer } from 'sql/workbench/services/notebook/browser/outputs/sanitizer';
|
||||||
import { CodeComponent } from 'sql/workbench/contrib/notebook/browser/cellViews/code.component';
|
import { CodeComponent } from 'sql/workbench/contrib/notebook/browser/cellViews/code.component';
|
||||||
@@ -61,7 +61,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
|
|
||||||
@HostListener('document:keydown', ['$event'])
|
@HostListener('document:keydown', ['$event'])
|
||||||
onkeydown(e: KeyboardEvent) {
|
onkeydown(e: KeyboardEvent) {
|
||||||
if (this.isActive()) {
|
if (this.isActive() && this.cellModel?.currentMode === CellEditModes.WYSIWYG) {
|
||||||
// select the active .
|
// select the active .
|
||||||
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
|
if ((e.ctrlKey || e.metaKey) && e.key === 'a') {
|
||||||
preventDefaultAndExecCommand(e, 'selectAll');
|
preventDefaultAndExecCommand(e, 'selectAll');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { localize } from 'vs/nls';
|
|||||||
import * as notebookUtils from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
import * as notebookUtils from 'sql/workbench/services/notebook/browser/models/notebookUtils';
|
||||||
import { CellTypes, CellType, NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts';
|
import { CellTypes, CellType, NotebookChangeType } from 'sql/workbench/services/notebook/common/contracts';
|
||||||
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
import { NotebookModel } from 'sql/workbench/services/notebook/browser/models/notebookModel';
|
||||||
import { ICellModel, IOutputChangedEvent, CellExecutionState, ICellModelOptions, ITableUpdatedEvent } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
import { ICellModel, IOutputChangedEvent, CellExecutionState, ICellModelOptions, ITableUpdatedEvent, CellEditModes } from 'sql/workbench/services/notebook/browser/models/modelInterfaces';
|
||||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||||
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
|
||||||
@@ -878,6 +878,19 @@ export class CellModel extends Disposable implements ICellModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get currentMode(): CellEditModes {
|
||||||
|
if (this._cellType === CellTypes.Code) {
|
||||||
|
return CellEditModes.CODE;
|
||||||
|
}
|
||||||
|
if (this._showMarkdown && this._showPreview) {
|
||||||
|
return CellEditModes.SPLIT;
|
||||||
|
} else if (this._showMarkdown && !this._showPreview) {
|
||||||
|
return CellEditModes.MARKDOWN;
|
||||||
|
}
|
||||||
|
// defaulting to WYSIWYG
|
||||||
|
return CellEditModes.WYSIWYG;
|
||||||
|
}
|
||||||
|
|
||||||
private setLanguageFromContents(cell: nb.ICellContents): void {
|
private setLanguageFromContents(cell: nb.ICellContents): void {
|
||||||
if (cell.cell_type === CellTypes.Markdown) {
|
if (cell.cell_type === CellTypes.Markdown) {
|
||||||
this._language = 'markdown';
|
this._language = 'markdown';
|
||||||
|
|||||||
@@ -530,6 +530,7 @@ export interface ICellModel {
|
|||||||
sendChangeToNotebook(change: NotebookChangeType): void;
|
sendChangeToNotebook(change: NotebookChangeType): void;
|
||||||
cellSourceChanged: boolean;
|
cellSourceChanged: boolean;
|
||||||
readonly savedConnectionName: string | undefined;
|
readonly savedConnectionName: string | undefined;
|
||||||
|
readonly currentMode: CellEditModes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IModelFactory {
|
export interface IModelFactory {
|
||||||
@@ -585,3 +586,10 @@ export interface INotebookContentsEditable {
|
|||||||
nbformat: number;
|
nbformat: number;
|
||||||
nbformat_minor: number;
|
nbformat_minor: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum CellEditModes {
|
||||||
|
'CODE',
|
||||||
|
'MARKDOWN',
|
||||||
|
'SPLIT',
|
||||||
|
'WYSIWYG'
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user