Skip to content

Commit

Permalink
Merge pull request microsoft#40784 from saighost/master
Browse files Browse the repository at this point in the history
Add an option to display minimap to the left.
  • Loading branch information
alexdima authored Jan 24, 2018
2 parents ffec1fa + 65c8b8a commit ce89557
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/vs/editor/browser/controller/mouseTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ abstract class BareHitTestRequest {

this.mouseVerticalOffset = Math.max(0, ctx.getCurrentScrollTop() + pos.y - editorPos.y);
this.mouseContentHorizontalOffset = ctx.getCurrentScrollLeft() + pos.x - editorPos.x - ctx.layoutInfo.contentLeft;
this.isInMarginArea = (pos.x - editorPos.x < ctx.layoutInfo.contentLeft);
this.isInMarginArea = (pos.x - editorPos.x < ctx.layoutInfo.contentLeft && pos.x - editorPos.x >= ctx.layoutInfo.glyphMarginLeft);
this.isInContentArea = !this.isInMarginArea;
this.mouseColumn = Math.max(0, MouseTargetFactory._getMouseColumn(this.mouseContentHorizontalOffset, ctx.typicalHalfwidthCharacterWidth));
}
Expand Down Expand Up @@ -587,6 +587,8 @@ export class MouseTargetFactory {
offsetX: offset
};

offset -= ctx.layoutInfo.glyphMarginLeft;

if (offset <= ctx.layoutInfo.glyphMarginWidth) {
// On the glyph margin
return request.fulfill(MouseTargetType.GUTTER_GLYPH_MARGIN, pos, res.range, detail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ export class EditorScrollbar extends ViewPart {
const layoutInfo = this._context.configuration.editor.layoutInfo;

this.scrollbarDomNode.setLeft(layoutInfo.contentLeft);
this.scrollbarDomNode.setWidth(layoutInfo.contentWidth + layoutInfo.minimapWidth);

const side = this._context.configuration.editor.viewInfo.minimap.side;
if (side === 'right') {
this.scrollbarDomNode.setWidth(layoutInfo.contentWidth + layoutInfo.minimapWidth);
} else {
this.scrollbarDomNode.setWidth(layoutInfo.contentWidth);
}
this.scrollbarDomNode.setHeight(layoutInfo.contentHeight);
}

Expand Down
8 changes: 7 additions & 1 deletion src/vs/editor/browser/viewParts/minimap/minimap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class MinimapOptions {

public readonly lineHeight: number;

/**
* container dom node left position (in CSS px)
*/
public readonly minimapLeft: number;
/**
* container dom node width (in CSS px)
*/
Expand Down Expand Up @@ -121,6 +125,7 @@ class MinimapOptions {
this.pixelRatio = pixelRatio;
this.typicalHalfwidthCharacterWidth = fontInfo.typicalHalfwidthCharacterWidth;
this.lineHeight = configuration.editor.lineHeight;
this.minimapLeft = layoutInfo.minimapLeft;
this.minimapWidth = layoutInfo.minimapWidth;
this.minimapHeight = layoutInfo.height;

Expand All @@ -138,6 +143,7 @@ class MinimapOptions {
&& this.pixelRatio === other.pixelRatio
&& this.typicalHalfwidthCharacterWidth === other.typicalHalfwidthCharacterWidth
&& this.lineHeight === other.lineHeight
&& this.minimapLeft === other.minimapLeft
&& this.minimapWidth === other.minimapWidth
&& this.minimapHeight === other.minimapHeight
&& this.canvasInnerWidth === other.canvasInnerWidth
Expand Down Expand Up @@ -456,7 +462,6 @@ export class Minimap extends ViewPart {
this._domNode.setPosition('absolute');
this._domNode.setAttribute('role', 'presentation');
this._domNode.setAttribute('aria-hidden', 'true');
this._domNode.setRight(this._context.configuration.editor.layoutInfo.verticalScrollbarWidth);

this._shadow = createFastDomNode(document.createElement('div'));
this._shadow.setClassName('minimap-shadow-hidden');
Expand Down Expand Up @@ -563,6 +568,7 @@ export class Minimap extends ViewPart {
}

private _applyLayout(): void {
this._domNode.setLeft(this._options.minimapLeft);
this._domNode.setWidth(this._options.minimapWidth);
this._domNode.setHeight(this._options.minimapHeight);
this._shadow.setHeight(this._options.minimapHeight);
Expand Down
6 changes: 6 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.viewInfo.minimap.enabled,
'description': nls.localize('minimap.enabled', "Controls if the minimap is shown")
},
'editor.minimap.side': {
'type': 'string',
'enum': ['left', 'right'],
'default': EDITOR_DEFAULTS.viewInfo.minimap.side,
'description': nls.localize('minimap.side', "Controls the side where to render the minimap. Possible values are \'right\' and \'left\'")
},
'editor.minimap.showSlider': {
'type': 'string',
'enum': ['always', 'mouseover'],
Expand Down
39 changes: 35 additions & 4 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export interface IEditorMinimapOptions {
* Defaults to false.
*/
enabled?: boolean;
/**
* Control the side of the minimap in editor.
* Defaults to 'right'.
*/
side?: 'right' | 'left';
/**
* Control the rendering of the minimap slider.
* Defaults to 'mouseover'.
Expand Down Expand Up @@ -740,6 +745,7 @@ export interface InternalEditorScrollbarOptions {

export interface InternalEditorMinimapOptions {
readonly enabled: boolean;
readonly side: 'right' | 'left';
readonly showSlider: 'always' | 'mouseover';
readonly renderCharacters: boolean;
readonly maxColumn: number;
Expand Down Expand Up @@ -1019,6 +1025,7 @@ export class InternalEditorOptions {
&& a.contentWidth === b.contentWidth
&& a.contentHeight === b.contentHeight
&& a.renderMinimap === b.renderMinimap
&& a.minimapLeft === b.minimapLeft
&& a.minimapWidth === b.minimapWidth
&& a.viewportColumn === b.viewportColumn
&& a.verticalScrollbarWidth === b.verticalScrollbarWidth
Expand Down Expand Up @@ -1101,6 +1108,7 @@ export class InternalEditorOptions {
private static _equalsMinimapOptions(a: InternalEditorMinimapOptions, b: InternalEditorMinimapOptions): boolean {
return (
a.enabled === b.enabled
&& a.side === b.side
&& a.showSlider === b.showSlider
&& a.renderCharacters === b.renderCharacters
&& a.maxColumn === b.maxColumn
Expand Down Expand Up @@ -1288,6 +1296,10 @@ export interface EditorLayoutInfo {
*/
readonly contentHeight: number;

/**
* The position for the minimap
*/
readonly minimapLeft: number;
/**
* The width of the minimap
*/
Expand Down Expand Up @@ -1553,6 +1565,7 @@ export class EditorOptionsValidator {
}
return {
enabled: _boolean(opts.enabled, defaults.enabled),
side: _stringSet<'right' | 'left'>(opts.side, defaults.side, ['right', 'left']),
showSlider: _stringSet<'always' | 'mouseover'>(opts.showSlider, defaults.showSlider, ['always', 'mouseover']),
renderCharacters: _boolean(opts.renderCharacters, defaults.renderCharacters),
maxColumn: _clampedInt(opts.maxColumn, defaults.maxColumn, 1, 10000),
Expand Down Expand Up @@ -1769,6 +1782,7 @@ export class InternalEditorOptionsFactory {
scrollbar: opts.viewInfo.scrollbar,
minimap: {
enabled: (accessibilityIsOn ? false : opts.viewInfo.minimap.enabled), // DISABLED WHEN SCREEN READER IS ATTACHED
side: opts.viewInfo.minimap.side,
renderCharacters: opts.viewInfo.minimap.renderCharacters,
showSlider: opts.viewInfo.minimap.showSlider,
maxColumn: opts.viewInfo.minimap.maxColumn
Expand Down Expand Up @@ -1850,6 +1864,7 @@ export class InternalEditorOptionsFactory {
scrollbarArrowSize: opts.viewInfo.scrollbar.arrowSize,
verticalScrollbarHasArrows: opts.viewInfo.scrollbar.verticalHasArrows,
minimap: opts.viewInfo.minimap.enabled,
minimapSide: opts.viewInfo.minimap.side,
minimapRenderCharacters: opts.viewInfo.minimap.renderCharacters,
minimapMaxColumn: opts.viewInfo.minimap.maxColumn,
pixelRatio: env.pixelRatio
Expand Down Expand Up @@ -1982,6 +1997,7 @@ export interface IEditorLayoutProviderOpts {
horizontalScrollbarHeight: number;

minimap: boolean;
minimapSide: string;
minimapRenderCharacters: boolean;
minimapMaxColumn: number;
pixelRatio: number;
Expand All @@ -2007,6 +2023,7 @@ export class EditorLayoutProvider {
const scrollbarArrowSize = _opts.scrollbarArrowSize | 0;
const horizontalScrollbarHeight = _opts.horizontalScrollbarHeight | 0;
const minimap = _opts.minimap;
const minimapSide = _opts.minimapSide;
const minimapRenderCharacters = _opts.minimapRenderCharacters;
const minimapMaxColumn = _opts.minimapMaxColumn | 0;
const pixelRatio = _opts.pixelRatio;
Expand All @@ -2022,17 +2039,19 @@ export class EditorLayoutProvider {
glyphMarginWidth = lineHeight;
}

const glyphMarginLeft = 0;
const lineNumbersLeft = glyphMarginLeft + glyphMarginWidth;
const decorationsLeft = lineNumbersLeft + lineNumbersWidth;
const contentLeft = decorationsLeft + lineDecorationsWidth;
let glyphMarginLeft = 0;
let lineNumbersLeft = glyphMarginLeft + glyphMarginWidth;
let decorationsLeft = lineNumbersLeft + lineNumbersWidth;
let contentLeft = decorationsLeft + lineDecorationsWidth;

const remainingWidth = outerWidth - glyphMarginWidth - lineNumbersWidth - lineDecorationsWidth;

let renderMinimap: RenderMinimap;
let minimapLeft: number;
let minimapWidth: number;
let contentWidth: number;
if (!minimap) {
minimapLeft = 0;
minimapWidth = 0;
renderMinimap = RenderMinimap.None;
contentWidth = remainingWidth;
Expand Down Expand Up @@ -2064,6 +2083,16 @@ export class EditorLayoutProvider {
minimapWidth = Math.floor(minimapMaxColumn * minimapCharWidth);
}
contentWidth = remainingWidth - minimapWidth;

if (minimapSide === 'left') {
minimapLeft = 0;
glyphMarginLeft += minimapWidth;
lineNumbersLeft += minimapWidth;
decorationsLeft += minimapWidth;
contentLeft += minimapWidth;
} else {
minimapLeft = outerWidth - minimapWidth - verticalScrollbarWidth;
}
}

const viewportColumn = Math.max(1, Math.floor((contentWidth - verticalScrollbarWidth) / typicalHalfwidthCharacterWidth));
Expand Down Expand Up @@ -2091,6 +2120,7 @@ export class EditorLayoutProvider {
contentHeight: outerHeight,

renderMinimap: renderMinimap,
minimapLeft: minimapLeft,
minimapWidth: minimapWidth,

viewportColumn: viewportColumn,
Expand Down Expand Up @@ -2206,6 +2236,7 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
},
minimap: {
enabled: true,
side: 'right',
showSlider: 'mouseover',
renderCharacters: true,
maxColumn: 120
Expand Down
Loading

0 comments on commit ce89557

Please sign in to comment.