@@ -7,8 +7,8 @@ import * as DOM from 'vs/base/browser/dom';
77import { Disposable , DisposableStore , IDisposable } from 'vs/base/common/lifecycle' ;
88import { Schemas } from 'vs/base/common/network' ;
99import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
10- import { DiffElementViewModelBase , getFormattedMetadataJSON , getFormattedOutputJSON , OutputComparison , outputEqual , OUTPUT_EDITOR_HEIGHT_MAGIC , PropertyFoldingState , SideBySideDiffElementViewModel , SingleSideDiffElementViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel' ;
11- import { CellDiffSideBySideRenderTemplate , CellDiffSingleSideRenderTemplate , DiffSide , DIFF_CELL_MARGIN , INotebookTextDiffEditor , NOTEBOOK_DIFF_CELL_INPUT , NOTEBOOK_DIFF_CELL_PROPERTY , NOTEBOOK_DIFF_CELL_PROPERTY_EXPANDED } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser' ;
10+ import { DiffElementCellViewModelBase , getFormattedMetadataJSON , getFormattedOutputJSON , OutputComparison , outputEqual , OUTPUT_EDITOR_HEIGHT_MAGIC , PropertyFoldingState , SideBySideDiffElementViewModel , SingleSideDiffElementViewModel , DiffElementPlaceholderViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffElementViewModel' ;
11+ import { CellDiffSideBySideRenderTemplate , CellDiffSingleSideRenderTemplate , DiffSide , DIFF_CELL_MARGIN , INotebookTextDiffEditor , NOTEBOOK_DIFF_CELL_INPUT , NOTEBOOK_DIFF_CELL_PROPERTY , NOTEBOOK_DIFF_CELL_PROPERTY_EXPANDED , CellDiffPlaceholderRenderTemplate , IDiffCellMarginOverlay } from 'vs/workbench/contrib/notebook/browser/diff/notebookDiffEditorBrowser' ;
1212import { CodeEditorWidget , ICodeEditorWidgetOptions } from 'vs/editor/browser/widget/codeEditor/codeEditorWidget' ;
1313import { IModelService } from 'vs/editor/common/services/model' ;
1414import { ILanguageService } from 'vs/editor/common/languages/language' ;
@@ -31,7 +31,7 @@ import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestCont
3131import { MenuPreventer } from 'vs/workbench/contrib/codeEditor/browser/menuPreventer' ;
3232import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard' ;
3333import { TabCompletionController } from 'vs/workbench/contrib/snippets/browser/tabCompletion' ;
34- import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels' ;
34+ import { renderIcon , renderLabelWithIcons } from 'vs/base/browser/ui/iconLabel/iconLabels' ;
3535import * as editorCommon from 'vs/editor/common/editorCommon' ;
3636import { ITextModelService } from 'vs/editor/common/services/resolverService' ;
3737import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
@@ -44,6 +44,8 @@ import { IAccessibilityService } from 'vs/platform/accessibility/common/accessib
4444import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditor/diffEditorWidget' ;
4545import { ICommandService } from 'vs/platform/commands/common/commands' ;
4646import { DiffNestedCellViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel' ;
47+ import { localize } from 'vs/nls' ;
48+ import { Emitter } from 'vs/base/common/event' ;
4749
4850export function getOptimizedNestedCodeEditorWidgetOptions ( ) : ICodeEditorWidgetOptions {
4951 return {
@@ -59,6 +61,29 @@ export function getOptimizedNestedCodeEditorWidgetOptions(): ICodeEditorWidgetOp
5961 } ;
6062}
6163
64+ export class CellDiffPlaceholderElement extends Disposable {
65+ constructor (
66+ placeholder : DiffElementPlaceholderViewModel ,
67+ templateData : CellDiffPlaceholderRenderTemplate ,
68+ ) {
69+ super ( ) ;
70+ templateData . body . classList . remove ( 'left' , 'right' , 'full' ) ;
71+ const text = ( placeholder . hiddenCells . length === 1 ) ?
72+ localize ( 'hiddenCell' , '{0} hidden cell' , placeholder . hiddenCells . length ) :
73+ localize ( 'hiddenCells' , '{0} hidden cells' , placeholder . hiddenCells . length ) ;
74+ templateData . placeholder . innerText = text ;
75+
76+ this . _register ( DOM . addDisposableListener ( templateData . placeholder , 'dblclick' , ( e : MouseEvent ) => {
77+ if ( e . button !== 0 ) {
78+ return ;
79+ }
80+ e . preventDefault ( ) ;
81+ placeholder . showHiddenCells ( ) ;
82+ } ) ) ;
83+ this . _register ( templateData . marginOverlay . onAction ( ( ) => placeholder . showHiddenCells ( ) ) ) ;
84+ templateData . marginOverlay . show ( ) ;
85+ }
86+ }
6287
6388class PropertyHeader extends Disposable {
6489 protected _foldingIndicator ! : HTMLElement ;
@@ -69,14 +94,14 @@ class PropertyHeader extends Disposable {
6994 protected _propertyExpanded ?: IContextKey < boolean > ;
7095
7196 constructor (
72- readonly cell : DiffElementViewModelBase ,
97+ readonly cell : DiffElementCellViewModelBase ,
7398 readonly propertyHeaderContainer : HTMLElement ,
7499 readonly notebookEditor : INotebookTextDiffEditor ,
75100 readonly accessor : {
76101 updateInfoRendering : ( renderOutput : boolean ) => void ;
77- checkIfModified : ( cell : DiffElementViewModelBase ) => false | { reason : string | undefined } ;
78- getFoldingState : ( cell : DiffElementViewModelBase ) => PropertyFoldingState ;
79- updateFoldingState : ( cell : DiffElementViewModelBase , newState : PropertyFoldingState ) => void ;
102+ checkIfModified : ( cell : DiffElementCellViewModelBase ) => false | { reason : string | undefined } ;
103+ getFoldingState : ( cell : DiffElementCellViewModelBase ) => PropertyFoldingState ;
104+ updateFoldingState : ( cell : DiffElementCellViewModelBase , newState : PropertyFoldingState ) => void ;
80105 unChangedLabel : string ;
81106 changedLabel : string ;
82107 prefix : string ;
@@ -271,7 +296,7 @@ abstract class AbstractElementRenderer extends Disposable {
271296
272297 constructor (
273298 readonly notebookEditor : INotebookTextDiffEditor ,
274- readonly cell : DiffElementViewModelBase ,
299+ readonly cell : DiffElementCellViewModelBase ,
275300 readonly templateData : CellDiffSingleSideRenderTemplate | CellDiffSideBySideRenderTemplate ,
276301 readonly style : 'left' | 'right' | 'full' ,
277302 protected readonly instantiationService : IInstantiationService ,
@@ -1361,6 +1386,15 @@ export class ModifiedElement extends AbstractElementRenderer {
13611386 container . classList . remove ( 'inserted' , 'removed' ) ;
13621387 }
13631388
1389+ override buildBody ( ) : void {
1390+ super . buildBody ( ) ;
1391+ if ( this . cell . displayIconToHideUnmodifiedCells ) {
1392+ this . _register ( this . templateData . marginOverlay . onAction ( ( ) => this . cell . hideUnchangedCells ( ) ) ) ;
1393+ this . templateData . marginOverlay . show ( ) ;
1394+ } else {
1395+ this . templateData . marginOverlay . hide ( ) ;
1396+ }
1397+ }
13641398 _disposeMetadata ( ) {
13651399 this . cell . metadataStatusHeight = 0 ;
13661400 this . cell . metadataHeight = 0 ;
@@ -1790,3 +1824,78 @@ export class ModifiedElement extends AbstractElementRenderer {
17901824 super . dispose ( ) ;
17911825 }
17921826}
1827+
1828+
1829+ export class CollapsedCellOverlayWidget extends Disposable implements IDiffCellMarginOverlay {
1830+ private readonly _nodes = DOM . h ( 'div.diff-hidden-cells' , [
1831+ DOM . h ( 'div.center@content' , { style : { display : 'flex' } } , [
1832+ DOM . $ ( 'a' , {
1833+ title : localize ( 'showUnchangedCells' , 'Show Unchanged Cells' ) ,
1834+ role : 'button' ,
1835+ onclick : ( ) => { this . _action . fire ( ) ; }
1836+ } ,
1837+ ...renderLabelWithIcons ( '$(unfold)' ) ) ]
1838+ ) ,
1839+ ] ) ;
1840+
1841+ private readonly _action = this . _register ( new Emitter < void > ( ) ) ;
1842+ public readonly onAction = this . _action . event ;
1843+ constructor (
1844+ private readonly container : HTMLElement
1845+ ) {
1846+ super ( ) ;
1847+
1848+ this . _nodes . root . style . display = 'none' ;
1849+ container . appendChild ( this . _nodes . root ) ;
1850+ }
1851+ public show ( ) {
1852+ this . _nodes . root . style . display = 'block' ;
1853+ }
1854+ public hide ( ) {
1855+ this . _nodes . root . style . display = 'none' ;
1856+ }
1857+ public override dispose ( ) {
1858+ this . hide ( ) ;
1859+ this . container . removeChild ( this . _nodes . root ) ;
1860+ DOM . reset ( this . _nodes . root ) ;
1861+ super . dispose ( ) ;
1862+ }
1863+ }
1864+
1865+ export class UnchangedCellOverlayWidget extends Disposable implements IDiffCellMarginOverlay {
1866+ private readonly _nodes = DOM . h ( 'div.diff-hidden-cells' , [
1867+ DOM . h ( 'div.center@content' , { style : { display : 'flex' } } , [
1868+ DOM . $ ( 'a' , {
1869+ title : localize ( 'hideUnchangedCells' , 'Hide Unchanged Cells' ) ,
1870+ role : 'button' ,
1871+ onclick : ( ) => { this . _action . fire ( ) ; }
1872+ } ,
1873+ ...renderLabelWithIcons ( '$(fold)' )
1874+ ) ,
1875+ ]
1876+ ) ,
1877+ ] ) ;
1878+
1879+ private readonly _action = this . _register ( new Emitter < void > ( ) ) ;
1880+ public readonly onAction = this . _action . event ;
1881+ constructor (
1882+ private readonly container : HTMLElement
1883+ ) {
1884+ super ( ) ;
1885+
1886+ this . _nodes . root . style . display = 'none' ;
1887+ container . appendChild ( this . _nodes . root ) ;
1888+ }
1889+ public show ( ) {
1890+ this . _nodes . root . style . display = 'block' ;
1891+ }
1892+ public hide ( ) {
1893+ this . _nodes . root . style . display = 'none' ;
1894+ }
1895+ public override dispose ( ) {
1896+ this . hide ( ) ;
1897+ this . container . removeChild ( this . _nodes . root ) ;
1898+ DOM . reset ( this . _nodes . root ) ;
1899+ super . dispose ( ) ;
1900+ }
1901+ }
0 commit comments