mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Enable double click edit (#12200)
* fix to working version * add comment documentation * minor changes based on review * resolve comments * remnove unnecessary assignment
This commit is contained in:
@@ -107,4 +107,8 @@ export class CellToolbarComponent {
|
|||||||
|
|
||||||
this._actionBar.setContent(taskbarContent);
|
this._actionBar.setContent(taskbarContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getEditCellAction(): EditCellAction {
|
||||||
|
return this._editCellAction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
this._model.updateActiveCell(undefined);
|
this._model.updateActiveCell(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Double click to edit text cell in notebook
|
||||||
|
@HostListener('dblclick', ['$event']) onDblClick() {
|
||||||
|
this.enableActiveCellEditOnDoubleClick();
|
||||||
|
}
|
||||||
|
|
||||||
@HostListener('document:keydown.meta.a', ['$event'])
|
@HostListener('document:keydown.meta.a', ['$event'])
|
||||||
onkeydown(e) {
|
onkeydown(e) {
|
||||||
// use preventDefault() to avoid invoking the editor's select all
|
// use preventDefault() to avoid invoking the editor's select all
|
||||||
@@ -78,6 +83,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
private markdownRenderer: NotebookMarkdownRenderer;
|
private markdownRenderer: NotebookMarkdownRenderer;
|
||||||
private markdownResult: IMarkdownRenderResult;
|
private markdownResult: IMarkdownRenderResult;
|
||||||
public previewFeaturesEnabled: boolean = false;
|
public previewFeaturesEnabled: boolean = false;
|
||||||
|
public doubleClickEditEnabled: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
|
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
|
||||||
@@ -97,6 +103,9 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
||||||
this.previewFeaturesEnabled = this._configurationService.getValue('workbench.enablePreviewFeatures');
|
this.previewFeaturesEnabled = this._configurationService.getValue('workbench.enablePreviewFeatures');
|
||||||
}));
|
}));
|
||||||
|
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
||||||
|
this.doubleClickEditEnabled = this._configurationService.getValue('notebook.enableDoubleClickEdit');
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public get cellEditors(): ICellEditorProvider[] {
|
public get cellEditors(): ICellEditorProvider[] {
|
||||||
@@ -176,7 +185,7 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the preview of markdown component with latest changes
|
* Updates the preview of markdown component with latest changes
|
||||||
* If content is empty and in non-edit mode, default it to 'Add content here...'
|
* If content is empty and in non-edit mode, default it to 'Add content here...' or 'Double-click to edit' depending on setting
|
||||||
* Sanitizes the data to be shown in markdown cell
|
* Sanitizes the data to be shown in markdown cell
|
||||||
*/
|
*/
|
||||||
private updatePreview(): void {
|
private updatePreview(): void {
|
||||||
@@ -187,7 +196,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
if (trustedChanged || contentChanged) {
|
if (trustedChanged || contentChanged) {
|
||||||
this._lastTrustedMode = this.cellModel.trustedMode;
|
this._lastTrustedMode = this.cellModel.trustedMode;
|
||||||
if ((!cellModelSourceJoined) && !this.isEditMode) {
|
if ((!cellModelSourceJoined) && !this.isEditMode) {
|
||||||
|
if (this.doubleClickEditEnabled) {
|
||||||
|
this._content = localize('doubleClickEdit', "Double-click to edit");
|
||||||
|
} else {
|
||||||
this._content = localize('addContent', "Add content here...");
|
this._content = localize('addContent', "Add content here...");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this._content = this.cellModel.source;
|
this._content = this.cellModel.source;
|
||||||
}
|
}
|
||||||
@@ -350,4 +363,13 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
|||||||
});
|
});
|
||||||
return textOutput;
|
return textOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enables edit mode on double clicking active cell
|
||||||
|
private enableActiveCellEditOnDoubleClick() {
|
||||||
|
if (!this.isEditMode && this.doubleClickEditEnabled) {
|
||||||
|
this.toggleEditMode(true);
|
||||||
|
}
|
||||||
|
this.cellModel.active = true;
|
||||||
|
this._model.updateActiveCell(this.cellModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<cell-toolbar-component *ngIf="cell.active" [cellModel]="cell" [model]="model"></cell-toolbar-component>
|
<cell-toolbar-component *ngIf="cell.active" [cellModel]="cell" [model]="model"></cell-toolbar-component>
|
||||||
<code-cell-component *ngIf="cell.cellType === 'code'" [cellModel]="cell" [model]="model" [activeCellId]="activeCellId">
|
<code-cell-component *ngIf="cell.cellType === 'code'" [cellModel]="cell" [model]="model" [activeCellId]="activeCellId">
|
||||||
</code-cell-component>
|
</code-cell-component>
|
||||||
<text-cell-component *ngIf="cell.cellType === 'markdown'" [cellModel]="cell" [model]="model" [activeCellId]="activeCellId">
|
<text-cell-component *ngIf="cell.cellType === 'markdown'" [cellModel]="cell" [model]="model" [activeCellId]="activeCellId" (dblclick)="enableActiveCellIconOnDoubleClick()">
|
||||||
</text-cell-component>
|
</text-cell-component>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ import { NotebookInput } from 'sql/workbench/contrib/notebook/browser/models/not
|
|||||||
import { IColorTheme } from 'vs/platform/theme/common/themeService';
|
import { IColorTheme } from 'vs/platform/theme/common/themeService';
|
||||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||||
|
import { CellToolbarComponent } from 'sql/workbench/contrib/notebook/browser/cellViews/cellToolbar.component';
|
||||||
|
|
||||||
export const NOTEBOOK_SELECTOR: string = 'notebook-component';
|
export const NOTEBOOK_SELECTOR: string = 'notebook-component';
|
||||||
|
|
||||||
@@ -71,6 +72,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
|
|
||||||
@ViewChildren(CodeCellComponent) private codeCells: QueryList<CodeCellComponent>;
|
@ViewChildren(CodeCellComponent) private codeCells: QueryList<CodeCellComponent>;
|
||||||
@ViewChildren(TextCellComponent) private textCells: QueryList<TextCellComponent>;
|
@ViewChildren(TextCellComponent) private textCells: QueryList<TextCellComponent>;
|
||||||
|
@ViewChildren(CellToolbarComponent) private cellToolbar: QueryList<CellToolbarComponent>;
|
||||||
|
|
||||||
private _model: NotebookModel;
|
private _model: NotebookModel;
|
||||||
protected _actionBar: Taskbar;
|
protected _actionBar: Taskbar;
|
||||||
@@ -85,6 +87,7 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
private _navProvider: INavigationProvider;
|
private _navProvider: INavigationProvider;
|
||||||
private navigationResult: nb.NavigationResult;
|
private navigationResult: nb.NavigationResult;
|
||||||
public previewFeaturesEnabled: boolean = false;
|
public previewFeaturesEnabled: boolean = false;
|
||||||
|
public doubleClickEditEnabled: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
|
@Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef,
|
||||||
@@ -113,6 +116,9 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
||||||
this.previewFeaturesEnabled = this._configurationService.getValue('workbench.enablePreviewFeatures');
|
this.previewFeaturesEnabled = this._configurationService.getValue('workbench.enablePreviewFeatures');
|
||||||
}));
|
}));
|
||||||
|
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
||||||
|
this.doubleClickEditEnabled = this._configurationService.getValue('notebook.enableDoubleClickEdit');
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateProfile(): void {
|
private updateProfile(): void {
|
||||||
@@ -203,6 +209,18 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
|||||||
this.detectChanges();
|
this.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handles double click to edit icon change
|
||||||
|
// See textcell.component.ts for changing edit behavior
|
||||||
|
public enableActiveCellIconOnDoubleClick() {
|
||||||
|
if (this.doubleClickEditEnabled) {
|
||||||
|
const toolbarComponent = (<CellToolbarComponent>this.cellToolbar.first);
|
||||||
|
const toolbarEditCellAction = toolbarComponent.getEditCellAction();
|
||||||
|
if (!toolbarEditCellAction.editMode) {
|
||||||
|
toolbarEditCellAction.editMode = !toolbarEditCellAction.editMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add cell based on cell type
|
// Add cell based on cell type
|
||||||
public addCell(cellType: CellType, index?: number, event?: Event) {
|
public addCell(cellType: CellType, index?: number, event?: Event) {
|
||||||
if (event) {
|
if (event) {
|
||||||
|
|||||||
@@ -220,6 +220,11 @@ configurationRegistry.registerConfiguration({
|
|||||||
'type': 'boolean',
|
'type': 'boolean',
|
||||||
'default': false,
|
'default': false,
|
||||||
'description': localize('notebook.allowADSCommands', "Allow notebooks to run Azure Data Studio commands.")
|
'description': localize('notebook.allowADSCommands', "Allow notebooks to run Azure Data Studio commands.")
|
||||||
|
},
|
||||||
|
'notebook.enableDoubleClickEdit': {
|
||||||
|
'type': 'boolean',
|
||||||
|
'default': true,
|
||||||
|
'description': localize('notebook.enableDoubleClickEdit', "Enable double click to edit for text cells in notebooks")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user