src/vs/workbench/browser/parts/editor/textResourceEditor.ts/TextResourceEditor/onDidEditorPaste
class TextResourceEditor:	private onDidEditorPaste(e: IPasteEvent, codeEditor: ICodeEditor): void {
		if (this.input instanceof UntitledTextEditorInput && this.input.model.hasModeSetExplicitly) {
			return; // do not override mode if it was set explicitly
		}

		if (e.range.startLineNumber !== 1 || e.range.startColumn !== 1) {
			return; // only when pasting into first line, first column (= empty document)
		}

		if (codeEditor.getOption(EditorOption.readOnly)) {
			return; // not for readonly editors
		}

		const textModel = codeEditor.getModel();
		if (!textModel) {
			return; // require a live model
		}

		const currentMode = textModel.getModeId();
		if (currentMode !== PLAINTEXT_MODE_ID) {
			return; // require current mode to be unspecific
		}

		let candidateMode: string | undefined = undefined;

		// A mode is provided via the paste event so text was copied using
		// VSCode. As such we trust this mode and use it if specific
		if (e.mode) {
			candidateMode = e.mode;
		}

		// A mode was not provided, so the data comes from outside VSCode
		// We can still try to guess a good mode from the first line if
		// the paste changed the first line
		else {
			candidateMode = withNullAsUndefined(this.modeService.getModeIdByFilepathOrFirstLine(textModel.uri, textModel.getLineContent(1).substr(0, ModelConstants.FIRST_LINE_DETECTION_LENGTH_LIMIT)));
		}

		// Finally apply mode to model if specified
		if (candidateMode !== PLAINTEXT_MODE_ID) {
			this.modelService.setMode(textModel, this.modeService.create(candidateMode));
		}
	}