未验证 提交 ffd533aa 编写于 作者: J Jackson Kearl 提交者: GitHub

Remove unnecessary model creation in walkthrough pages (#108226)

上级 8907220c
......@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
import { WalkThroughInput } from 'vs/workbench/contrib/welcome/walkThrough/browser/walkThroughInput';
import { WalkThroughPart } from 'vs/workbench/contrib/welcome/walkThrough/browser/walkThroughPart';
import { WalkThroughArrowUp, WalkThroughArrowDown, WalkThroughPageUp, WalkThroughPageDown } from 'vs/workbench/contrib/welcome/walkThrough/browser/walkThroughActions';
import { WalkThroughContentProvider, WalkThroughSnippetContentProvider } from 'vs/workbench/contrib/welcome/walkThrough/common/walkThroughContentProvider';
import { WalkThroughSnippetContentProvider } from 'vs/workbench/contrib/welcome/walkThrough/common/walkThroughContentProvider';
import { EditorWalkThroughAction, EditorWalkThroughInputFactory } from 'vs/workbench/contrib/welcome/walkThrough/browser/editor/editorWalkThrough';
import { Registry } from 'vs/platform/registry/common/platform';
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
......@@ -34,9 +34,6 @@ Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions)
Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).registerEditorInputFactory(EditorWalkThroughInputFactory.ID, EditorWalkThroughInputFactory);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(WalkThroughContentProvider, LifecyclePhase.Starting);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench)
.registerWorkbenchContribution(WalkThroughSnippetContentProvider, LifecyclePhase.Starting);
......
......@@ -10,19 +10,19 @@ import { ITextModelService } from 'vs/editor/common/services/resolverService';
import * as marked from 'vs/base/common/marked/marked';
import { Schemas } from 'vs/base/common/network';
import { isEqual } from 'vs/base/common/resources';
import { EndOfLinePreference } from 'vs/editor/common/model';
import { requireToContent } from 'vs/workbench/contrib/welcome/walkThrough/common/walkThroughContentProvider';
export class WalkThroughModel extends EditorModel {
constructor(
private mainRef: IReference<ITextEditorModel>,
private mainRef: string,
private snippetRefs: IReference<ITextEditorModel>[]
) {
super();
}
get main() {
return this.mainRef.object;
return this.mainRef;
}
get snippets() {
......@@ -31,7 +31,6 @@ export class WalkThroughModel extends EditorModel {
dispose() {
this.snippetRefs.forEach(ref => ref.dispose());
this.mainRef.dispose();
super.dispose();
}
}
......@@ -94,10 +93,10 @@ export class WalkThroughInput extends EditorInput {
resolve(): Promise<WalkThroughModel> {
if (!this.promise) {
this.promise = this.textModelResolverService.createModelReference(this.options.resource)
.then(ref => {
this.promise = requireToContent(this.options.resource)
.then(content => {
if (this.resource.path.endsWith('.html')) {
return new WalkThroughModel(ref, []);
return new WalkThroughModel(content, []);
}
const snippets: Promise<IReference<ITextEditorModel>>[] = [];
......@@ -109,11 +108,10 @@ export class WalkThroughInput extends EditorInput {
return '';
};
const markdown = ref.object.textEditorModel.getValue(EndOfLinePreference.LF);
marked(markdown, { renderer });
marked(content, { renderer });
return Promise.all(snippets)
.then(refs => new WalkThroughModel(ref, refs));
.then(refs => new WalkThroughModel(content, refs));
});
}
......
......@@ -39,7 +39,6 @@ import { Dimension, size } from 'vs/base/browser/dom';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { CancellationToken } from 'vs/base/common/cancellation';
import { domEvent } from 'vs/base/browser/event';
import { EndOfLinePreference } from 'vs/editor/common/model';
export const WALK_THROUGH_FOCUS = new RawContextKey<boolean>('interactivePlaygroundFocus', false);
......@@ -279,7 +278,7 @@ export class WalkThroughPart extends EditorPane {
return;
}
const content = model.main.textEditorModel.getValue(EndOfLinePreference.LF);
const content = model.main;
if (!input.resource.path.endsWith('.md')) {
this.content.innerHTML = content;
this.updateSizeClasses();
......
......@@ -14,7 +14,7 @@ import { Schemas } from 'vs/base/common/network';
import { Range } from 'vs/editor/common/core/range';
import { createTextBufferFactory } from 'vs/editor/common/model/textModel';
function requireToContent(resource: URI): Promise<string> {
export function requireToContent(resource: URI): Promise<string> {
if (!resource.query) {
throw new Error('Welcome: invalid resource');
}
......@@ -37,30 +37,6 @@ function requireToContent(resource: URI): Promise<string> {
return content;
}
export class WalkThroughContentProvider implements ITextModelContentProvider, IWorkbenchContribution {
constructor(
@ITextModelService private readonly textModelResolverService: ITextModelService,
@IModeService private readonly modeService: IModeService,
@IModelService private readonly modelService: IModelService,
) {
this.textModelResolverService.registerTextModelContentProvider(Schemas.walkThrough, this);
}
public async provideTextContent(resource: URI): Promise<ITextModel> {
const content = await requireToContent(resource);
let codeEditorModel = this.modelService.getModel(resource);
if (!codeEditorModel) {
codeEditorModel = this.modelService.createModel(content, this.modeService.createByFilepathOrFirstLine(resource), resource);
} else {
this.modelService.updateModel(codeEditorModel, content);
}
return codeEditorModel;
}
}
export class WalkThroughSnippetContentProvider implements ITextModelContentProvider, IWorkbenchContribution {
constructor(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册