MarkdownCell -> MarkupCell

This commit is contained in:
Matt Bierner 2021-06-08 17:42:23 -07:00
parent 1cae09dd7e
commit 550c3ff481
No known key found for this signature in database
GPG key ID: 099C331567E11888
3 changed files with 14 additions and 10 deletions

View file

@ -1386,6 +1386,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
}
await this._webview!.initializeMarkup(requests.map(request => ({
mime: 'text/markdown',
cellId: request[0].id,
cellHandle: request[0].handle,
content: request[0].getText(),
@ -1393,7 +1394,9 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
visible: false,
})));
} else {
const initRequests = viewModel.viewCells.filter(cell => cell.cellKind === CellKind.Markup).slice(0, 5).map(cell => ({ cellId: cell.id, cellHandle: cell.handle, content: cell.getText(), offset: -10000, visible: false }));
const initRequests = viewModel.viewCells.filter(cell => cell.cellKind === CellKind.Markup).slice(0, 5).map(cell => ({
cellId: cell.id, cellHandle: cell.handle, content: cell.getText(), offset: -10000, visible: false, mime: 'text/markdown',
}));
await this._webview!.initializeMarkup(initRequests);
// no cached view state so we are rendering the first viewport
@ -2261,6 +2264,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditor
const cellTop = this._list.getAbsoluteTopOfElement(cell);
await this._webview.showMarkdownPreview({
mime: 'text/markdown',
cellHandle: cell.handle,
cellId: cell.id,
content: cell.getText(),

View file

@ -290,6 +290,7 @@ export interface IUpdateSelectedMarkupCellsMessage {
}
export interface IMarkupCellInitialization {
mime: string;
cellId: string;
cellHandle: number;
content: string;

View file

@ -1005,16 +1005,16 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
const notebookDocument = new class {
private readonly _markupCells = new Map<string, MarkdownCell>();
private readonly _markupCells = new Map<string, MarkupCell>();
private async createMarkupCell(init: webviewMessages.IMarkupCellInitialization, top: number): Promise<MarkdownCell> {
private async createMarkupCell(init: webviewMessages.IMarkupCellInitialization, top: number): Promise<MarkupCell> {
const existing = this._markupCells.get(init.cellId);
if (existing) {
console.error(`Trying to create markup that already exists: ${init.cellId}`);
return existing;
}
const markdownCell = new MarkdownCell(init.cellId, init.content, top);
const markdownCell = new MarkupCell(init.cellId, init.mime, init.content, top);
this._markupCells.set(init.cellId, markdownCell);
await markdownCell.ready;
@ -1061,7 +1061,7 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
cell?.unhide();
}
private getExpectedMarkupCell(id: string): MarkdownCell | undefined {
private getExpectedMarkupCell(id: string): MarkupCell | undefined {
const cell = this._markupCells.get(id);
if (!cell) {
console.log(`Could not find markup cell '${id}'`);
@ -1078,15 +1078,16 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
}
}();
class MarkdownCell implements IOutputItem {
class MarkupCell implements IOutputItem {
public readonly ready: Promise<void>;
/// Internal field that holds markdown text
private _content: string;
constructor(id: string, content: string, top: number) {
constructor(id: string, mime: string, content: string, top: number) {
this.id = id;
this.mime = mime;
this._content = content;
let resolveReady: () => void;
@ -1110,10 +1111,8 @@ async function webviewPreloads(style: PreloadStyles, options: PreloadOptions, re
}
//#region IOutputItem
public readonly mime = 'text/markdown';
public readonly id: string;
public readonly mime;
public readonly element: HTMLElement;
// deprecated fields