Skip to content

Commit

Permalink
Fixes microsoft#3296: [folding] Folding icons should not operate on m…
Browse files Browse the repository at this point in the history
…ouse-down
  • Loading branch information
aeschli committed Feb 25, 2016
1 parent a87b674 commit bf81d1e
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions src/vs/editor/contrib/folding/browser/folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ export class FoldingController implements editorCommon.IEditorContribution {
this.decorations = [];
this.updateHiddenAreas();
}});
this.localToDispose.push(this.editor.addListener2(editorCommon.EventType.MouseDown, (e) => this._onEditorMouseDown(e)));
this.localToDispose.push(this.editor.addListener2(editorCommon.EventType.MouseDown, e => this._onEditorMouseDown(e)));
this.localToDispose.push(this.editor.addListener2(editorCommon.EventType.MouseUp, e => this._onEditorMouseUp(e)));

this.updateScheduler.schedule();
}
Expand All @@ -320,7 +321,11 @@ export class FoldingController implements editorCommon.IEditorContribution {
return TPromise.as(ranges);
}

private _mouseDownInfo: { lineNumber: number, iconClicked: boolean };

private _onEditorMouseDown(e: IEditorMouseEvent): void {
this._mouseDownInfo = null;

if (this.decorations.length === 0) {
return;
}
Expand All @@ -334,10 +339,10 @@ export class FoldingController implements editorCommon.IEditorContribution {

let model = this.editor.getModel();

let toggleClicked = false;
let iconClicked = false;
switch (e.target.type) {
case editorCommon.MouseTargetType.GUTTER_LINE_DECORATIONS:
toggleClicked = true;
iconClicked = true;
break;
case editorCommon.MouseTargetType.CONTENT_TEXT:
if (range.isEmpty && range.startColumn === model.getLineMaxColumn(range.startLineNumber)) {
Expand All @@ -348,26 +353,46 @@ export class FoldingController implements editorCommon.IEditorContribution {
return;
}

let hasChanges = false;
this._mouseDownInfo = { lineNumber: range.startLineNumber, iconClicked};
}

private _onEditorMouseUp(e: IEditorMouseEvent): void {
if (!this._mouseDownInfo) {
return;
}
let lineNumber = this._mouseDownInfo.lineNumber;
let iconClicked = this._mouseDownInfo.iconClicked;

let range = e.target.range;
if (!range || !range.isEmpty || range.startLineNumber !== lineNumber) {
return;
}

let model = this.editor.getModel();

if (iconClicked) {
if (e.target.type !== editorCommon.MouseTargetType.GUTTER_LINE_DECORATIONS) {
return;
}
} else {
if (range.startColumn !== model.getLineMaxColumn(range.startLineNumber)) {
return;
}
}

this.editor.changeDecorations(changeAccessor => {
for (let i = 0; i < this.decorations.length; i++) {
let dec = this.decorations[i];
let decRange = dec.getDecorationRange(model);
if (decRange.startLineNumber === range.startLineNumber) {
if (toggleClicked || dec.isCollapsed) {
if (decRange.startLineNumber === lineNumber) {
if (iconClicked || dec.isCollapsed) {
dec.setCollapsed(!dec.isCollapsed, changeAccessor);
hasChanges = true;
this.updateHiddenAreas();
}
break;
return;
}
}
});

if (hasChanges) {
this.updateHiddenAreas();
}

}

private updateHiddenAreas(): void {
Expand Down

0 comments on commit bf81d1e

Please sign in to comment.