Skip to content

Commit

Permalink
Bring in relevant changes from ben/custom-text-editor
Browse files Browse the repository at this point in the history
Ref #89268
  • Loading branch information
Jackson Kearl committed Apr 6, 2020
1 parent a4f436b commit b2b3aee
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 42 deletions.
56 changes: 30 additions & 26 deletions src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ const enum ForceOpenAs {
Binary
}

/**
* A file editor input is the input type for the file editor of file system resources.
*/
export class FileEditorInput extends TextResourceEditorInput implements IFileEditorInput {
export abstract class BaseFileEditorInput extends TextResourceEditorInput implements IFileEditorInput {

private preferredEncoding: string | undefined;
private preferredMode: string | undefined;

private forceOpenAs: ForceOpenAs = ForceOpenAs.None;
protected forceOpenAs: ForceOpenAs = ForceOpenAs.None;

private model: ITextFileEditorModel | undefined = undefined;
private cachedTextFileModelReference: IReference<ITextFileEditorModel> | undefined = undefined;
Expand All @@ -46,7 +43,7 @@ export class FileEditorInput extends TextResourceEditorInput implements IFileEdi
resource: URI,
preferredEncoding: string | undefined,
preferredMode: string | undefined,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IInstantiationService protected readonly instantiationService: IInstantiationService,
@ITextFileService textFileService: ITextFileService,
@ITextModelService private readonly textModelResolverService: ITextModelService,
@ILabelService labelService: ILabelService,
Expand Down Expand Up @@ -162,10 +159,6 @@ export class FileEditorInput extends TextResourceEditorInput implements IFileEdi
this.forceOpenAs = ForceOpenAs.Binary;
}

getTypeId(): string {
return FILE_EDITOR_INPUT_ID;
}

getName(): string {
return this.decorateLabel(super.getName());
}
Expand Down Expand Up @@ -218,10 +211,6 @@ export class FileEditorInput extends TextResourceEditorInput implements IFileEdi
return super.isSaving();
}

getPreferredEditorId(candidates: string[]): string {
return this.forceOpenAs === ForceOpenAs.Binary ? BINARY_FILE_EDITOR_ID : TEXT_FILE_EDITOR_ID;
}

resolve(): Promise<ITextFileEditorModel | BinaryEditorModel> {

// Resolve as binary
Expand Down Expand Up @@ -301,18 +290,6 @@ export class FileEditorInput extends TextResourceEditorInput implements IFileEdi
return undefined;
}

matches(otherInput: unknown): boolean {
if (super.matches(otherInput) === true) {
return true;
}

if (otherInput) {
return otherInput instanceof FileEditorInput && otherInput.resource.toString() === this.resource.toString();
}

return false;
}

dispose(): void {

// Model
Expand All @@ -325,3 +302,30 @@ export class FileEditorInput extends TextResourceEditorInput implements IFileEdi
super.dispose();
}
}


/**
* A file editor input is the input type for the file editor of file system resources.
*/
export class FileEditorInput extends BaseFileEditorInput {

getTypeId(): string {
return FILE_EDITOR_INPUT_ID;
}

getPreferredEditorId(candidates: string[]): string {
return this.forceOpenAs === ForceOpenAs.Binary ? BINARY_FILE_EDITOR_ID : TEXT_FILE_EDITOR_ID;
}

matches(otherInput: unknown): boolean {
if (super.matches(otherInput) === true) {
return true;
}

if (otherInput) {
return otherInput instanceof FileEditorInput && otherInput.resource.toString() === this.resource.toString();
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
import { IFileService } from 'vs/platform/files/common/files';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';

/**
* An editor input to be used for untitled text buffers.
*/
export class UntitledTextEditorInput extends TextResourceEditorInput implements IEncodingSupport, IModeSupport {

static readonly ID: string = 'workbench.editors.untitledEditorInput';
export abstract class BaseUntitledTextEditorInput extends TextResourceEditorInput implements IEncodingSupport, IModeSupport {

private modelResolve: Promise<IUntitledTextEditorModel & IResolvedTextEditorModel> | undefined = undefined;

Expand Down Expand Up @@ -46,10 +41,6 @@ export class UntitledTextEditorInput extends TextResourceEditorInput implements
this._register(model.onDidRevert(() => this.dispose()));
}

getTypeId(): string {
return UntitledTextEditorInput.ID;
}

getName(): string {
return this.model.name;
}
Expand Down Expand Up @@ -120,6 +111,24 @@ export class UntitledTextEditorInput extends TextResourceEditorInput implements
return this.modelResolve;
}

dispose(): void {
this.modelResolve = undefined;

super.dispose();
}
}

/**
* An editor input to be used for untitled text buffers.
*/
export class UntitledTextEditorInput extends BaseUntitledTextEditorInput {

static readonly ID: string = 'workbench.editors.untitledEditorInput';

getTypeId(): string {
return UntitledTextEditorInput.ID;
}

matches(otherInput: unknown): boolean {
if (super.matches(otherInput) === true) {
return true;
Expand All @@ -132,10 +141,4 @@ export class UntitledTextEditorInput extends TextResourceEditorInput implements

return false;
}

dispose(): void {
this.modelResolve = undefined;

super.dispose();
}
}

0 comments on commit b2b3aee

Please sign in to comment.