From 9ebf2c206f2f94f06a610220de311e4d620fb35d Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 15 Dec 2016 17:53:50 +0100 Subject: [PATCH] Range decorations: Take code editor as argument instead of workbench editor Option to decorate whole line or not --- .../workbench/common/editor/rangeDecorations.ts | 16 ++++++++-------- .../markers/browser/markersTreeController.ts | 3 ++- .../parts/search/browser/searchViewlet.ts | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/common/editor/rangeDecorations.ts b/src/vs/workbench/common/editor/rangeDecorations.ts index 8a920a142be..6104e528281 100644 --- a/src/vs/workbench/common/editor/rangeDecorations.ts +++ b/src/vs/workbench/common/editor/rangeDecorations.ts @@ -7,12 +7,12 @@ import { IDisposable } from 'vs/base/common/lifecycle'; import URI from 'vs/base/common/uri'; import * as editorCommon from 'vs/editor/common/editorCommon'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { IEditor } from 'vs/platform/editor/common/editor'; import { asFileEditorInput } from 'vs/workbench/common/editor'; export interface IRangeHighlightDecoration { resource: URI; range: editorCommon.IRange; + isWholeLine?: boolean; } export class RangeHighlightDecorations implements IDisposable { @@ -31,26 +31,26 @@ export class RangeHighlightDecorations implements IDisposable { this.rangeHighlightDecorationId = null; } - public highlightRange(range: IRangeHighlightDecoration, editor?: IEditor) { + public highlightRange(range: IRangeHighlightDecoration, editor?: editorCommon.ICommonCodeEditor) { editor = editor ? editor : this.getEditor(range); if (editor) { - this.doHighlightRange(editor.getControl(), range); + this.doHighlightRange(editor, range); } } private doHighlightRange(editor: editorCommon.ICommonCodeEditor, selectionRange: IRangeHighlightDecoration) { this.removeHighlightRange(); editor.changeDecorations((changeAccessor: editorCommon.IModelDecorationsChangeAccessor) => { - this.rangeHighlightDecorationId = changeAccessor.addDecoration(selectionRange.range, this.createRangeHighlightDecoration()); + this.rangeHighlightDecorationId = changeAccessor.addDecoration(selectionRange.range, this.createRangeHighlightDecoration(selectionRange.isWholeLine)); }); this.setEditor(editor); } - private getEditor(resourceRange: IRangeHighlightDecoration): IEditor { + private getEditor(resourceRange: IRangeHighlightDecoration): editorCommon.ICommonCodeEditor { const editorInput = asFileEditorInput(this.editorService.getActiveEditorInput()); if (editorInput) { if (editorInput.getResource().fsPath === resourceRange.resource.fsPath) { - return this.editorService.getActiveEditor(); + return this.editorService.getActiveEditor().getControl(); } } return null; @@ -86,11 +86,11 @@ export class RangeHighlightDecorations implements IDisposable { model.deltaDecorations([rangeHighlightDecorationId], []); } - private createRangeHighlightDecoration(): editorCommon.IModelDecorationOptions { + private createRangeHighlightDecoration(isWholeLine: boolean = true): editorCommon.IModelDecorationOptions { return { stickiness: editorCommon.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges, className: 'rangeHighlight', - isWholeLine: true + isWholeLine }; } diff --git a/src/vs/workbench/parts/markers/browser/markersTreeController.ts b/src/vs/workbench/parts/markers/browser/markersTreeController.ts index d699a1c77be..14f008999e9 100644 --- a/src/vs/workbench/parts/markers/browser/markersTreeController.ts +++ b/src/vs/workbench/parts/markers/browser/markersTreeController.ts @@ -22,6 +22,7 @@ import { Keybinding } from 'vs/base/common/keyCodes'; import { IActionProvider } from 'vs/base/parts/tree/browser/actionsRenderer'; import { ActionItem, Separator } from 'vs/base/browser/ui/actionbar/actionbar'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; +import { ICommonCodeEditor } from 'vs/editor/common/editorCommon'; export class Controller extends treedefaults.DefaultController { @@ -124,7 +125,7 @@ export class Controller extends treedefaults.DefaultController { }, }, sideByside).done((editor) => { if (preserveFocus) { - this.rangeHighlightDecorations.highlightRange(marker, editor); + this.rangeHighlightDecorations.highlightRange(marker, editor.getControl()); } else { this.rangeHighlightDecorations.removeHighlightRange(); } diff --git a/src/vs/workbench/parts/search/browser/searchViewlet.ts b/src/vs/workbench/parts/search/browser/searchViewlet.ts index 07c01fc333d..c47f745968c 100644 --- a/src/vs/workbench/parts/search/browser/searchViewlet.ts +++ b/src/vs/workbench/parts/search/browser/searchViewlet.ts @@ -8,7 +8,7 @@ import 'vs/css!./media/searchviewlet'; import nls = require('vs/nls'); import { TPromise } from 'vs/base/common/winjs.base'; -import { EditorType } from 'vs/editor/common/editorCommon'; +import { EditorType, ICommonCodeEditor } from 'vs/editor/common/editorCommon'; import lifecycle = require('vs/base/common/lifecycle'); import errors = require('vs/base/common/errors'); import aria = require('vs/base/browser/ui/aria/aria'); @@ -992,7 +992,7 @@ export class SearchViewlet extends Viewlet { this.viewModel.searchResult.rangeHighlightDecorations.highlightRange({ resource, range: element.range() - }, editor); + }, editor.getControl()); } else { this.viewModel.searchResult.rangeHighlightDecorations.removeHighlightRange(); } -- GitLab