Skip to content

Commit

Permalink
Merge pull request #6553 from kisstkondoros/patch-1
Browse files Browse the repository at this point in the history
Gutter icon background size limited
  • Loading branch information
alexdima committed Jun 17, 2016
2 parents e65d79b + 65c7bd2 commit 9e7b462
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/vs/editor/browser/services/codeEditorServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export class CodeEditorServiceImpl extends AbstractCodeEditorService {
private _styleSheet: HTMLStyleElement;
private _decorationOptionProviders: {[key:string]:IModelDecorationOptionsProvider};

constructor() {
constructor(styleSheet = dom.createStyleSheet()) {
super();
this._styleSheet = dom.createStyleSheet();
this._styleSheet = styleSheet;
this._decorationOptionProviders = Object.create(null);
}

Expand Down Expand Up @@ -141,6 +141,8 @@ class DecorationTypeOptionsProvider implements IModelDecorationOptionsProvider {
public stickiness: TrackedRangeStickiness;

constructor(styleSheet: HTMLStyleElement, key:string, options:IDecorationRenderOptions) {
this.refCount = 0;

var themedOpts = getThemedRenderOptions(options);

this.className = DecorationRenderHelper.createCSSRules(
Expand Down Expand Up @@ -262,6 +264,7 @@ class DecorationRenderHelper {
letterSpacing: 'letter-spacing:{0};',

gutterIconPath: 'background:url(\'{0}\') center center no-repeat;',
gutterIconSize: 'background-size:{0};',

contentText: 'content:\'{0}\';',
contentIconPath: 'content:url(\'{0}\')',
Expand Down Expand Up @@ -321,7 +324,10 @@ class DecorationRenderHelper {
let cssTextArr = [];

if (typeof opts.gutterIconPath !== 'undefined') {
cssTextArr.push(strings.format(this._CSS_MAP.gutterIconPath, URI.file(opts.gutterIconPath).toString()));
cssTextArr.push(strings.format(this._CSS_MAP.gutterIconPath, URI.parse(opts.gutterIconPath).toString()));
if (typeof opts.gutterIconSize !== 'undefined') {
cssTextArr.push(strings.format(this._CSS_MAP.gutterIconSize, opts.gutterIconSize));
}
}

return cssTextArr.join('');
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/common/editorCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,7 @@ export interface IThemeDecorationRenderOptions {
letterSpacing?: string;

gutterIconPath?: string;
gutterIconSize?: string;

overviewRulerColor?: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import * as assert from 'assert';
import * as dom from 'vs/base/browser/dom';
import {CodeEditorServiceImpl} from 'vs/editor/browser/services/codeEditorServiceImpl';
import {IDecorationRenderOptions} from 'vs/editor/common/editorCommon';

suite('Browser Services - EditorLayoutProvider', () => {
var options: IDecorationRenderOptions = {
gutterIconPath: 'https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png',
gutterIconSize: 'contain',
backgroundColor: 'red',
borderColor: 'yellow'
};
test('register and resolve decoration type', () => {
var s = new CodeEditorServiceImpl();
s.registerDecorationType('example', options);
assert.notEqual(s.resolveDecorationOptions('example', false), undefined);
});
test('remove decoration type', () => {
var s = new CodeEditorServiceImpl();
s.registerDecorationType('example', options);
assert.notEqual(s.resolveDecorationOptions('example', false), undefined);
s.removeDecorationType('example');
assert.throws(() => s.resolveDecorationOptions('example', false));
});
test('css properties', () => {
var styleSheet = dom.createStyleSheet();
var s = new CodeEditorServiceImpl(styleSheet);
s.registerDecorationType('example', options);
var sheet = styleSheet.sheet.toString();
assert(sheet.indexOf('background: url(\'https://github.com/Microsoft/vscode/blob/master/resources/linux/code.png\') center center no-repeat;') > 0);
assert(sheet.indexOf('background-size: contain;') > 0);
assert(sheet.indexOf('border-color: yellow;') > 0);
assert(sheet.indexOf('background-color: red;') > 0);
});
});
7 changes: 7 additions & 0 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,13 @@ declare namespace vscode {
*/
gutterIconPath?: string;

/**
* Specifies the size of the gutter icon.
* Available values are 'auto', 'contain', 'cover' and any percentage value.
* For further information: https://msdn.microsoft.com/en-us/library/jj127316(v=vs.85).aspx
*/
gutterIconSize?: string;

/**
* The color of the decoration in the overview ruler. Use rgba() and define transparent colors to play well with other decorations.
*/
Expand Down

0 comments on commit 9e7b462

Please sign in to comment.