Skip to content

Commit 60b19b3

Browse files
committed
Unchanged collapsed code improvements
1 parent 4a40139 commit 60b19b3

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed

build/lib/stylelint/vscode-known-variables.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"--vscode-diffEditor-removedLineBackground",
101101
"--vscode-diffEditor-removedTextBackground",
102102
"--vscode-diffEditor-removedTextBorder",
103+
"--vscode-diffEditor-unchangedCodeBackground",
103104
"--vscode-diffEditor-unchangedRegionBackground",
104105
"--vscode-diffEditor-unchangedRegionForeground",
105106
"--vscode-diffEditorGutter-insertedLineBackground",

src/vs/editor/browser/widget/diffEditorWidget2/diffModel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ export class UnchangedRegion {
252252
let length = mapping.originalRange.length;
253253

254254
if (origStart === 1 && modStart === 1 && length > minContext + minHiddenLineCount) {
255-
length -= minContext;
255+
if (length < originalLineCount) {
256+
length -= minContext;
257+
}
256258
result.push(new UnchangedRegion(origStart, modStart, length, 0, 0));
257259
} else if (origStart + length === originalLineCount + 1 && length > minContext + minHiddenLineCount) {
258260
origStart += minContext;

src/vs/editor/browser/widget/diffEditorWidget2/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
}
99

1010
.diff-hidden-lines {
11-
transform: translate(0px, -8px);
11+
height: 0px; /* The children each have a fixed height, the transform confuses the browser */
12+
transform: translate(0px, -10px);
1213
font-size: 13px;
1314
line-height: 14px;
1415
}
@@ -35,6 +36,10 @@
3536
transform: translate(0px, -6px);
3637
}
3738

39+
.diff-unchanged-lines {
40+
background: var(--vscode-diffEditor-unchangedCodeBackground);
41+
}
42+
3843

3944
.diff-hidden-lines .center {
4045
background: var(--vscode-diffEditor-unchangedRegionBackground);

src/vs/editor/browser/widget/diffEditorWidget2/unchangedRanges.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import { isDefined } from 'vs/base/common/types';
1313
import { ICodeEditor, IViewZone } from 'vs/editor/browser/editorBrowser';
1414
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
1515
import { DiffModel, UnchangedRegion } from 'vs/editor/browser/widget/diffEditorWidget2/diffModel';
16-
import { PlaceholderViewZone, ViewZoneOverlayWidget, applyStyle, applyViewZones } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
16+
import { PlaceholderViewZone, ViewZoneOverlayWidget, applyObservableDecorations, applyStyle, applyViewZones } from 'vs/editor/browser/widget/diffEditorWidget2/utils';
1717
import { EditorOption } from 'vs/editor/common/config/editorOptions';
18+
import { IModelDecorationOptions, IModelDeltaDecoration } from 'vs/editor/common/model';
1819

1920
export class UnchangedRangesFeature extends Disposable {
2021
private _isUpdatingViewZones = false;
@@ -61,13 +62,13 @@ export class UnchangedRangesFeature extends Disposable {
6162

6263
{
6364
const d = derived('hiddenOriginalRangeStart', reader => r.getHiddenOriginalRange(reader).startLineNumber - 1);
64-
const origVz = new PlaceholderViewZone(d, 30);
65+
const origVz = new PlaceholderViewZone(d, 24);
6566
origViewZones.push(origVz);
6667
store.add(new CollapsedCodeOverlayWidget(this._originalEditor, origVz, r, !sideBySide));
6768
}
6869
{
6970
const d = derived('hiddenModifiedRangeStart', reader => r.getHiddenModifiedRange(reader).startLineNumber - 1);
70-
const modViewZone = new PlaceholderViewZone(d, 30);
71+
const modViewZone = new PlaceholderViewZone(d, 24);
7172
modViewZones.push(modViewZone);
7273
store.add(new CollapsedCodeOverlayWidget(this._modifiedEditor, modViewZone, r, false));
7374
}
@@ -76,6 +77,29 @@ export class UnchangedRangesFeature extends Disposable {
7677
return { origViewZones, modViewZones, };
7778
});
7879

80+
81+
const unchangedLinesDecoration: IModelDecorationOptions = {
82+
description: 'unchanged lines',
83+
className: 'diff-unchanged-lines',
84+
isWholeLine: true,
85+
};
86+
87+
this._register(applyObservableDecorations(this._originalEditor, derived('decorations', (reader) => {
88+
const unchangedRegions = this._diffModel.read(reader)?.unchangedRegions.read(reader) ?? [];
89+
return unchangedRegions.map<IModelDeltaDecoration>(r => ({
90+
range: r.originalRange.toInclusiveRange()!,
91+
options: unchangedLinesDecoration,
92+
}));
93+
})));
94+
95+
this._register(applyObservableDecorations(this._modifiedEditor, derived('decorations', (reader) => {
96+
const unchangedRegions = this._diffModel.read(reader)?.unchangedRegions.read(reader) ?? [];
97+
return unchangedRegions.map<IModelDeltaDecoration>(r => ({
98+
range: r.modifiedRange.toInclusiveRange()!,
99+
options: unchangedLinesDecoration,
100+
}));
101+
})));
102+
79103
this._register(applyViewZones(this._originalEditor, viewZones.map(v => v.origViewZones), v => this._isUpdatingViewZones = v));
80104
this._register(applyViewZones(this._modifiedEditor, viewZones.map(v => v.modViewZones), v => this._isUpdatingViewZones = v));
81105

@@ -90,14 +114,14 @@ export class UnchangedRangesFeature extends Disposable {
90114

91115
class CollapsedCodeOverlayWidget extends ViewZoneOverlayWidget {
92116
private readonly _nodes = h('div.diff-hidden-lines', [
93-
h('div.top@top', { title: 'Show more above' }),
117+
h('div.top@top', { title: 'Click or drag to show more above' }),
94118
h('div.center@content', { style: { display: 'flex' } }, [
95119
h('div@first', { style: { display: 'flex', justifyContent: 'center', alignItems: 'center' } },
96120
[$('a', { title: 'Show all', role: 'button', onclick: () => { this._unchangedRegion.showAll(undefined); } }, ...renderLabelWithIcons('$(unfold)'))]
97121
),
98122
h('div@others', { style: { display: 'flex', justifyContent: 'center', alignItems: 'center' } }),
99123
]),
100-
h('div.bottom@bottom', { title: 'Show more below', role: 'button' }),
124+
h('div.bottom@bottom', { title: 'Click or drag to show more below', role: 'button' }),
101125
]);
102126

103127
constructor(
@@ -123,6 +147,9 @@ class CollapsedCodeOverlayWidget extends ViewZoneOverlayWidget {
123147
const editor = this._editor;
124148

125149
this._register(addDisposableListener(this._nodes.top, 'mousedown', e => {
150+
if (e.button !== 0) {
151+
return;
152+
}
126153
this._nodes.top.classList.toggle('dragging', true);
127154
this._nodes.root.classList.toggle('dragging', true);
128155
e.preventDefault();
@@ -154,7 +181,9 @@ class CollapsedCodeOverlayWidget extends ViewZoneOverlayWidget {
154181
}));
155182

156183
this._register(addDisposableListener(this._nodes.bottom, 'mousedown', e => {
157-
184+
if (e.button !== 0) {
185+
return;
186+
}
158187
this._nodes.bottom.classList.toggle('dragging', true);
159188
this._nodes.root.classList.toggle('dragging', true);
160189
e.preventDefault();
@@ -176,12 +205,17 @@ class CollapsedCodeOverlayWidget extends ViewZoneOverlayWidget {
176205
});
177206

178207
const mouseUpListener = addDisposableListener(document.body, 'mouseup', e => {
208+
this._unchangedRegion.isDragged.set(false, undefined);
209+
179210
if (!didMove) {
211+
const top = editor.getTopForLineNumber(this._unchangedRegion.modifiedRange.endLineNumberExclusive);
212+
180213
this._unchangedRegion.showMoreBelow(20, undefined);
214+
const top2 = editor.getTopForLineNumber(this._unchangedRegion.modifiedRange.endLineNumberExclusive);
215+
editor.setScrollTop(editor.getScrollTop() + (top2 - top));
181216
}
182217
this._nodes.bottom.classList.toggle('dragging', false);
183218
this._nodes.root.classList.toggle('dragging', false);
184-
this._unchangedRegion.isDragged.set(false, undefined);
185219
mouseMoveListener.dispose();
186220
mouseUpListener.dispose();
187221
});

src/vs/platform/theme/common/colorRegistry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,9 @@ export const diffRemovedOutline = registerColor('diffEditor.removedTextBorder',
424424
export const diffBorder = registerColor('diffEditor.border', { dark: null, light: null, hcDark: contrastBorder, hcLight: contrastBorder }, nls.localize('diffEditorBorder', 'Border color between the two text editors.'));
425425
export const diffDiagonalFill = registerColor('diffEditor.diagonalFill', { dark: '#cccccc33', light: '#22222233', hcDark: null, hcLight: null }, nls.localize('diffDiagonalFill', "Color of the diff editor's diagonal fill. The diagonal fill is used in side-by-side diff views."));
426426

427-
export const diffUnchangedRegionBackground = registerColor('diffEditor.unchangedRegionBackground', { dark: '#3e3e3e', light: '#e4e4e4', hcDark: null, hcLight: null }, nls.localize('diffEditor.unchangedRegionBackground', "The background color of unchanged blocks in diff editor."));
428-
export const diffUnchangedRegionForeground = registerColor('diffEditor.unchangedRegionForeground', { dark: '#a3a2a2', light: '#4d4c4c', hcDark: null, hcLight: null }, nls.localize('diffEditor.unchangedRegionForeground', "The foreground color of unchanged blocks in diff editor."));
427+
export const diffUnchangedRegionBackground = registerColor('diffEditor.unchangedRegionBackground', { dark: '#3e3e3e', light: '#e4e4e4', hcDark: null, hcLight: null }, nls.localize('diffEditor.unchangedRegionBackground', "The background color of unchanged blocks in the diff editor."));
428+
export const diffUnchangedRegionForeground = registerColor('diffEditor.unchangedRegionForeground', { dark: '#a3a2a2', light: '#4d4c4c', hcDark: null, hcLight: null }, nls.localize('diffEditor.unchangedRegionForeground', "The foreground color of unchanged blocks in the diff editor."));
429+
export const diffUnchangedTextBackground = registerColor('diffEditor.unchangedCodeBackground', { dark: '#74747429', light: '#b8b8b829', hcDark: null, hcLight: null }, nls.localize('diffEditor.unchangedCodeBackground', "The background color of unchanged code in the diff editor."));
429430

430431
/**
431432
* List and tree colors

0 commit comments

Comments
 (0)