提交 eb87600b 编写于 作者: A Alex Dima

Use more URIs

上级 0129edae
......@@ -401,11 +401,7 @@ class DecorationCSSRules {
if (typeof opts !== 'undefined') {
this.collectBorderSettingsCSSText(opts, cssTextArr);
if (typeof opts.contentIconPath !== 'undefined') {
if (typeof opts.contentIconPath === 'string') {
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.file(opts.contentIconPath).toString().replace(/'/g, '%27')));
} else {
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.revive(opts.contentIconPath).toString(true).replace(/'/g, '%27')));
}
cssTextArr.push(strings.format(_CSS_MAP.contentIconPath, URI.revive(opts.contentIconPath).toString(true).replace(/'/g, '%27')));
}
if (typeof opts.contentText === 'string') {
const truncated = opts.contentText.match(/^.*$/m)![0]; // only take first line
......@@ -432,11 +428,7 @@ class DecorationCSSRules {
let cssTextArr: string[] = [];
if (typeof opts.gutterIconPath !== 'undefined') {
if (typeof opts.gutterIconPath === 'string') {
cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.file(opts.gutterIconPath).toString()));
} else {
cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.revive(opts.gutterIconPath).toString(true).replace(/'/g, '%27')));
}
cssTextArr.push(strings.format(_CSS_MAP.gutterIconPath, URI.revive(opts.gutterIconPath).toString(true).replace(/'/g, '%27')));
if (typeof opts.gutterIconSize !== 'undefined') {
cssTextArr.push(strings.format(_CSS_MAP.gutterIconSize, opts.gutterIconSize));
}
......
......@@ -534,10 +534,10 @@ export interface IThemeDecorationRenderOptions {
textDecoration?: string;
cursor?: string;
color?: string | ThemeColor;
opacity?: number;
opacity?: string;
letterSpacing?: string;
gutterIconPath?: string | UriComponents;
gutterIconPath?: UriComponents;
gutterIconSize?: string;
overviewRulerColor?: string | ThemeColor;
......@@ -551,7 +551,7 @@ export interface IThemeDecorationRenderOptions {
*/
export interface IContentDecorationRenderOptions {
contentText?: string;
contentIconPath?: string | UriComponents;
contentIconPath?: UriComponents;
border?: string;
borderColor?: string | ThemeColor;
......
......@@ -134,7 +134,7 @@ suite('Decoration Render Options', () => {
// unix file path (used as string)
let s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet);
s.registerDecorationType('example', { gutterIconPath: '/Users/foo/bar.png' });
s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/bar.png') });
let sheet = readStyleSheet(styleSheet);//.innerHTML || styleSheet.sheet.toString();
assert(
sheet.indexOf('background: url(\'file:///Users/foo/bar.png\') center center no-repeat;') > 0
......@@ -143,7 +143,7 @@ suite('Decoration Render Options', () => {
// windows file path (used as string)
s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet);
s.registerDecorationType('example', { gutterIconPath: 'c:\\files\\miles\\more.png' });
s.registerDecorationType('example', { gutterIconPath: URI.file('c:\\files\\miles\\more.png') });
sheet = readStyleSheet(styleSheet);
// TODO@Alex test fails
// assert(
......@@ -162,7 +162,7 @@ suite('Decoration Render Options', () => {
// single quote must always be escaped/encoded
s = new TestCodeEditorServiceImpl(themeServiceMock, styleSheet);
s.registerDecorationType('example', { gutterIconPath: '/Users/foo/b\'ar.png' });
s.registerDecorationType('example', { gutterIconPath: URI.file('/Users/foo/b\'ar.png') });
sheet = readStyleSheet(styleSheet);
assert(
sheet.indexOf('background: url(\'file:///Users/foo/b%27ar.png\') center center no-repeat;') > 0
......
......@@ -25,7 +25,7 @@ export class TextEditorDecorationType implements vscode.TextEditorDecorationType
constructor(proxy: MainThreadTextEditorsShape, options: vscode.DecorationRenderOptions) {
this.key = TextEditorDecorationType._Keys.nextId();
this._proxy = proxy;
this._proxy.$registerTextEditorDecorationType(this.key, <any>/* URI vs Uri */ options);
this._proxy.$registerTextEditorDecorationType(this.key, TypeConverters.DecorationRenderOptions.from(options));
}
public dispose(): void {
......
......@@ -8,8 +8,8 @@ import * as types from './extHostTypes';
import * as search from 'vs/workbench/parts/search/common/search';
import { ITextEditorOptions } from 'vs/platform/editor/common/editor';
import { EditorViewColumn } from 'vs/workbench/api/shared/editor';
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
import { EndOfLineSequence } from 'vs/editor/common/model';
import { IDecorationOptions, IThemeDecorationRenderOptions, IDecorationRenderOptions, IContentDecorationRenderOptions } from 'vs/editor/common/editorCommon';
import { EndOfLineSequence, TrackedRangeStickiness } from 'vs/editor/common/model';
import * as vscode from 'vscode';
import { URI } from 'vs/base/common/uri';
import { ProgressLocation as MainProgressLocation } from 'vs/platform/progress/common/progress';
......@@ -252,6 +252,126 @@ export function fromRangeOrRangeWithMessage(ranges: vscode.Range[] | vscode.Deco
}
}
function pathOrURIToURI(value: string | URI): URI {
if (typeof value === 'undefined') {
return value;
}
if (typeof value === 'string') {
return URI.file(value);
} else {
return value;
}
}
export namespace ThemableDecorationAttachmentRenderOptions {
export function from(options: vscode.ThemableDecorationAttachmentRenderOptions): IContentDecorationRenderOptions {
if (typeof options === 'undefined') {
return options;
}
return {
contentText: options.contentText,
contentIconPath: pathOrURIToURI(options.contentIconPath),
border: options.border,
borderColor: <string | types.ThemeColor>options.borderColor,
fontStyle: options.fontStyle,
fontWeight: options.fontWeight,
textDecoration: options.textDecoration,
color: <string | types.ThemeColor>options.color,
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
margin: options.margin,
width: options.width,
height: options.height,
};
}
}
export namespace ThemableDecorationRenderOptions {
export function from(options: vscode.ThemableDecorationRenderOptions): IThemeDecorationRenderOptions {
if (typeof options === 'undefined') {
return options;
}
return {
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
outline: options.outline,
outlineColor: <string | types.ThemeColor>options.outlineColor,
outlineStyle: options.outlineStyle,
outlineWidth: options.outlineWidth,
border: options.border,
borderColor: <string | types.ThemeColor>options.borderColor,
borderRadius: options.borderRadius,
borderSpacing: options.borderSpacing,
borderStyle: options.borderStyle,
borderWidth: options.borderWidth,
fontStyle: options.fontStyle,
fontWeight: options.fontWeight,
textDecoration: options.textDecoration,
cursor: options.cursor,
color: <string | types.ThemeColor>options.color,
opacity: options.opacity,
letterSpacing: options.letterSpacing,
gutterIconPath: pathOrURIToURI(options.gutterIconPath),
gutterIconSize: options.gutterIconSize,
overviewRulerColor: <string | types.ThemeColor>options.overviewRulerColor,
before: ThemableDecorationAttachmentRenderOptions.from(options.before),
after: ThemableDecorationAttachmentRenderOptions.from(options.after),
};
}
}
export namespace DecorationRangeBehavior {
export function from(value: types.DecorationRangeBehavior): TrackedRangeStickiness {
if (typeof value === 'undefined') {
return value;
}
switch (value) {
case types.DecorationRangeBehavior.OpenOpen:
return TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges;
case types.DecorationRangeBehavior.ClosedClosed:
return TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges;
case types.DecorationRangeBehavior.OpenClosed:
return TrackedRangeStickiness.GrowsOnlyWhenTypingBefore;
case types.DecorationRangeBehavior.ClosedOpen:
return TrackedRangeStickiness.GrowsOnlyWhenTypingAfter;
}
}
}
export namespace DecorationRenderOptions {
export function from(options: vscode.DecorationRenderOptions): IDecorationRenderOptions {
return {
isWholeLine: options.isWholeLine,
rangeBehavior: DecorationRangeBehavior.from(options.rangeBehavior),
overviewRulerLane: options.overviewRulerLane,
light: ThemableDecorationRenderOptions.from(options.light),
dark: ThemableDecorationRenderOptions.from(options.dark),
backgroundColor: <string | types.ThemeColor>options.backgroundColor,
outline: options.outline,
outlineColor: <string | types.ThemeColor>options.outlineColor,
outlineStyle: options.outlineStyle,
outlineWidth: options.outlineWidth,
border: options.border,
borderColor: <string | types.ThemeColor>options.borderColor,
borderRadius: options.borderRadius,
borderSpacing: options.borderSpacing,
borderStyle: options.borderStyle,
borderWidth: options.borderWidth,
fontStyle: options.fontStyle,
fontWeight: options.fontWeight,
textDecoration: options.textDecoration,
cursor: options.cursor,
color: <string | types.ThemeColor>options.color,
opacity: options.opacity,
letterSpacing: options.letterSpacing,
gutterIconPath: pathOrURIToURI(options.gutterIconPath),
gutterIconSize: options.gutterIconSize,
overviewRulerColor: <string | types.ThemeColor>options.overviewRulerColor,
before: ThemableDecorationAttachmentRenderOptions.from(options.before),
after: ThemableDecorationAttachmentRenderOptions.from(options.after),
};
}
}
export namespace TextEdit {
export function from(edit: vscode.TextEdit): modes.TextEdit {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册