markdown -> markup

Our api supports the concept of generic markup cell however our implementation currently only supports markdown. Rename functions to prepare to support markup
This commit is contained in:
Matt Bierner 2021-06-10 19:49:08 -07:00
parent 0dcfa4d964
commit 4bc877935e
No known key found for this signature in database
GPG key ID: 099C331567E11888
7 changed files with 70 additions and 71 deletions

View file

@ -42,7 +42,7 @@ class NotebookViewportContribution extends Disposable implements INotebookEditor
const cell = this._notebookEditor.viewModel?.viewCells[index];
if (cell?.cellKind === CellKind.Markup && cell?.getEditState() === CellEditState.Preview && !cell.metadata.inputCollapsed) {
this._notebookEditor.createMarkdownPreview(cell);
this._notebookEditor.createMarkupPreview(cell);
} else if (cell?.cellKind === CellKind.Code) {
const viewCell = (cell as CodeCellViewModel);
const outputs = viewCell.outputsViewModels;

View file

@ -140,19 +140,19 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
}
}
setMarkdownCellEditState(cellId: string, editState: CellEditState): void {
setMarkupCellEditState(cellId: string, editState: CellEditState): void {
// throw new Error('Method not implemented.');
}
markdownCellDragStart(cellId: string, event: { dragOffsetY: number; }): void {
didStartDragMarkupCell(cellId: string, event: { dragOffsetY: number; }): void {
// throw new Error('Method not implemented.');
}
markdownCellDrag(cellId: string, event: { dragOffsetY: number; }): void {
didDragMarkupCell(cellId: string, event: { dragOffsetY: number; }): void {
// throw new Error('Method not implemented.');
}
markdownCellDragEnd(cellId: string): void {
didEndDragMarkupCell(cellId: string): void {
// throw new Error('Method not implemented.');
}
markdownCellDrop(cellId: string) {
didDropMarkupCell(cellId: string) {
// throw new Error('Method not implemented.');
}
@ -679,7 +679,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
});
}
updateMarkdownCellHeight() {
updateMarkupCellHeight() {
// TODO
}

View file

@ -181,12 +181,12 @@ export interface ICommonNotebookEditor {
focusNextNotebookCell(cell: IGenericCellViewModel, focus: 'editor' | 'container' | 'output'): void;
updateOutputHeight(cellInfo: ICommonCellInfo, output: IDisplayOutputViewModel, height: number, isInit: boolean, source?: string): void;
scheduleOutputHeightAck(cellInfo: ICommonCellInfo, outputId: string, height: number): void;
updateMarkdownCellHeight(cellId: string, height: number, isInit: boolean): void;
setMarkdownCellEditState(cellId: string, editState: CellEditState): void;
markdownCellDragStart(cellId: string, event: { dragOffsetY: number }): void;
markdownCellDrag(cellId: string, event: { dragOffsetY: number }): void;
markdownCellDrop(cellId: string, event: { dragOffsetY: number, ctrlKey: boolean, altKey: boolean }): void;
markdownCellDragEnd(cellId: string): void;
updateMarkupCellHeight(cellId: string, height: number, isInit: boolean): void;
setMarkupCellEditState(cellId: string, editState: CellEditState): void;
didStartDragMarkupCell(cellId: string, event: { dragOffsetY: number }): void;
didDragMarkupCell(cellId: string, event: { dragOffsetY: number }): void;
didDropMarkupCell(cellId: string, event: { dragOffsetY: number, ctrlKey: boolean, altKey: boolean }): void;
didEndDragMarkupCell(cellId: string): void;
}
//#endregion
@ -478,9 +478,9 @@ export interface INotebookEditor extends ICommonNotebookEditor {
*/
layoutNotebookCell(cell: ICellViewModel, height: number): Promise<void>;
createMarkdownPreview(cell: ICellViewModel): Promise<void>;
unhideMarkdownPreviews(cells: readonly ICellViewModel[]): Promise<void>;
hideMarkdownPreviews(cells: readonly ICellViewModel[]): Promise<void>;
createMarkupPreview(cell: ICellViewModel): Promise<void>;
unhideMarkupPreviews(cells: readonly ICellViewModel[]): Promise<void>;
hideMarkupPreviews(cells: readonly ICellViewModel[]): Promise<void>;
/**
* Render the output in webview layer
@ -794,14 +794,13 @@ export enum CellRevealPosition {
export enum CellEditState {
/**
* Default state.
* For markdown cell, it's Markdown preview.
* For markup cells, this is the renderer version of the markup.
* For code cell, the browser focus should be on the container instead of the editor
*/
Preview,
/**
* Eding mode. Source for markdown or code is rendered in editors and the state will be persistent.
* Editing mode. Source for markup or code is rendered in editors and the state will be persistent.
*/
Editing
}

View file

@ -1258,8 +1258,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}
}
this.hideMarkdownPreviews(hiddenCells);
this.deleteMarkdownPreviews(deletedCells);
this.hideMarkupPreviews(hiddenCells);
this.deleteMarkupPreviews(deletedCells);
}));
// init rendering
@ -1322,7 +1322,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
if (cell.cellKind === CellKind.Markup) {
store.add((cell as MarkdownCellViewModel).onDidHideInput(() => {
this.hideMarkdownPreviews([(cell as MarkdownCellViewModel)]);
this.hideMarkupPreviews([(cell as MarkdownCellViewModel)]);
}));
}
@ -2251,7 +2251,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
};
}
async createMarkdownPreview(cell: MarkdownCellViewModel) {
async createMarkupPreview(cell: MarkdownCellViewModel) {
if (!this.useRenderer) {
// TODO: handle case where custom renderer is disabled?
return;
@ -2270,7 +2270,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}
const cellTop = this._list.getAbsoluteTopOfElement(cell);
await this._webview.showMarkdownPreview({
await this._webview.showMarkupPreview({
mime: cell.mime,
cellHandle: cell.handle,
cellId: cell.id,
@ -2280,7 +2280,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
});
}
async unhideMarkdownPreviews(cells: readonly MarkdownCellViewModel[]) {
async unhideMarkupPreviews(cells: readonly MarkdownCellViewModel[]) {
if (!this.useRenderer) {
// TODO: handle case where custom renderer is disabled?
return;
@ -2294,10 +2294,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
await this._resolveWebview();
}
await this._webview?.unhideMarkdownPreviews(cells.map(cell => cell.id));
await this._webview?.unhideMarkupPreviews(cells.map(cell => cell.id));
}
async hideMarkdownPreviews(cells: readonly MarkdownCellViewModel[]) {
async hideMarkupPreviews(cells: readonly MarkdownCellViewModel[]) {
if (!this.useRenderer) {
// TODO: handle case where custom renderer is disabled?
return;
@ -2311,10 +2311,10 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
await this._resolveWebview();
}
await this._webview?.hideMarkdownPreviews(cells.map(cell => cell.id));
await this._webview?.hideMarkupPreviews(cells.map(cell => cell.id));
}
async deleteMarkdownPreviews(cells: readonly MarkdownCellViewModel[]) {
async deleteMarkupPreviews(cells: readonly MarkdownCellViewModel[]) {
if (!this.useRenderer) {
// TODO: handle case where custom renderer is disabled?
return;
@ -2328,7 +2328,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
await this._resolveWebview();
}
await this._webview?.deleteMarkdownPreviews(cells.map(cell => cell.id));
await this._webview?.deleteMarkupPreviews(cells.map(cell => cell.id));
}
private async updateSelectedMarkdownPreviews(): Promise<void> {
@ -2343,7 +2343,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const selectedCells = this.getSelectionViewModels().map(cell => cell.id);
// Only show selection when there is more than 1 cell selected
await this._webview?.updateMarkdownPreviewSelections(selectedCells.length > 1 ? selectedCells : []);
await this._webview?.updateMarkupPreviewSelections(selectedCells.length > 1 ? selectedCells : []);
}
async createOutput(cell: CodeCellViewModel, output: IInsetRenderOutput, offset: number): Promise<void> {
@ -2488,7 +2488,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
this._webview.removeInsets(removedItems);
const markdownUpdateItems: { id: string, top: number; }[] = [];
for (const cellId of this._webview.markdownPreviewMapping.keys()) {
for (const cellId of this._webview.markupPreviewMapping.keys()) {
const cell = this.viewModel?.viewCells.find(cell => cell.id === cellId);
if (cell) {
const cellTop = this._list.getAbsoluteTopOfElement(cell);
@ -2520,7 +2520,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}
}
updateMarkdownCellHeight(cellId: string, height: number, isInit: boolean) {
updateMarkupCellHeight(cellId: string, height: number, isInit: boolean) {
const cell = this.getCellById(cellId);
if (cell && cell instanceof MarkdownCellViewModel) {
const { bottomToolbarGap } = this._notebookOptions.computeBottomToolbarDimensions(this.viewModel?.viewType);
@ -2529,35 +2529,35 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}
}
setMarkdownCellEditState(cellId: string, editState: CellEditState): void {
setMarkupCellEditState(cellId: string, editState: CellEditState): void {
const cell = this.getCellById(cellId);
if (cell instanceof MarkdownCellViewModel) {
cell.updateEditState(editState, 'setMarkdownCellEditState');
}
}
markdownCellDragStart(cellId: string, event: { dragOffsetY: number; }): void {
didStartDragMarkupCell(cellId: string, event: { dragOffsetY: number; }): void {
const cell = this.getCellById(cellId);
if (cell instanceof MarkdownCellViewModel) {
this._dndController?.startExplicitDrag(cell, event.dragOffsetY);
}
}
markdownCellDrag(cellId: string, event: { dragOffsetY: number; }): void {
didDragMarkupCell(cellId: string, event: { dragOffsetY: number; }): void {
const cell = this.getCellById(cellId);
if (cell instanceof MarkdownCellViewModel) {
this._dndController?.explicitDrag(cell, event.dragOffsetY);
}
}
markdownCellDrop(cellId: string, event: { dragOffsetY: number, ctrlKey: boolean, altKey: boolean; }): void {
didDropMarkupCell(cellId: string, event: { dragOffsetY: number, ctrlKey: boolean, altKey: boolean; }): void {
const cell = this.getCellById(cellId);
if (cell instanceof MarkdownCellViewModel) {
this._dndController?.explicitDrop(cell, event);
}
}
markdownCellDragEnd(cellId: string): void {
didEndDragMarkupCell(cellId: string): void {
const cell = this.getCellById(cellId);
if (cell instanceof MarkdownCellViewModel) {
this._dndController?.endExplicitDrag(cell);

View file

@ -64,7 +64,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Disposable {
element: HTMLElement;
webview: WebviewElement | undefined = undefined;
insetMapping: Map<IDisplayOutputViewModel, ICachedInset<T>> = new Map();
readonly markdownPreviewMapping = new Map<string, IMarkupCellInitialization>();
readonly markupPreviewMapping = new Map<string, IMarkupCellInitialization>();
hiddenInsetMapping: Set<IDisplayOutputViewModel> = new Set();
reversedInsetMapping: Map<string, IDisplayOutputViewModel> = new Map();
localResourceRootsCache: URI[] | undefined = undefined;
@ -456,7 +456,7 @@ var requirejs = (function() {
this.notebookEditor.scheduleOutputHeightAck(cellInfo, update.id, height);
}
} else {
this.notebookEditor.updateMarkdownCellHeight(update.id, height, !!update.init);
this.notebookEditor.updateMarkupCellHeight(update.id, height, !!update.init);
}
}
break;
@ -591,7 +591,7 @@ var requirejs = (function() {
{
const cell = this.notebookEditor.getCellById(data.cellId);
if (cell) {
this.notebookEditor.setMarkdownCellEditState(data.cellId, CellEditState.Editing);
this.notebookEditor.setMarkupCellEditState(data.cellId, CellEditState.Editing);
this.notebookEditor.focusNotebookCell(cell, 'editor', { skipReveal: true });
}
break;
@ -614,17 +614,17 @@ var requirejs = (function() {
}
case 'cell-drag-start':
{
this.notebookEditor.markdownCellDragStart(data.cellId, data);
this.notebookEditor.didStartDragMarkupCell(data.cellId, data);
break;
}
case 'cell-drag':
{
this.notebookEditor.markdownCellDrag(data.cellId, data);
this.notebookEditor.didDragMarkupCell(data.cellId, data);
break;
}
case 'cell-drop':
{
this.notebookEditor.markdownCellDrop(data.cellId, {
this.notebookEditor.didDropMarkupCell(data.cellId, {
dragOffsetY: data.dragOffsetY,
ctrlKey: data.ctrlKey,
altKey: data.altKey,
@ -633,7 +633,7 @@ var requirejs = (function() {
}
case 'cell-drag-end':
{
this.notebookEditor.markdownCellDragEnd(data.cellId);
this.notebookEditor.didEndDragMarkupCell(data.cellId);
break;
}
@ -743,8 +743,8 @@ var requirejs = (function() {
this._sendMessageToWebview({ ...inset.cachedCreation, initiallyHidden: this.hiddenInsetMapping.has(output) });
}
const mdCells = [...this.markdownPreviewMapping.values()];
this.markdownPreviewMapping.clear();
const mdCells = [...this.markupPreviewMapping.values()];
this.markupPreviewMapping.clear();
this.initializeMarkup(mdCells);
this._updateStyles();
this._updateOptions();
@ -782,7 +782,7 @@ var requirejs = (function() {
});
}
updateScrollTops(outputRequests: IDisplayOutputLayoutUpdateRequest[], markdownPreviews: { id: string, top: number }[]) {
updateScrollTops(outputRequests: IDisplayOutputLayoutUpdateRequest[], markupPreviews: { id: string, top: number }[]) {
if (this._disposed) {
return;
}
@ -811,42 +811,42 @@ var requirejs = (function() {
};
}));
if (!widgets.length && !markdownPreviews.length) {
if (!widgets.length && !markupPreviews.length) {
return;
}
this._sendMessageToWebview({
type: 'view-scroll',
widgets: widgets,
markupCells: markdownPreviews,
markupCells: markupPreviews,
});
}
private async createMarkdownPreview(initialization: IMarkupCellInitialization) {
private async createMarkupPreview(initialization: IMarkupCellInitialization) {
if (this._disposed) {
return;
}
if (this.markdownPreviewMapping.has(initialization.cellId)) {
console.error('Trying to create markdown preview that already exists');
if (this.markupPreviewMapping.has(initialization.cellId)) {
console.error('Trying to create markup preview that already exists');
return;
}
this.markdownPreviewMapping.set(initialization.cellId, initialization);
this.markupPreviewMapping.set(initialization.cellId, initialization);
this._sendMessageToWebview({
type: 'createMarkupCell',
cell: initialization
});
}
async showMarkdownPreview(initialization: IMarkupCellInitialization) {
async showMarkupPreview(initialization: IMarkupCellInitialization) {
if (this._disposed) {
return;
}
const entry = this.markdownPreviewMapping.get(initialization.cellId);
const entry = this.markupPreviewMapping.get(initialization.cellId);
if (!entry) {
return this.createMarkdownPreview(initialization);
return this.createMarkupPreview(initialization);
}
const sameContent = initialization.content === entry.content;
@ -867,14 +867,14 @@ var requirejs = (function() {
entry.visible = true;
}
async hideMarkdownPreviews(cellIds: readonly string[]) {
async hideMarkupPreviews(cellIds: readonly string[]) {
if (this._disposed) {
return;
}
const cellsToHide: string[] = [];
for (const cellId of cellIds) {
const entry = this.markdownPreviewMapping.get(cellId);
const entry = this.markupPreviewMapping.get(cellId);
if (entry) {
if (entry.visible) {
cellsToHide.push(cellId);
@ -891,14 +891,14 @@ var requirejs = (function() {
}
}
async unhideMarkdownPreviews(cellIds: readonly string[]) {
async unhideMarkupPreviews(cellIds: readonly string[]) {
if (this._disposed) {
return;
}
const toUnhide: string[] = [];
for (const cellId of cellIds) {
const entry = this.markdownPreviewMapping.get(cellId);
const entry = this.markupPreviewMapping.get(cellId);
if (entry) {
if (!entry.visible) {
entry.visible = true;
@ -915,16 +915,16 @@ var requirejs = (function() {
});
}
async deleteMarkdownPreviews(cellIds: readonly string[]) {
async deleteMarkupPreviews(cellIds: readonly string[]) {
if (this._disposed) {
return;
}
for (const id of cellIds) {
if (!this.markdownPreviewMapping.has(id)) {
if (!this.markupPreviewMapping.has(id)) {
console.error(`Trying to delete a preview that does not exist: ${id}`);
}
this.markdownPreviewMapping.delete(id);
this.markupPreviewMapping.delete(id);
}
if (cellIds.length) {
@ -935,14 +935,14 @@ var requirejs = (function() {
}
}
async updateMarkdownPreviewSelections(selectedCellsIds: string[]) {
async updateMarkupPreviewSelections(selectedCellsIds: string[]) {
if (this._disposed) {
return;
}
this._sendMessageToWebview({
type: 'updateSelectedMarkupCells',
selectedCellIds: selectedCellsIds.filter(id => this.markdownPreviewMapping.has(id)),
selectedCellIds: selectedCellsIds.filter(id => this.markupPreviewMapping.has(id)),
});
}
@ -961,7 +961,7 @@ var requirejs = (function() {
});
for (const cell of cells) {
this.markdownPreviewMapping.set(cell.cellId, { ...cell, visible: false });
this.markupPreviewMapping.set(cell.cellId, { ...cell, visible: false });
}
this._sendMessageToWebview({

View file

@ -532,9 +532,9 @@ export class MarkdownCellRenderer extends AbstractCellRenderer implements IListR
private updateCollapsedState(element: MarkdownCellViewModel) {
if (element.metadata.inputCollapsed) {
this.notebookEditor.hideMarkdownPreviews([element]);
this.notebookEditor.hideMarkupPreviews([element]);
} else {
this.notebookEditor.unhideMarkdownPreviews([element]);
this.notebookEditor.unhideMarkupPreviews([element]);
}
}

View file

@ -35,7 +35,7 @@ class WebviewMarkdownRenderer extends Disposable implements IMarkdownRenderStrat
}
update(): void {
this.notebookEditor.createMarkdownPreview(this.viewCell);
this.notebookEditor.createMarkupPreview(this.viewCell);
}
}
@ -282,7 +282,7 @@ export class StatefulMarkdownCell extends Disposable {
DOM.hide(this.templateData.collapsedPart);
if (this.useRenderer) {
this.notebookEditor.hideMarkdownPreviews([this.viewCell]);
this.notebookEditor.hideMarkupPreviews([this.viewCell]);
}
this.templateData.container.classList.toggle('collapsed', false);