Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add folding from end of region #77363

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,12 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.contribInfo.showFoldingControls,
'description': nls.localize('showFoldingControls', "Controls whether the fold controls on the gutter are automatically hidden.")
},
'editor.foldingControls': {
'type': 'string',
'enum': ['classic', 'top-bottom'],
'default': EDITOR_DEFAULTS.contribInfo.foldingControls,
'description': nls.localize('foldingControls', "Controls the style of folding controls shown when folding is enabled.")
},
'editor.matchBrackets': {
'type': 'boolean',
'default': EDITOR_DEFAULTS.contribInfo.matchBrackets,
Expand Down
10 changes: 10 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,11 @@ export interface IEditorOptions {
* Defaults to 'mouseover'.
*/
showFoldingControls?: 'always' | 'mouseover';
/**
* Controls the style of folding controls shown when folding is enabled.
* Defaults to 'classic'.
*/
foldingControls?: 'classic' | 'top-bottom';
/**
* Enable highlighting of matching brackets.
* Defaults to true.
Expand Down Expand Up @@ -1036,6 +1041,7 @@ export interface EditorContribOptions {
readonly folding: boolean;
readonly foldingStrategy: 'auto' | 'indentation';
readonly showFoldingControls: 'always' | 'mouseover';
readonly foldingControls: 'classic' | 'top-bottom';
readonly matchBrackets: boolean;
readonly find: InternalEditorFindOptions;
readonly colorDecorators: boolean;
Expand Down Expand Up @@ -1463,6 +1469,7 @@ export class InternalEditorOptions {
&& a.folding === b.folding
&& a.foldingStrategy === b.foldingStrategy
&& a.showFoldingControls === b.showFoldingControls
&& a.foldingControls === b.foldingControls
&& a.matchBrackets === b.matchBrackets
&& this._equalFindOptions(a.find, b.find)
&& a.colorDecorators === b.colorDecorators
Expand Down Expand Up @@ -2118,6 +2125,7 @@ export class EditorOptionsValidator {
folding: _boolean(opts.folding, defaults.folding),
foldingStrategy: _stringSet<'auto' | 'indentation'>(opts.foldingStrategy, defaults.foldingStrategy, ['auto', 'indentation']),
showFoldingControls: _stringSet<'always' | 'mouseover'>(opts.showFoldingControls, defaults.showFoldingControls, ['always', 'mouseover']),
foldingControls: _stringSet<'classic' | 'top-bottom'>(opts.foldingControls, defaults.foldingControls, ['classic', 'top-bottom']),
matchBrackets: _boolean(opts.matchBrackets, defaults.matchBrackets),
find: find,
colorDecorators: _boolean(opts.colorDecorators, defaults.colorDecorators),
Expand Down Expand Up @@ -2232,6 +2240,7 @@ export class InternalEditorOptionsFactory {
folding: (accessibilityIsOn ? false : opts.contribInfo.folding), // DISABLED WHEN SCREEN READER IS ATTACHED
foldingStrategy: opts.contribInfo.foldingStrategy,
showFoldingControls: opts.contribInfo.showFoldingControls,
foldingControls: opts.contribInfo.foldingControls,
matchBrackets: (accessibilityIsOn ? false : opts.contribInfo.matchBrackets), // DISABLED WHEN SCREEN READER IS ATTACHED
find: opts.contribInfo.find,
colorDecorators: opts.contribInfo.colorDecorators,
Expand Down Expand Up @@ -2728,6 +2737,7 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
folding: true,
foldingStrategy: 'auto',
showFoldingControls: 'mouseover',
foldingControls: 'classic',
matchBrackets: true,
find: {
seedSearchStringFromSelection: true,
Expand Down
35 changes: 33 additions & 2 deletions src/vs/editor/contrib/folding/folding.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

.monaco-editor .margin-view-overlays .folding {
.monaco-editor .margin-view-overlays .folding,
.monaco-editor .margin-view-overlays .foldingEnd {
cursor: pointer;
background-repeat: no-repeat;
background-origin: border-box;
Expand All @@ -17,25 +18,55 @@
background-image: url('tree-expanded-light.svg');
}

.monaco-editor .margin-view-overlays .foldingEnd {
background-image: url('tree-expanded-end-light.svg');
}

.monaco-editor.hc-black .margin-view-overlays .folding,
.monaco-editor.vs-dark .margin-view-overlays .folding {
background-image: url('tree-expanded-dark.svg');
}

.monaco-editor.hc-black .margin-view-overlays .foldingEnd,
.monaco-editor.vs-dark .margin-view-overlays .foldingEnd {
background-image: url('tree-expanded-end-dark.svg');
}

.monaco-editor.hc-black .margin-view-overlays .folding {
background-image: url('tree-expanded-hc.svg');
}

.monaco-editor.hc-black .margin-view-overlays .foldingEnd {
background-image: url('tree-expanded-end-hc.svg');
}

.monaco-editor .margin-view-overlays:hover .folding,
.monaco-editor .margin-view-overlays .folding.alwaysShowFoldIcons {
opacity: 1;
}

.monaco-editor .margin-view-overlays:hover .foldingEnd,
.monaco-editor .margin-view-overlays .foldingEnd.alwaysShowFoldIcons {
opacity: .50;
}

.monaco-editor .margin-view-overlays:hover .foldingEnd:hover,
.monaco-editor .margin-view-overlays .foldingEnd.alwaysShowFoldIcons:hover {
opacity: 1;
}

.monaco-editor .margin-view-overlays .folding.collapsed {
background-image: url('tree-collapsed-light.svg');
opacity: 1;
}

.monaco-editor .margin-view-overlays .folding + .foldingEnd,
.monaco-editor .margin-view-overlays .foldingEnd.collapsed {
opacity: 0;
cursor: default;
z-index: -1;
}

.monaco-editor.vs-dark .margin-view-overlays .folding.collapsed {
background-image: url('tree-collapsed-dark.svg');
}
Expand All @@ -51,4 +82,4 @@
display: inline;
line-height: 1em;
cursor: pointer;
}
}
27 changes: 24 additions & 3 deletions src/vs/editor/contrib/folding/folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class FoldingController extends Disposable implements IEditorContribution

private readonly editor: ICodeEditor;
private _isEnabled: boolean;
private _isFoldFromEndEnabled: boolean;
private _autoHideFoldingControls: boolean;
private _useFoldingProviders: boolean;

Expand Down Expand Up @@ -87,6 +88,7 @@ export class FoldingController extends Disposable implements IEditorContribution
super();
this.editor = editor;
this._isEnabled = this.editor.getConfiguration().contribInfo.folding;
this._isFoldFromEndEnabled = this.editor.getConfiguration().contribInfo.foldingControls === 'top-bottom';
this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover';
this._useFoldingProviders = this.editor.getConfiguration().contribInfo.foldingStrategy !== 'indentation';

Expand All @@ -106,6 +108,11 @@ export class FoldingController extends Disposable implements IEditorContribution
if (oldIsEnabled !== this._isEnabled) {
this.onModelChanged();
}
let oldIsFoldFromEndEnabled = this._isFoldFromEndEnabled;
this._isFoldFromEndEnabled = this.editor.getConfiguration().contribInfo.foldingControls === 'top-bottom';
if (oldIsFoldFromEndEnabled !== this._isFoldFromEndEnabled) {
this.onModelChanged();
}
let oldShowFoldingControls = this._autoHideFoldingControls;
this._autoHideFoldingControls = this.editor.getConfiguration().contribInfo.showFoldingControls === 'mouseover';
if (oldShowFoldingControls !== this._autoHideFoldingControls) {
Expand Down Expand Up @@ -182,7 +189,7 @@ export class FoldingController extends Disposable implements IEditorContribution
return;
}

this.foldingModel = new FoldingModel(model, this.foldingDecorationProvider);
this.foldingModel = new FoldingModel(model, this.foldingDecorationProvider, this._isFoldFromEndEnabled);
this.localToDispose.add(this.foldingModel);

this.hiddenRangeModel = new HiddenRangeModel(this.foldingModel);
Expand Down Expand Up @@ -412,15 +419,29 @@ export class FoldingController extends Disposable implements IEditorContribution
foldingModel.then(foldingModel => {
if (foldingModel) {
let region = foldingModel.getRegionAtLine(lineNumber);
if (region && region.startLineNumber === lineNumber) {
let isEnd = false;

if (this._isFoldFromEndEnabled && ((region && region.startLineNumber !== lineNumber) || region === null)) {
lineNumber -= 1;
region = foldingModel.getTopEndRegionAtLine(lineNumber);

isEnd = region !== null && (region.endLineNumber === lineNumber);
}

if (region && (region.startLineNumber === lineNumber || isEnd)) {
let isCollapsed = region.isCollapsed;

if (isCollapsed && isEnd) {
return;
}

if (iconClicked || isCollapsed) {
let toToggle = [region];
if (e.event.middleButton || e.event.shiftKey) {
toToggle.push(...foldingModel.getRegionsInside(region, r => r.isCollapsed === isCollapsed));
}
foldingModel.toggleCollapseState(toToggle);
this.reveal({ lineNumber, column: 1 });
this.reveal({ lineNumber: region.startLineNumber, column: 1 });
}
}
}
Expand Down
38 changes: 33 additions & 5 deletions src/vs/editor/contrib/folding/foldingDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,46 @@ export class FoldingDecorationProvider implements IDecorationProvider {
linesDecorationsClassName: 'folding alwaysShowFoldIcons'
});

private static COLLAPSED_VISUAL_DECORATION_END = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
linesDecorationsClassName: 'foldingEnd collapsed'
});

private static EXPANDED_AUTO_HIDE_VISUAL_DECORATION_END = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
linesDecorationsClassName: 'foldingEnd'
});

private static EXPANDED_VISUAL_DECORATION_END = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
linesDecorationsClassName: 'foldingEnd alwaysShowFoldIcons'
});

private static VISUAL_DECORATION_HIDDEN = ModelDecorationOptions.register({
stickiness: TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
linesDecorationsClassName: ''
});

public autoHideFoldingControls: boolean = true;

constructor(private readonly editor: ICodeEditor) {
}

getDecorationOption(isCollapsed: boolean): ModelDecorationOptions {
if (isCollapsed) {
return FoldingDecorationProvider.COLLAPSED_VISUAL_DECORATION;
getDecorationOption(isCollapsed: boolean, isEnd: boolean = false, isHidden: boolean = false): ModelDecorationOptions {
if (isHidden) {
return FoldingDecorationProvider.VISUAL_DECORATION_HIDDEN;
} else if (isCollapsed) {
return isEnd ?
FoldingDecorationProvider.COLLAPSED_VISUAL_DECORATION_END :
FoldingDecorationProvider.COLLAPSED_VISUAL_DECORATION;
} else if (this.autoHideFoldingControls) {
return FoldingDecorationProvider.EXPANDED_AUTO_HIDE_VISUAL_DECORATION;
return isEnd ?
FoldingDecorationProvider.EXPANDED_AUTO_HIDE_VISUAL_DECORATION_END :
FoldingDecorationProvider.EXPANDED_AUTO_HIDE_VISUAL_DECORATION;
} else {
return FoldingDecorationProvider.EXPANDED_VISUAL_DECORATION;
return isEnd ?
FoldingDecorationProvider.EXPANDED_VISUAL_DECORATION_END :
FoldingDecorationProvider.EXPANDED_VISUAL_DECORATION;
}
}

Expand Down
Loading