3147: Notebook markdown cell should be opened in preview mode (#3168)

* 3147: Notebook markdown cell should be opened in preview mode

* 3147: Default ability to double click a cell to add text

* Misc changes

* CSS cleanup

* Localization stuff

* Remove constants file in Notebook codebase
This commit is contained in:
Raj
2018-11-09 10:38:14 -08:00
committed by GitHub
parent 7508192ab9
commit a2bbf3f44e
2 changed files with 21 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ import * as themeColors from 'vs/workbench/common/theme';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { ICellModel } from 'sql/parts/notebook/models/modelInterfaces';
import { ISanitizer, defaultSanitizer } from 'sql/parts/notebook/outputs/sanitizer';
import { localize } from 'vs/nls';
export const TEXT_SELECTOR: string = 'text-cell-component';
@@ -35,7 +36,7 @@ export class TextCellComponent extends CellView implements OnInit {
@Inject(ICommandService) private _commandService: ICommandService
) {
super();
this.isEditMode = true;
this.isEditMode = false;
}
ngOnChanges() {
@@ -50,14 +51,23 @@ export class TextCellComponent extends CellView implements OnInit {
return this._sanitizer = defaultSanitizer;
}
/**
* Updates the preview of markdown component with latest changes
* If content is empty and in non-edit mode, default it to 'Double-click to edit'
* Sanitizes the data to be shown in markdown cell
*/
private updatePreview() {
if (this.cellModel.source && this._content !== this.cellModel.source) {
this._content = this.sanitizeContent(this.cellModel.source);
// todo: pass in the notebook filename instead of undefined value
this._commandService.executeCommand<string>('notebook.showPreview', undefined, this._content).then((htmlcontent) => {
let outputElement = <HTMLElement>this.output.nativeElement;
outputElement.innerHTML = htmlcontent;
});
if (this._content !== this.cellModel.source) {
if (!this.cellModel.source && !this.isEditMode) {
(<HTMLElement>this.output.nativeElement).innerHTML = localize('doubleClickEdit', 'Double-click to edit');
} else {
this._content = this.sanitizeContent(this.cellModel.source);
// todo: pass in the notebook filename instead of undefined value
this._commandService.executeCommand<string>('notebook.showPreview', undefined, this._content).then((htmlcontent) => {
let outputElement = <HTMLElement>this.output.nativeElement;
outputElement.innerHTML = htmlcontent;
});
}
}
}
@@ -70,6 +80,7 @@ export class TextCellComponent extends CellView implements OnInit {
}
ngOnInit() {
this.updatePreview();
this._register(this.themeService.onDidColorThemeChange(this.updateTheme, this));
this.updateTheme(this.themeService.getColorTheme());
}
@@ -89,6 +100,7 @@ export class TextCellComponent extends CellView implements OnInit {
public toggleEditMode(): void {
this.isEditMode = !this.isEditMode;
this.updatePreview();
this._changeRef.detectChanges();
}
}

View File

@@ -11,4 +11,4 @@ text-cell-component .notebook-preview {
border-top-width: 1px;
border-top-style: solid;
user-select: initial;
}
}