feat: 添加vscode编辑器
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
export {};
|
||||
@@ -0,0 +1,214 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { editorOptionsRegistry } from './editorOptions.js';
|
||||
import { EDITOR_MODEL_DEFAULTS } from '../core/textModelDefaults.js';
|
||||
import * as nls from '../../../nls.js';
|
||||
import { Extensions } from '../../../platform/configuration/common/configurationRegistry.js';
|
||||
import { Registry } from '../../../platform/registry/common/platform.js';
|
||||
export const editorConfigurationBaseNode = Object.freeze({
|
||||
id: 'editor',
|
||||
order: 5,
|
||||
type: 'object',
|
||||
title: nls.localize('editorConfigurationTitle', "Editor"),
|
||||
scope: 5 /* ConfigurationScope.LANGUAGE_OVERRIDABLE */,
|
||||
});
|
||||
const editorConfiguration = Object.assign(Object.assign({}, editorConfigurationBaseNode), { properties: {
|
||||
'editor.tabSize': {
|
||||
type: 'number',
|
||||
default: EDITOR_MODEL_DEFAULTS.tabSize,
|
||||
minimum: 1,
|
||||
markdownDescription: nls.localize('tabSize', "The number of spaces a tab is equal to. This setting is overridden based on the file contents when `#editor.detectIndentation#` is on.")
|
||||
},
|
||||
// 'editor.indentSize': {
|
||||
// 'anyOf': [
|
||||
// {
|
||||
// type: 'string',
|
||||
// enum: ['tabSize']
|
||||
// },
|
||||
// {
|
||||
// type: 'number',
|
||||
// minimum: 1
|
||||
// }
|
||||
// ],
|
||||
// default: 'tabSize',
|
||||
// markdownDescription: nls.localize('indentSize', "The number of spaces used for indentation or 'tabSize' to use the value from `#editor.tabSize#`. This setting is overridden based on the file contents when `#editor.detectIndentation#` is on.")
|
||||
// },
|
||||
'editor.insertSpaces': {
|
||||
type: 'boolean',
|
||||
default: EDITOR_MODEL_DEFAULTS.insertSpaces,
|
||||
markdownDescription: nls.localize('insertSpaces', "Insert spaces when pressing `Tab`. This setting is overridden based on the file contents when `#editor.detectIndentation#` is on.")
|
||||
},
|
||||
'editor.detectIndentation': {
|
||||
type: 'boolean',
|
||||
default: EDITOR_MODEL_DEFAULTS.detectIndentation,
|
||||
markdownDescription: nls.localize('detectIndentation', "Controls whether `#editor.tabSize#` and `#editor.insertSpaces#` will be automatically detected when a file is opened based on the file contents.")
|
||||
},
|
||||
'editor.trimAutoWhitespace': {
|
||||
type: 'boolean',
|
||||
default: EDITOR_MODEL_DEFAULTS.trimAutoWhitespace,
|
||||
description: nls.localize('trimAutoWhitespace', "Remove trailing auto inserted whitespace.")
|
||||
},
|
||||
'editor.largeFileOptimizations': {
|
||||
type: 'boolean',
|
||||
default: EDITOR_MODEL_DEFAULTS.largeFileOptimizations,
|
||||
description: nls.localize('largeFileOptimizations', "Special handling for large files to disable certain memory intensive features.")
|
||||
},
|
||||
'editor.wordBasedSuggestions': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: nls.localize('wordBasedSuggestions', "Controls whether completions should be computed based on words in the document.")
|
||||
},
|
||||
'editor.wordBasedSuggestionsMode': {
|
||||
enum: ['currentDocument', 'matchingDocuments', 'allDocuments'],
|
||||
default: 'matchingDocuments',
|
||||
enumDescriptions: [
|
||||
nls.localize('wordBasedSuggestionsMode.currentDocument', 'Only suggest words from the active document.'),
|
||||
nls.localize('wordBasedSuggestionsMode.matchingDocuments', 'Suggest words from all open documents of the same language.'),
|
||||
nls.localize('wordBasedSuggestionsMode.allDocuments', 'Suggest words from all open documents.')
|
||||
],
|
||||
description: nls.localize('wordBasedSuggestionsMode', "Controls from which documents word based completions are computed.")
|
||||
},
|
||||
'editor.semanticHighlighting.enabled': {
|
||||
enum: [true, false, 'configuredByTheme'],
|
||||
enumDescriptions: [
|
||||
nls.localize('semanticHighlighting.true', 'Semantic highlighting enabled for all color themes.'),
|
||||
nls.localize('semanticHighlighting.false', 'Semantic highlighting disabled for all color themes.'),
|
||||
nls.localize('semanticHighlighting.configuredByTheme', 'Semantic highlighting is configured by the current color theme\'s `semanticHighlighting` setting.')
|
||||
],
|
||||
default: 'configuredByTheme',
|
||||
description: nls.localize('semanticHighlighting.enabled', "Controls whether the semanticHighlighting is shown for the languages that support it.")
|
||||
},
|
||||
'editor.stablePeek': {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
markdownDescription: nls.localize('stablePeek', "Keep peek editors open even when double clicking their content or when hitting `Escape`.")
|
||||
},
|
||||
'editor.maxTokenizationLineLength': {
|
||||
type: 'integer',
|
||||
default: 20000,
|
||||
description: nls.localize('maxTokenizationLineLength', "Lines above this length will not be tokenized for performance reasons")
|
||||
},
|
||||
'editor.language.brackets': {
|
||||
type: ['array', 'null'],
|
||||
default: null,
|
||||
description: nls.localize('schema.brackets', 'Defines the bracket symbols that increase or decrease the indentation.'),
|
||||
items: {
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
type: 'string',
|
||||
description: nls.localize('schema.openBracket', 'The opening bracket character or string sequence.')
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
description: nls.localize('schema.closeBracket', 'The closing bracket character or string sequence.')
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'editor.language.colorizedBracketPairs': {
|
||||
type: ['array', 'null'],
|
||||
default: null,
|
||||
description: nls.localize('schema.colorizedBracketPairs', 'Defines the bracket pairs that are colorized by their nesting level if bracket pair colorization is enabled.'),
|
||||
items: {
|
||||
type: 'array',
|
||||
items: [
|
||||
{
|
||||
type: 'string',
|
||||
description: nls.localize('schema.openBracket', 'The opening bracket character or string sequence.')
|
||||
},
|
||||
{
|
||||
type: 'string',
|
||||
description: nls.localize('schema.closeBracket', 'The closing bracket character or string sequence.')
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'diffEditor.maxComputationTime': {
|
||||
type: 'number',
|
||||
default: 5000,
|
||||
description: nls.localize('maxComputationTime', "Timeout in milliseconds after which diff computation is cancelled. Use 0 for no timeout.")
|
||||
},
|
||||
'diffEditor.maxFileSize': {
|
||||
type: 'number',
|
||||
default: 50,
|
||||
description: nls.localize('maxFileSize', "Maximum file size in MB for which to compute diffs. Use 0 for no limit.")
|
||||
},
|
||||
'diffEditor.renderSideBySide': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: nls.localize('sideBySide', "Controls whether the diff editor shows the diff side by side or inline.")
|
||||
},
|
||||
'diffEditor.renderMarginRevertIcon': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: nls.localize('renderMarginRevertIcon', "When enabled, the diff editor shows arrows in its glyph margin to revert changes.")
|
||||
},
|
||||
'diffEditor.ignoreTrimWhitespace': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: nls.localize('ignoreTrimWhitespace', "When enabled, the diff editor ignores changes in leading or trailing whitespace.")
|
||||
},
|
||||
'diffEditor.renderIndicators': {
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
description: nls.localize('renderIndicators', "Controls whether the diff editor shows +/- indicators for added/removed changes.")
|
||||
},
|
||||
'diffEditor.codeLens': {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: nls.localize('codeLens', "Controls whether the editor shows CodeLens.")
|
||||
},
|
||||
'diffEditor.wordWrap': {
|
||||
type: 'string',
|
||||
enum: ['off', 'on', 'inherit'],
|
||||
default: 'inherit',
|
||||
markdownEnumDescriptions: [
|
||||
nls.localize('wordWrap.off', "Lines will never wrap."),
|
||||
nls.localize('wordWrap.on', "Lines will wrap at the viewport width."),
|
||||
nls.localize('wordWrap.inherit', "Lines will wrap according to the `#editor.wordWrap#` setting."),
|
||||
]
|
||||
}
|
||||
} });
|
||||
function isConfigurationPropertySchema(x) {
|
||||
return (typeof x.type !== 'undefined' || typeof x.anyOf !== 'undefined');
|
||||
}
|
||||
// Add properties from the Editor Option Registry
|
||||
for (const editorOption of editorOptionsRegistry) {
|
||||
const schema = editorOption.schema;
|
||||
if (typeof schema !== 'undefined') {
|
||||
if (isConfigurationPropertySchema(schema)) {
|
||||
// This is a single schema contribution
|
||||
editorConfiguration.properties[`editor.${editorOption.name}`] = schema;
|
||||
}
|
||||
else {
|
||||
for (const key in schema) {
|
||||
if (Object.hasOwnProperty.call(schema, key)) {
|
||||
editorConfiguration.properties[key] = schema[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let cachedEditorConfigurationKeys = null;
|
||||
function getEditorConfigurationKeys() {
|
||||
if (cachedEditorConfigurationKeys === null) {
|
||||
cachedEditorConfigurationKeys = Object.create(null);
|
||||
Object.keys(editorConfiguration.properties).forEach((prop) => {
|
||||
cachedEditorConfigurationKeys[prop] = true;
|
||||
});
|
||||
}
|
||||
return cachedEditorConfigurationKeys;
|
||||
}
|
||||
export function isEditorConfigurationKey(key) {
|
||||
const editorConfigurationKeys = getEditorConfigurationKeys();
|
||||
return (editorConfigurationKeys[`editor.${key}`] || false);
|
||||
}
|
||||
export function isDiffEditorConfigurationKey(key) {
|
||||
const editorConfigurationKeys = getEditorConfigurationKeys();
|
||||
return (editorConfigurationKeys[`diffEditor.${key}`] || false);
|
||||
}
|
||||
const configurationRegistry = Registry.as(Extensions.Configuration);
|
||||
configurationRegistry.registerConfiguration(editorConfiguration);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { Emitter } from '../../../base/common/event.js';
|
||||
export const EditorZoom = new class {
|
||||
constructor() {
|
||||
this._zoomLevel = 0;
|
||||
this._onDidChangeZoomLevel = new Emitter();
|
||||
this.onDidChangeZoomLevel = this._onDidChangeZoomLevel.event;
|
||||
}
|
||||
getZoomLevel() {
|
||||
return this._zoomLevel;
|
||||
}
|
||||
setZoomLevel(zoomLevel) {
|
||||
zoomLevel = Math.min(Math.max(-5, zoomLevel), 20);
|
||||
if (this._zoomLevel === zoomLevel) {
|
||||
return;
|
||||
}
|
||||
this._zoomLevel = zoomLevel;
|
||||
this._onDidChangeZoomLevel.fire(this._zoomLevel);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,139 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as platform from '../../../base/common/platform.js';
|
||||
import { EDITOR_FONT_DEFAULTS } from './editorOptions.js';
|
||||
import { EditorZoom } from './editorZoom.js';
|
||||
/**
|
||||
* Determined from empirical observations.
|
||||
* @internal
|
||||
*/
|
||||
const GOLDEN_LINE_HEIGHT_RATIO = platform.isMacintosh ? 1.5 : 1.35;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const MINIMUM_LINE_HEIGHT = 8;
|
||||
export class BareFontInfo {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(opts) {
|
||||
this._bareFontInfoBrand = undefined;
|
||||
this.pixelRatio = opts.pixelRatio;
|
||||
this.fontFamily = String(opts.fontFamily);
|
||||
this.fontWeight = String(opts.fontWeight);
|
||||
this.fontSize = opts.fontSize;
|
||||
this.fontFeatureSettings = opts.fontFeatureSettings;
|
||||
this.lineHeight = opts.lineHeight | 0;
|
||||
this.letterSpacing = opts.letterSpacing;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static createFromValidatedSettings(options, pixelRatio, ignoreEditorZoom) {
|
||||
const fontFamily = options.get(45 /* EditorOption.fontFamily */);
|
||||
const fontWeight = options.get(49 /* EditorOption.fontWeight */);
|
||||
const fontSize = options.get(48 /* EditorOption.fontSize */);
|
||||
const fontFeatureSettings = options.get(47 /* EditorOption.fontLigatures */);
|
||||
const lineHeight = options.get(61 /* EditorOption.lineHeight */);
|
||||
const letterSpacing = options.get(58 /* EditorOption.letterSpacing */);
|
||||
return BareFontInfo._create(fontFamily, fontWeight, fontSize, fontFeatureSettings, lineHeight, letterSpacing, pixelRatio, ignoreEditorZoom);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static _create(fontFamily, fontWeight, fontSize, fontFeatureSettings, lineHeight, letterSpacing, pixelRatio, ignoreEditorZoom) {
|
||||
if (lineHeight === 0) {
|
||||
lineHeight = GOLDEN_LINE_HEIGHT_RATIO * fontSize;
|
||||
}
|
||||
else if (lineHeight < MINIMUM_LINE_HEIGHT) {
|
||||
// Values too small to be line heights in pixels are in ems.
|
||||
lineHeight = lineHeight * fontSize;
|
||||
}
|
||||
// Enforce integer, minimum constraints
|
||||
lineHeight = Math.round(lineHeight);
|
||||
if (lineHeight < MINIMUM_LINE_HEIGHT) {
|
||||
lineHeight = MINIMUM_LINE_HEIGHT;
|
||||
}
|
||||
const editorZoomLevelMultiplier = 1 + (ignoreEditorZoom ? 0 : EditorZoom.getZoomLevel() * 0.1);
|
||||
fontSize *= editorZoomLevelMultiplier;
|
||||
lineHeight *= editorZoomLevelMultiplier;
|
||||
return new BareFontInfo({
|
||||
pixelRatio: pixelRatio,
|
||||
fontFamily: fontFamily,
|
||||
fontWeight: fontWeight,
|
||||
fontSize: fontSize,
|
||||
fontFeatureSettings: fontFeatureSettings,
|
||||
lineHeight: lineHeight,
|
||||
letterSpacing: letterSpacing
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
getId() {
|
||||
return `${this.pixelRatio}-${this.fontFamily}-${this.fontWeight}-${this.fontSize}-${this.fontFeatureSettings}-${this.lineHeight}-${this.letterSpacing}`;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
getMassagedFontFamily() {
|
||||
const fallbackFontFamily = EDITOR_FONT_DEFAULTS.fontFamily;
|
||||
const fontFamily = BareFontInfo._wrapInQuotes(this.fontFamily);
|
||||
if (fallbackFontFamily && this.fontFamily !== fallbackFontFamily) {
|
||||
return `${fontFamily}, ${fallbackFontFamily}`;
|
||||
}
|
||||
return fontFamily;
|
||||
}
|
||||
static _wrapInQuotes(fontFamily) {
|
||||
if (/[,"']/.test(fontFamily)) {
|
||||
// Looks like the font family might be already escaped
|
||||
return fontFamily;
|
||||
}
|
||||
if (/[+ ]/.test(fontFamily)) {
|
||||
// Wrap a font family using + or <space> with quotes
|
||||
return `"${fontFamily}"`;
|
||||
}
|
||||
return fontFamily;
|
||||
}
|
||||
}
|
||||
// change this whenever `FontInfo` members are changed
|
||||
export const SERIALIZED_FONT_INFO_VERSION = 1;
|
||||
export class FontInfo extends BareFontInfo {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(opts, isTrusted) {
|
||||
super(opts);
|
||||
this._editorStylingBrand = undefined;
|
||||
this.version = SERIALIZED_FONT_INFO_VERSION;
|
||||
this.isTrusted = isTrusted;
|
||||
this.isMonospace = opts.isMonospace;
|
||||
this.typicalHalfwidthCharacterWidth = opts.typicalHalfwidthCharacterWidth;
|
||||
this.typicalFullwidthCharacterWidth = opts.typicalFullwidthCharacterWidth;
|
||||
this.canUseHalfwidthRightwardsArrow = opts.canUseHalfwidthRightwardsArrow;
|
||||
this.spaceWidth = opts.spaceWidth;
|
||||
this.middotWidth = opts.middotWidth;
|
||||
this.wsmiddotWidth = opts.wsmiddotWidth;
|
||||
this.maxDigitWidth = opts.maxDigitWidth;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
equals(other) {
|
||||
return (this.fontFamily === other.fontFamily
|
||||
&& this.fontWeight === other.fontWeight
|
||||
&& this.fontSize === other.fontSize
|
||||
&& this.fontFeatureSettings === other.fontFeatureSettings
|
||||
&& this.lineHeight === other.lineHeight
|
||||
&& this.letterSpacing === other.letterSpacing
|
||||
&& this.typicalHalfwidthCharacterWidth === other.typicalHalfwidthCharacterWidth
|
||||
&& this.typicalFullwidthCharacterWidth === other.typicalFullwidthCharacterWidth
|
||||
&& this.canUseHalfwidthRightwardsArrow === other.canUseHalfwidthRightwardsArrow
|
||||
&& this.spaceWidth === other.spaceWidth
|
||||
&& this.middotWidth === other.middotWidth
|
||||
&& this.wsmiddotWidth === other.wsmiddotWidth
|
||||
&& this.maxDigitWidth === other.maxDigitWidth);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user