Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jzyrobert committed Jun 28, 2022
1 parent e759e03 commit 67c4de2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
17 changes: 17 additions & 0 deletions src/vs/editor/contrib/folding/browser/folding.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,20 @@
line-height: 1em;
cursor: pointer;
}

.monaco-editor .inline-folded-count:before {
color: grey;
margin: 0.1em 0.2em 0 0.2em;
content: "⋯";
display: inline;
line-height: 1em;
cursor: pointer;
}

.monaco-editor .inline-folded-count {
color: grey;
margin: 0.1em 0.2em 0 0.2em;
display: inline;
line-height: 1em;
cursor: pointer;
}
40 changes: 28 additions & 12 deletions src/vs/editor/contrib/folding/browser/foldingDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import { Codicon } from 'vs/base/common/codicons';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration, TrackedRangeStickiness } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IModelDecorationOptions, IModelDecorationsChangeAccessor, IModelDeltaDecoration, TrackedRangeStickiness } from 'vs/editor/common/model';
import { ModelDecorationInjectedTextOptions, ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IDecorationProvider } from 'vs/editor/contrib/folding/browser/foldingModel';
import { localize } from 'vs/nls';
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
Expand All @@ -16,22 +16,21 @@ export const foldingExpandedIcon = registerIcon('folding-expanded', Codicon.chev
export const foldingCollapsedIcon = registerIcon('folding-collapsed', Codicon.chevronRight, localize('foldingCollapsedIcon', 'Icon for collapsed ranges in the editor glyph margin.'));
export class FoldingDecorationProvider implements IDecorationProvider {

private static readonly COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register({
private static readonly COLLAPSED_VISUAL_DEFAULTS: IModelDecorationOptions = {
description: 'folding-collapsed-visual-decoration',
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
afterContentClassName: 'inline-folded',
isWholeLine: true,
firstLineDecorationClassName: ThemeIcon.asClassName(foldingCollapsedIcon)
});
};
private static readonly COLLAPSED_VISUAL_DECORATION = ModelDecorationOptions.register(this.COLLAPSED_VISUAL_DEFAULTS);

private static readonly COLLAPSED_HIGHLIGHTED_VISUAL_DECORATION = ModelDecorationOptions.register({
private static readonly COLLAPSED_HIGHLIGHTED_DEFAULTS: IModelDecorationOptions = {
...this.COLLAPSED_VISUAL_DEFAULTS,
description: 'folding-collapsed-highlighted-visual-decoration',
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
afterContentClassName: 'inline-folded',
className: 'folded-background',
isWholeLine: true,
firstLineDecorationClassName: ThemeIcon.asClassName(foldingCollapsedIcon)
});
};
private static readonly COLLAPSED_HIGHLIGHTED_VISUAL_DECORATION = ModelDecorationOptions.register(this.COLLAPSED_HIGHLIGHTED_DEFAULTS);

private static readonly EXPANDED_AUTO_HIDE_VISUAL_DECORATION = ModelDecorationOptions.register({
description: 'folding-expanded-auto-hide-visual-decoration',
Expand Down Expand Up @@ -59,11 +58,28 @@ export class FoldingDecorationProvider implements IDecorationProvider {
constructor(private readonly editor: ICodeEditor) {
}

getDecorationOption(isCollapsed: boolean, isHidden: boolean): ModelDecorationOptions {
getDecorationOption(isCollapsed: boolean, isHidden: boolean, lineCount?: number): ModelDecorationOptions {
const countDecoration = ModelDecorationInjectedTextOptions.from({ content: `(${lineCount} lines)`, inlineClassName: 'inline-folded-count' });
if (isHidden) {
return FoldingDecorationProvider.HIDDEN_RANGE_DECORATION;
return lineCount ?
ModelDecorationOptions.register({
...FoldingDecorationProvider.COLLAPSED_VISUAL_DEFAULTS,
after: countDecoration
}) :
FoldingDecorationProvider.HIDDEN_RANGE_DECORATION;
}
if (isCollapsed) {
if (lineCount) {
return this.showFoldingHighlights ?
ModelDecorationOptions.register({
...FoldingDecorationProvider.COLLAPSED_HIGHLIGHTED_DEFAULTS,
after: countDecoration
}) :
ModelDecorationOptions.register({
...FoldingDecorationProvider.COLLAPSED_VISUAL_DEFAULTS,
after: countDecoration
});
}
return this.showFoldingHighlights ? FoldingDecorationProvider.COLLAPSED_HIGHLIGHTED_VISUAL_DECORATION : FoldingDecorationProvider.COLLAPSED_VISUAL_DECORATION;
} else if (this.autoHideFoldingControls) {
return FoldingDecorationProvider.EXPANDED_AUTO_HIDE_VISUAL_DECORATION;
Expand Down
7 changes: 4 additions & 3 deletions src/vs/editor/contrib/folding/browser/foldingModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IModelDecorationOptions, IModelDecorationsChangeAccessor, IModelDeltaDe
import { FoldingRegion, FoldingRegions, ILineRange } from './foldingRanges';

export interface IDecorationProvider {
getDecorationOption(isCollapsed: boolean, isHidden: boolean): IModelDecorationOptions;
getDecorationOption(isCollapsed: boolean, isHidden: boolean, lineNumber?: number): IModelDecorationOptions;
deltaDecorations(oldDecorations: string[], newDecorations: IModelDeltaDecoration[]): string[];
changeDecorations<T>(callback: (changeAccessor: IModelDecorationsChangeAccessor) => T): T | null;
}
Expand Down Expand Up @@ -57,10 +57,11 @@ export class FoldingModel {
let lastHiddenLine = -1; // the end of the last hidden lines
const updateDecorationsUntil = (index: number) => {
while (k < index) {
const startLineNumber = this._regions.getStartLineNumber(k);
const endLineNumber = this._regions.getEndLineNumber(k);
const isCollapsed = this._regions.isCollapsed(k);
if (endLineNumber <= dirtyRegionEndLine) {
accessor.changeDecorationOptions(this._editorDecorationIds[k], this._decorationProvider.getDecorationOption(isCollapsed, endLineNumber <= lastHiddenLine));
accessor.changeDecorationOptions(this._editorDecorationIds[k], this._decorationProvider.getDecorationOption(isCollapsed, endLineNumber <= lastHiddenLine, endLineNumber - startLineNumber));
}
if (isCollapsed && endLineNumber > lastHiddenLine) {
lastHiddenLine = endLineNumber;
Expand Down Expand Up @@ -119,7 +120,7 @@ export class FoldingModel {
endLineNumber: startLineNumber,
endColumn: maxColumn
};
newEditorDecorations.push({ range: decorationRange, options: this._decorationProvider.getDecorationOption(isCollapsed, endLineNumber <= lastHiddenLine) });
newEditorDecorations.push({ range: decorationRange, options: this._decorationProvider.getDecorationOption(isCollapsed, endLineNumber <= lastHiddenLine, endLineNumber - startLineNumber) });
if (isCollapsed && endLineNumber > lastHiddenLine) {
lastHiddenLine = endLineNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class TestDecorationProvider {
constructor(private model: ITextModel) {
}

getDecorationOption(isCollapsed: boolean, isHidden: boolean): ModelDecorationOptions {
getDecorationOption(isCollapsed: boolean, isHidden: boolean, lineCount?: number): ModelDecorationOptions {
if (isHidden) {
return TestDecorationProvider.hiddenDecoration;
}
Expand Down

0 comments on commit 67c4de2

Please sign in to comment.