@@ -10,24 +10,24 @@ import { Disposable, IReference, toDisposable } from 'vs/base/common/lifecycle';
1010import { IObservable , IReader , autorun , autorunWithStore , derived , derivedObservableWithCache , derivedWithStore , observableFromEvent , observableValue } from 'vs/base/common/observable' ;
1111import { ITransaction , disposableObservableValue , globalTransaction , transaction } from 'vs/base/common/observableInternal/base' ;
1212import { Scrollable , ScrollbarVisibility } from 'vs/base/common/scrollable' ;
13+ import { URI } from 'vs/base/common/uri' ;
1314import 'vs/css!./style' ;
15+ import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
1416import { ObservableElementSizeObserver } from 'vs/editor/browser/widget/diffEditor/utils' ;
17+ import { RevealOptions } from 'vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorWidget' ;
1518import { IWorkbenchUIElementFactory } from 'vs/editor/browser/widget/multiDiffEditorWidget/workbenchUIElementFactory' ;
1619import { OffsetRange } from 'vs/editor/common/core/offsetRange' ;
20+ import { IRange } from 'vs/editor/common/core/range' ;
21+ import { ISelection , Selection } from 'vs/editor/common/core/selection' ;
22+ import { IDiffEditor } from 'vs/editor/common/editorCommon' ;
23+ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
24+ import { ContextKeyValue , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
25+ import { ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
1726import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
27+ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
1828import { DiffEditorItemTemplate , TemplateData } from './diffEditorItemTemplate' ;
1929import { DocumentDiffItemViewModel , MultiDiffEditorViewModel } from './multiDiffEditorViewModel' ;
2030import { ObjectPool } from './objectPool' ;
21- import { ContextKeyValue , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
22- import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
23- import { EditorContextKeys } from 'vs/editor/common/editorContextKeys' ;
24- import { ISelection , Selection } from 'vs/editor/common/core/selection' ;
25- import { URI } from 'vs/base/common/uri' ;
26- import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
27- import { IDiffEditor } from 'vs/editor/common/editorCommon' ;
28- import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
29- import { Range } from 'vs/editor/common/core/range' ;
30- import { ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
3131
3232export class MultiDiffEditorWidgetImpl extends Disposable {
3333 private readonly _elements = h ( 'div.monaco-component.multiDiffEditor' , [
@@ -107,7 +107,6 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
107107 private readonly _workbenchUIElementFactory : IWorkbenchUIElementFactory ,
108108 @IContextKeyService private readonly _parentContextKeyService : IContextKeyService ,
109109 @IInstantiationService private readonly _parentInstantiationService : IInstantiationService ,
110- @IConfigurationService private readonly _configurationService : IConfigurationService ,
111110 ) {
112111 super ( ) ;
113112
@@ -190,8 +189,7 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
190189 this . _scrollableElement . setScrollPosition ( { scrollLeft : scrollState . left , scrollTop : scrollState . top } ) ;
191190 }
192191
193- // todo@aiday -mar need to reveal the range instead of just the start line number
194- public reveal ( resource : IMultiDiffResource , range : Range ) : void {
192+ public reveal ( resource : IMultiDiffResource , options ?: RevealOptions ) : void {
195193 const viewItems = this . _viewItems . get ( ) ;
196194 let searchCallback : ( item : VirtualizedViewItem ) => boolean ;
197195 if ( 'original' in resource ) {
@@ -200,11 +198,18 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
200198 searchCallback = ( item ) => item . viewModel . modifiedUri ?. toString ( ) === resource . modified . toString ( ) ;
201199 }
202200 const index = viewItems . findIndex ( searchCallback ) ;
203- let scrollTop = ( range . startLineNumber - 1 ) * this . _configurationService . getValue < number > ( 'editor.lineHeight' ) ;
201+ let scrollTop = 0 ;
204202 for ( let i = 0 ; i < index ; i ++ ) {
205203 scrollTop += viewItems [ i ] . contentHeight . get ( ) + this . _spaceBetweenPx ;
206204 }
207205 this . _scrollableElement . setScrollPosition ( { scrollTop } ) ;
206+
207+ const diffEditor = viewItems [ index ] . template . get ( ) ?. editor ;
208+ const editor = 'original' in resource ? diffEditor ?. getOriginalEditor ( ) : diffEditor ?. getModifiedEditor ( ) ;
209+ if ( editor && options ?. range ) {
210+ editor . revealRangeInCenter ( options . range ) ;
211+ highlightRange ( editor , options . range ) ;
212+ }
208213 }
209214
210215 public getViewState ( ) : IMultiDiffEditorViewState {
@@ -290,6 +295,16 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
290295 }
291296}
292297
298+ function highlightRange ( targetEditor : ICodeEditor , range : IRange ) {
299+ const modelNow = targetEditor . getModel ( ) ;
300+ const decorations = targetEditor . createDecorationsCollection ( [ { range, options : { description : 'symbol-navigate-action-highlight' , className : 'symbolHighlight' } } ] ) ;
301+ setTimeout ( ( ) => {
302+ if ( targetEditor . getModel ( ) === modelNow ) {
303+ decorations . clear ( ) ;
304+ }
305+ } , 350 ) ;
306+ }
307+
293308export interface IMultiDiffEditorViewState {
294309 scrollState : { top : number ; left : number } ;
295310 docStates ?: Record < string , IMultiDiffDocState > ;
@@ -307,7 +322,7 @@ export interface IMultiDiffEditorOptions extends ITextEditorOptions {
307322export interface IMultiDiffEditorOptionsViewState {
308323 revealData ?: {
309324 resource : IMultiDiffResource ;
310- range : Range ;
325+ range ?: IRange ;
311326 } ;
312327}
313328
0 commit comments