Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 4d2c4bf

Browse files
committed
Simulate indentation of the project tree using some divs
instead of using combinations of padding/margin. Fixes #10574
1 parent 239c937 commit 4d2c4bf

3 files changed

Lines changed: 65 additions & 24 deletions

File tree

src/project/FileTreeView.js

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ define(function (require, exports, module) {
5959
var CLICK_RENAME_MINIMUM = 500,
6060
RIGHT_MOUSE_BUTTON = 2,
6161
LEFT_MOUSE_BUTTON = 0;
62+
63+
var INDENTATION_WIDTH = 18;
6264

6365
/**
6466
* @private
@@ -108,6 +110,40 @@ define(function (require, exports, module) {
108110
return width;
109111
}
110112

113+
/**
114+
* @private
115+
*
116+
* Create an appropriate div based thickness to indent the tree correctly.
117+
*
118+
* @param {int} depth - The depthness of the current node.
119+
* @return {ReactComponent} - The resulting div.
120+
*/
121+
function _createThickness(depth) {
122+
return DOM.div({
123+
className: "thickness",
124+
style: {
125+
width: (INDENTATION_WIDTH * depth) + "px"
126+
}
127+
});
128+
}
129+
130+
/**
131+
* @private
132+
*
133+
* Create the arrow icons used for the folders indented correctly.
134+
*
135+
* @param {int} depth - The depthness of the current node.
136+
* @return {ReactComponent} - The resulting ins.
137+
*/
138+
function _createAlignedIns(depth) {
139+
return DOM.ins({
140+
className: "jstree-icon",
141+
style: {
142+
marginLeft: (INDENTATION_WIDTH * depth) + "px"
143+
}
144+
}, " ");
145+
}
146+
111147
/**
112148
* This is a mixin that provides rename input behavior. It is responsible for taking keyboard input
113149
* and invoking the correct action based on that input.
@@ -457,32 +493,40 @@ define(function (require, exports, module) {
457493
'context-node': this.props.entry.get("context")
458494
});
459495

496+
var liArgs = [
497+
{
498+
className: this.getClasses("jstree-leaf"),
499+
onClick: this.handleClick,
500+
onMouseDown: this.handleMouseDown,
501+
onDoubleClick: this.handleDoubleClick
502+
},
503+
DOM.ins({
504+
className: "jstree-icon"
505+
}, " "),
506+
];
507+
var thickness = _createThickness(this.props.depth);
508+
460509
if (this.props.entry.get("rename")) {
461510
nameDisplay = fileRenameInput({
462511
actions: this.props.actions,
463512
entry: this.props.entry,
464513
name: this.props.name,
465514
parentPath: this.props.parentPath
466515
});
516+
517+
liArgs.push(thickness);
467518
} else {
468519
// Need to flatten the argument list because getIcons returns an array
469520
var aArgs = _.flatten([{
470521
href: "#",
471522
className: fileClasses
472-
}, this.getIcons(), name, extension]);
523+
}, thickness, this.getIcons(), name, extension]);
473524
nameDisplay = DOM.a.apply(DOM.a, aArgs);
474525
}
475526

476-
return DOM.li({
477-
className: this.getClasses("jstree-leaf"),
478-
onClick: this.handleClick,
479-
onMouseDown: this.handleMouseDown,
480-
onDoubleClick: this.handleDoubleClick
481-
},
482-
DOM.ins({
483-
className: "jstree-icon"
484-
}, " "),
485-
nameDisplay);
527+
liArgs.push(nameDisplay);
528+
529+
return DOM.li.apply(DOM.li, liArgs);
486530
}
487531
}));
488532

@@ -668,6 +712,7 @@ define(function (require, exports, module) {
668712
if (isOpen && children) {
669713
nodeClass = "open";
670714
childNodes = directoryContents({
715+
depth: this.props.depth + 1,
671716
parentPath: this.myPath(),
672717
contents: children,
673718
extensions: this.props.extensions,
@@ -698,11 +743,13 @@ define(function (require, exports, module) {
698743
});
699744
}
700745

746+
var thickness = _createThickness(this.props.depth);
747+
701748
// Need to flatten the arguments because getIcons returns an array
702749
var aArgs = _.flatten([{
703750
href: "#",
704751
className: directoryClasses
705-
}, this.getIcons()]);
752+
}, thickness, this.getIcons()]);
706753
if (!entry.get("rename")) {
707754
aArgs.push(this.props.name);
708755
}
@@ -714,9 +761,7 @@ define(function (require, exports, module) {
714761
onClick: this.handleClick,
715762
onMouseDown: this.handleMouseDown
716763
},
717-
DOM.ins({
718-
className: "jstree-icon"
719-
}, " "),
764+
_createAlignedIns(this.props.depth),
720765
renameInput,
721766
nameDisplay,
722767
childNodes);
@@ -764,6 +809,7 @@ define(function (require, exports, module) {
764809

765810
if (FileTreeViewModel.isFile(entry)) {
766811
return fileNode({
812+
depth: this.props.depth,
767813
parentPath: this.props.parentPath,
768814
name: name,
769815
entry: entry,
@@ -775,6 +821,7 @@ define(function (require, exports, module) {
775821
});
776822
} else {
777823
return directoryNode({
824+
depth: this.props.depth,
778825
parentPath: this.props.parentPath,
779826
name: name,
780827
entry: entry,
@@ -977,6 +1024,7 @@ define(function (require, exports, module) {
9771024
}),
9781025
contents = directoryContents({
9791026
isRoot: true,
1027+
depth: 1,
9801028
parentPath: this.props.parentPath,
9811029
sortDirectoriesFirst: this.props.sortDirectoriesFirst,
9821030
contents: this.props.treeData,

src/styles/brackets.less

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,6 @@ a, img {
10091009
#project-files-container {
10101010
.box-flex(1);
10111011

1012-
ul {
1013-
padding-left: 8px;
1014-
}
1015-
10161012
> ul {
10171013
padding-bottom: 24px;
10181014
}

src/styles/jsTreeTheme.less

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@li-min-height: 23px;
2828

2929
.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; }
30-
.jstree li { display:block; min-height:@li-min-height; line-height:16px; white-space:nowrap; margin-left:18px; min-width:18px; }
30+
.jstree li { display:block; min-height:@li-min-height; line-height:16px; white-space:nowrap; min-width:18px; }
3131
.jstree-rtl li { margin-left:0; margin-right:18px; }
3232
.jstree > ul > li { margin-left:0px; }
3333
.jstree-rtl > ul > li { margin-right:0px; }
@@ -46,6 +46,7 @@ li.jstree-closed > ul { display:none; }
4646
.jstree-brackets .jstree-open > ins { background-position:-72px 0; }
4747
.jstree-brackets .jstree-closed > ins { background-position:-54px 0; }
4848
.jstree-brackets .jstree-leaf > ins { background-position:-36px 0; }
49+
.jstree-brackets .thickness { display: inline-block; }
4950

5051
.jstree-brackets li a:hover {
5152
text-decoration: none;
@@ -86,14 +87,10 @@ li.jstree-closed > ul { display:none; }
8687
color: @project-panel-text-2;
8788
}
8889
&.jstree-closed, &.jstree-open {
89-
margin-left: 10px;
9090
> a {
9191
color: @project-panel-text-2;
9292
}
9393
}
94-
&.jstree-leaf {
95-
margin-left: 10px;
96-
}
9794
}
9895

9996
.jstree ins {

0 commit comments

Comments
 (0)