@@ -11,6 +11,7 @@ import { isIOS } from 'vs/base/common/platform';
11
11
import { ThemeIcon } from 'vs/base/common/themables' ;
12
12
import { IEditorMouseEvent , MouseTargetType } from 'vs/editor/browser/editorBrowser' ;
13
13
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget' ;
14
+ import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2' ;
14
15
import { EditorOption } from 'vs/editor/common/config/editorOptions' ;
15
16
import { LineRangeMapping } from 'vs/editor/common/diff/linesDiffComputer' ;
16
17
import { EndOfLineSequence , ITextModel } from 'vs/editor/common/model' ;
@@ -42,9 +43,10 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
42
43
constructor (
43
44
private readonly _getViewZoneId : ( ) => string ,
44
45
private readonly _marginDomNode : HTMLElement ,
45
- private readonly editor : CodeEditorWidget ,
46
- private readonly diff : LineRangeMapping ,
47
- private readonly viewLineCounts : number [ ] ,
46
+ private readonly _modifiedEditor : CodeEditorWidget ,
47
+ private readonly _diff : LineRangeMapping ,
48
+ private readonly _editor : DiffEditorWidget2 ,
49
+ private readonly _viewLineCounts : number [ ] ,
48
50
private readonly _originalTextModel : ITextModel ,
49
51
private readonly _contextMenuService : IContextMenuService ,
50
52
private readonly _clipboardService : IClipboardService ,
@@ -57,46 +59,46 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
57
59
this . _diffActions = document . createElement ( 'div' ) ;
58
60
this . _diffActions . className = ThemeIcon . asClassName ( Codicon . lightBulb ) + ' lightbulb-glyph' ;
59
61
this . _diffActions . style . position = 'absolute' ;
60
- const lineHeight = this . editor . getOption ( EditorOption . lineHeight ) ;
62
+ const lineHeight = this . _modifiedEditor . getOption ( EditorOption . lineHeight ) ;
61
63
this . _diffActions . style . right = '0px' ;
62
64
this . _diffActions . style . visibility = 'hidden' ;
63
65
this . _diffActions . style . height = `${ lineHeight } px` ;
64
66
this . _diffActions . style . lineHeight = `${ lineHeight } px` ;
65
67
this . _marginDomNode . appendChild ( this . _diffActions ) ;
66
68
67
69
const actions : Action [ ] = [ ] ;
68
- const isDeletion = diff . modifiedRange . isEmpty ;
70
+ const isDeletion = _diff . modifiedRange . isEmpty ;
69
71
70
72
// default action
71
73
actions . push ( new Action (
72
74
'diff.clipboard.copyDeletedContent' ,
73
75
isDeletion
74
- ? ( diff . originalRange . length > 1
76
+ ? ( _diff . originalRange . length > 1
75
77
? localize ( 'diff.clipboard.copyDeletedLinesContent.label' , "Copy deleted lines" )
76
78
: localize ( 'diff.clipboard.copyDeletedLinesContent.single.label' , "Copy deleted line" ) )
77
- : ( diff . originalRange . length > 1
79
+ : ( _diff . originalRange . length > 1
78
80
? localize ( 'diff.clipboard.copyChangedLinesContent.label' , "Copy changed lines" )
79
81
: localize ( 'diff.clipboard.copyChangedLinesContent.single.label' , "Copy changed line" ) ) ,
80
82
undefined ,
81
83
true ,
82
84
async ( ) => {
83
- const originalText = this . _originalTextModel . getValueInRange ( diff . originalRange . toExclusiveRange ( ) ) ;
85
+ const originalText = this . _originalTextModel . getValueInRange ( _diff . originalRange . toExclusiveRange ( ) ) ;
84
86
await this . _clipboardService . writeText ( originalText ) ;
85
87
}
86
88
) ) ;
87
89
88
90
let currentLineNumberOffset = 0 ;
89
91
let copyLineAction : Action | undefined = undefined ;
90
- if ( diff . originalRange . length > 1 ) {
92
+ if ( _diff . originalRange . length > 1 ) {
91
93
copyLineAction = new Action (
92
94
'diff.clipboard.copyDeletedLineContent' ,
93
95
isDeletion
94
- ? localize ( 'diff.clipboard.copyDeletedLineContent.label' , "Copy deleted line ({0})" , diff . originalRange . startLineNumber )
95
- : localize ( 'diff.clipboard.copyChangedLineContent.label' , "Copy changed line ({0})" , diff . originalRange . startLineNumber ) ,
96
+ ? localize ( 'diff.clipboard.copyDeletedLineContent.label' , "Copy deleted line ({0})" , _diff . originalRange . startLineNumber )
97
+ : localize ( 'diff.clipboard.copyChangedLineContent.label' , "Copy changed line ({0})" , _diff . originalRange . startLineNumber ) ,
96
98
undefined ,
97
99
true ,
98
100
async ( ) => {
99
- let lineContent = this . _originalTextModel . getLineContent ( diff . originalRange . startLineNumber + currentLineNumberOffset ) ;
101
+ let lineContent = this . _originalTextModel . getLineContent ( _diff . originalRange . startLineNumber + currentLineNumberOffset ) ;
100
102
if ( lineContent === '' ) {
101
103
// empty line -> new line
102
104
const eof = this . _originalTextModel . getEndOfLineSequence ( ) ;
@@ -109,21 +111,18 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
109
111
actions . push ( copyLineAction ) ;
110
112
}
111
113
112
- const readOnly = editor . getOption ( EditorOption . readOnly ) ;
114
+ const readOnly = _modifiedEditor . getOption ( EditorOption . readOnly ) ;
113
115
if ( ! readOnly ) {
114
116
actions . push ( new Action ( 'diff.inline.revertChange' , localize ( 'diff.inline.revertChange.label' , "Revert this change" ) , undefined , true , async ( ) => {
115
- const originalText = this . _originalTextModel . getValueInRange ( this . diff . originalRange . toExclusiveRange ( ) ) ;
116
- editor . executeEdits ( 'diffEditor' , [
117
- { range : this . diff . modifiedRange . toExclusiveRange ( ) , text : originalText }
118
- ] ) ;
117
+ this . _editor . revert ( this . _diff ) ;
119
118
} ) ) ;
120
119
}
121
120
122
- const useShadowDOM = editor . getOption ( EditorOption . useShadowDOM ) && ! isIOS ; // Do not use shadow dom on IOS #122035
121
+ const useShadowDOM = _modifiedEditor . getOption ( EditorOption . useShadowDOM ) && ! isIOS ; // Do not use shadow dom on IOS #122035
123
122
124
123
const showContextMenu = ( x : number , y : number ) => {
125
124
this . _contextMenuService . showContextMenu ( {
126
- domForShadowRoot : useShadowDOM ? editor . getDomNode ( ) ?? undefined : undefined ,
125
+ domForShadowRoot : useShadowDOM ? _modifiedEditor . getDomNode ( ) ?? undefined : undefined ,
127
126
getAnchor : ( ) => {
128
127
return {
129
128
x,
@@ -134,8 +133,8 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
134
133
if ( copyLineAction ) {
135
134
copyLineAction . label =
136
135
isDeletion
137
- ? localize ( 'diff.clipboard.copyDeletedLineContent.label' , "Copy deleted line ({0})" , diff . originalRange . startLineNumber + currentLineNumberOffset )
138
- : localize ( 'diff.clipboard.copyChangedLineContent.label' , "Copy changed line ({0})" , diff . originalRange . startLineNumber + currentLineNumberOffset ) ;
136
+ ? localize ( 'diff.clipboard.copyDeletedLineContent.label' , "Copy deleted line ({0})" , _diff . originalRange . startLineNumber + currentLineNumberOffset )
137
+ : localize ( 'diff.clipboard.copyChangedLineContent.label' , "Copy changed line ({0})" , _diff . originalRange . startLineNumber + currentLineNumberOffset ) ;
139
138
}
140
139
return actions ;
141
140
} ,
@@ -150,7 +149,7 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
150
149
showContextMenu ( e . posx , top + height + pad ) ;
151
150
} ) ) ;
152
151
153
- this . _register ( editor . onMouseMove ( ( e : IEditorMouseEvent ) => {
152
+ this . _register ( _modifiedEditor . onMouseMove ( ( e : IEditorMouseEvent ) => {
154
153
if ( ( e . target . type === MouseTargetType . CONTENT_VIEW_ZONE || e . target . type === MouseTargetType . GUTTER_VIEW_ZONE ) && e . target . detail . viewZoneId === this . _getViewZoneId ( ) ) {
155
154
currentLineNumberOffset = this . _updateLightBulbPosition ( this . _marginDomNode , e . event . browserEvent . y , lineHeight ) ;
156
155
this . visibility = true ;
@@ -159,7 +158,7 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
159
158
}
160
159
} ) ) ;
161
160
162
- this . _register ( editor . onMouseDown ( ( e : IEditorMouseEvent ) => {
161
+ this . _register ( _modifiedEditor . onMouseDown ( ( e : IEditorMouseEvent ) => {
163
162
if ( ! e . event . rightButton ) {
164
163
return ;
165
164
}
@@ -182,10 +181,10 @@ export class InlineDiffDeletedCodeMargin extends Disposable {
182
181
const lineNumberOffset = Math . floor ( offset / lineHeight ) ;
183
182
const newTop = lineNumberOffset * lineHeight ;
184
183
this . _diffActions . style . top = `${ newTop } px` ;
185
- if ( this . viewLineCounts ) {
184
+ if ( this . _viewLineCounts ) {
186
185
let acc = 0 ;
187
- for ( let i = 0 ; i < this . viewLineCounts . length ; i ++ ) {
188
- acc += this . viewLineCounts [ i ] ;
186
+ for ( let i = 0 ; i < this . _viewLineCounts . length ; i ++ ) {
187
+ acc += this . _viewLineCounts [ i ] ;
189
188
if ( lineNumberOffset < acc ) {
190
189
return i ;
191
190
}
0 commit comments