当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript editorBrowser.getCodeEditor函数代码示例

本文整理汇总了TypeScript中vs/editor/browser/editorBrowser.getCodeEditor函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getCodeEditor函数的具体用法?TypeScript getCodeEditor怎么用?TypeScript getCodeEditor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getCodeEditor函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getActiveTextEditorOptions

export function getActiveTextEditorOptions(group: IEditorGroup, expectedActiveEditor?: IEditorInput, presetOptions?: EditorOptions): EditorOptions {
	const activeGroupCodeEditor = group.activeControl ? getCodeEditor(group.activeControl.getControl()) : undefined;
	if (activeGroupCodeEditor) {
		if (!expectedActiveEditor || expectedActiveEditor.matches(group.activeEditor)) {
			return TextEditorOptions.fromEditor(activeGroupCodeEditor, presetOptions);
		}
	}

	return presetOptions || new EditorOptions();
}
开发者ID:kumarharsh,项目名称:vscode,代码行数:10,代码来源:editor.ts

示例2: save

function save(
	resource: URI | null,
	isSaveAs: boolean,
	options: ISaveOptions | undefined,
	editorService: IEditorService,
	fileService: IFileService,
	untitledEditorService: IUntitledEditorService,
	textFileService: ITextFileService,
	editorGroupService: IEditorGroupsService
): Promise<any> {

	function ensureForcedSave(options?: ISaveOptions): ISaveOptions {
		if (!options) {
			options = { force: true };
		} else {
			options.force = true;
		}

		return options;
	}

	if (resource && (fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {

		// Save As (or Save untitled with associated path)
		if (isSaveAs || resource.scheme === Schemas.untitled) {
			let encodingOfSource: string | undefined;
			if (resource.scheme === Schemas.untitled) {
				encodingOfSource = untitledEditorService.getEncoding(resource);
			} else if (fileService.canHandleResource(resource)) {
				const textModel = textFileService.models.get(resource);
				encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file!
			}

			let viewStateOfSource: IEditorViewState | null;
			const activeTextEditorWidget = getCodeEditor(editorService.activeTextEditorWidget);
			if (activeTextEditorWidget) {
				const activeResource = toResource(editorService.activeEditor, { supportSideBySide: true });
				if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) {
					viewStateOfSource = activeTextEditorWidget.saveViewState();
				}
			}

			// Special case: an untitled file with associated path gets saved directly unless "saveAs" is true
			let savePromise: Promise<URI | undefined>;
			if (!isSaveAs && resource.scheme === Schemas.untitled && untitledEditorService.hasAssociatedFilePath(resource)) {
				savePromise = textFileService.save(resource, options).then((result) => {
					if (result) {
						return resource.with({ scheme: Schemas.file });
					}

					return undefined;
				});
			}

			// Otherwise, really "Save As..."
			else {

				// Force a change to the file to trigger external watchers if any
				// fixes https://github.com/Microsoft/vscode/issues/59655
				options = ensureForcedSave(options);

				savePromise = textFileService.saveAs(resource, undefined, options);
			}

			return savePromise.then((target) => {
				if (!target || target.toString() === resource.toString()) {
					return false; // save canceled or same resource used
				}

				const replacement: IResourceInput = {
					resource: target,
					encoding: encodingOfSource,
					options: {
						pinned: true,
						viewState: viewStateOfSource || undefined
					}
				};

				return Promise.all(editorGroupService.groups.map(g =>
					editorService.replaceEditors([{
						editor: { resource },
						replacement
					}], g))).then(() => true);
			});
		}

		// Pin the active editor if we are saving it
		const activeControl = editorService.activeControl;
		const activeEditorResource = activeControl && activeControl.input && activeControl.input.getResource();
		if (activeControl && activeEditorResource && activeEditorResource.toString() === resource.toString()) {
			activeControl.group.pinEditor(activeControl.input);
		}

		// Just save (force a change to the file to trigger external watchers if any)
		options = ensureForcedSave(options);

		return textFileService.save(resource, options);
	}

	return Promise.resolve(false);
//.........这里部分代码省略.........
开发者ID:joelday,项目名称:vscode,代码行数:101,代码来源:fileCommands.ts

示例3: save

function save(resource: URI, isSaveAs: boolean, editorService: IEditorService, fileService: IFileService, untitledEditorService: IUntitledEditorService,
	textFileService: ITextFileService, editorGroupService: IEditorGroupsService): TPromise<any> {

	if (resource && (fileService.canHandleResource(resource) || resource.scheme === Schemas.untitled)) {

		// Save As (or Save untitled with associated path)
		if (isSaveAs || resource.scheme === Schemas.untitled) {
			let encodingOfSource: string;
			if (resource.scheme === Schemas.untitled) {
				encodingOfSource = untitledEditorService.getEncoding(resource);
			} else if (fileService.canHandleResource(resource)) {
				const textModel = textFileService.models.get(resource);
				encodingOfSource = textModel && textModel.getEncoding(); // text model can be null e.g. if this is a binary file!
			}

			let viewStateOfSource: IEditorViewState;
			const activeTextEditorWidget = getCodeEditor(editorService.activeTextEditorWidget);
			if (activeTextEditorWidget) {
				const activeResource = toResource(editorService.activeEditor, { supportSideBySide: true });
				if (activeResource && (fileService.canHandleResource(activeResource) || resource.scheme === Schemas.untitled) && activeResource.toString() === resource.toString()) {
					viewStateOfSource = activeTextEditorWidget.saveViewState();
				}
			}

			// Special case: an untitled file with associated path gets saved directly unless "saveAs" is true
			let savePromise: TPromise<URI>;
			if (!isSaveAs && resource.scheme === Schemas.untitled && untitledEditorService.hasAssociatedFilePath(resource)) {
				savePromise = textFileService.save(resource).then((result) => {
					if (result) {
						return resource.with({ scheme: Schemas.file });
					}

					return null;
				});
			}

			// Otherwise, really "Save As..."
			else {
				savePromise = textFileService.saveAs(resource);
			}

			return savePromise.then((target) => {
				if (!target || target.toString() === resource.toString()) {
					return void 0; // save canceled or same resource used
				}

				const replacement: IResourceInput = {
					resource: target,
					encoding: encodingOfSource,
					options: {
						pinned: true,
						viewState: viewStateOfSource
					}
				};

				return TPromise.join(editorGroupService.groups.map(g =>
					editorService.replaceEditors([{
						editor: { resource },
						replacement
					}], g))).then(() => true);
			});
		}

		// Pin the active editor if we are saving it
		const activeControl = editorService.activeControl;
		const activeEditorResource = activeControl && activeControl.input && activeControl.input.getResource();
		if (activeEditorResource && activeEditorResource.toString() === resource.toString()) {
			activeControl.group.pinEditor(activeControl.input);
		}

		// Just save
		return textFileService.save(resource, { force: true /* force a change to the file to trigger external watchers if any */ });
	}

	return TPromise.as(false);
}
开发者ID:liunian,项目名称:vscode,代码行数:76,代码来源:fileCommands.ts


注:本文中的vs/editor/browser/editorBrowser.getCodeEditor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。