mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 01:25:38 -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);
|
||||
}
|
||||
|
||||
public getEditCellAction(): EditCellAction {
|
||||
return this._editCellAction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
this._model.updateActiveCell(undefined);
|
||||
}
|
||||
|
||||
// Double click to edit text cell in notebook
|
||||
@HostListener('dblclick', ['$event']) onDblClick() {
|
||||
this.enableActiveCellEditOnDoubleClick();
|
||||
}
|
||||
|
||||
@HostListener('document:keydown.meta.a', ['$event'])
|
||||
onkeydown(e) {
|
||||
// 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 markdownResult: IMarkdownRenderResult;
|
||||
public previewFeaturesEnabled: boolean = false;
|
||||
public doubleClickEditEnabled: boolean;
|
||||
|
||||
constructor(
|
||||
@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.previewFeaturesEnabled = this._configurationService.getValue('workbench.enablePreviewFeatures');
|
||||
}));
|
||||
this._register(this._configurationService.onDidChangeConfiguration(e => {
|
||||
this.doubleClickEditEnabled = this._configurationService.getValue('notebook.enableDoubleClickEdit');
|
||||
}));
|
||||
}
|
||||
|
||||
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
|
||||
* 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
|
||||
*/
|
||||
private updatePreview(): void {
|
||||
@@ -187,7 +196,11 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
if (trustedChanged || contentChanged) {
|
||||
this._lastTrustedMode = this.cellModel.trustedMode;
|
||||
if ((!cellModelSourceJoined) && !this.isEditMode) {
|
||||
this._content = localize('addContent', "Add content here...");
|
||||
if (this.doubleClickEditEnabled) {
|
||||
this._content = localize('doubleClickEdit', "Double-click to edit");
|
||||
} else {
|
||||
this._content = localize('addContent', "Add content here...");
|
||||
}
|
||||
} else {
|
||||
this._content = this.cellModel.source;
|
||||
}
|
||||
@@ -350,4 +363,13 @@ export class TextCellComponent extends CellView implements OnInit, OnChanges {
|
||||
});
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user