@@ -10,24 +10,24 @@ import { Disposable, IReference, toDisposable } from 'vs/base/common/lifecycle';
10
10
import { IObservable , IReader , autorun , autorunWithStore , derived , derivedObservableWithCache , derivedWithStore , observableFromEvent , observableValue } from 'vs/base/common/observable' ;
11
11
import { ITransaction , disposableObservableValue , globalTransaction , transaction } from 'vs/base/common/observableInternal/base' ;
12
12
import { Scrollable , ScrollbarVisibility } from 'vs/base/common/scrollable' ;
13
+ import { URI } from 'vs/base/common/uri' ;
13
14
import 'vs/css!./style' ;
15
+ import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
14
16
import { ObservableElementSizeObserver } from 'vs/editor/browser/widget/diffEditor/utils' ;
17
+ import { RevealOptions } from 'vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorWidget' ;
15
18
import { IWorkbenchUIElementFactory } from 'vs/editor/browser/widget/multiDiffEditorWidget/workbenchUIElementFactory' ;
16
19
import { 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' ;
17
26
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
27
+ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection' ;
18
28
import { DiffEditorItemTemplate , TemplateData } from './diffEditorItemTemplate' ;
19
29
import { DocumentDiffItemViewModel , MultiDiffEditorViewModel } from './multiDiffEditorViewModel' ;
20
30
import { 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' ;
31
31
32
32
export class MultiDiffEditorWidgetImpl extends Disposable {
33
33
private readonly _elements = h ( 'div.monaco-component.multiDiffEditor' , [
@@ -107,7 +107,6 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
107
107
private readonly _workbenchUIElementFactory : IWorkbenchUIElementFactory ,
108
108
@IContextKeyService private readonly _parentContextKeyService : IContextKeyService ,
109
109
@IInstantiationService private readonly _parentInstantiationService : IInstantiationService ,
110
- @IConfigurationService private readonly _configurationService : IConfigurationService ,
111
110
) {
112
111
super ( ) ;
113
112
@@ -190,8 +189,7 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
190
189
this . _scrollableElement . setScrollPosition ( { scrollLeft : scrollState . left , scrollTop : scrollState . top } ) ;
191
190
}
192
191
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 {
195
193
const viewItems = this . _viewItems . get ( ) ;
196
194
let searchCallback : ( item : VirtualizedViewItem ) => boolean ;
197
195
if ( 'original' in resource ) {
@@ -200,11 +198,18 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
200
198
searchCallback = ( item ) => item . viewModel . modifiedUri ?. toString ( ) === resource . modified . toString ( ) ;
201
199
}
202
200
const index = viewItems . findIndex ( searchCallback ) ;
203
- let scrollTop = ( range . startLineNumber - 1 ) * this . _configurationService . getValue < number > ( 'editor.lineHeight' ) ;
201
+ let scrollTop = 0 ;
204
202
for ( let i = 0 ; i < index ; i ++ ) {
205
203
scrollTop += viewItems [ i ] . contentHeight . get ( ) + this . _spaceBetweenPx ;
206
204
}
207
205
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
+ }
208
213
}
209
214
210
215
public getViewState ( ) : IMultiDiffEditorViewState {
@@ -290,6 +295,16 @@ export class MultiDiffEditorWidgetImpl extends Disposable {
290
295
}
291
296
}
292
297
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
+
293
308
export interface IMultiDiffEditorViewState {
294
309
scrollState : { top : number ; left : number } ;
295
310
docStates ?: Record < string , IMultiDiffDocState > ;
@@ -307,7 +322,7 @@ export interface IMultiDiffEditorOptions extends ITextEditorOptions {
307
322
export interface IMultiDiffEditorOptionsViewState {
308
323
revealData ?: {
309
324
resource : IMultiDiffResource ;
310
- range : Range ;
325
+ range ?: IRange ;
311
326
} ;
312
327
}
313
328
0 commit comments