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

Commit a9c6e52

Browse files
committed
Merge pull request #9353 from adobe/dangoor/9316-rename-collapse
File tree: properly handle clicks on nested files and directories
2 parents 48ae54f + db383a1 commit a9c6e52

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/project/FileTreeView.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ define(function (require, exports, module) {
9595
* and invoking the correct action based on that input.
9696
*/
9797
var renameBehavior = {
98+
/**
99+
* Stop clicks from propagating so that clicking on the rename input doesn't
100+
* cause directories to collapse.
101+
*/
102+
handleClick: function (e) {
103+
e.stopPropagation();
104+
if (e.button !== LEFT_MOUSE_BUTTON) {
105+
return false;
106+
}
107+
return true;
108+
},
109+
98110
/**
99111
* If the user presses enter or escape, we either successfully complete or cancel, respectively,
100112
* the rename or create operation that is underway.
@@ -169,12 +181,13 @@ define(function (require, exports, module) {
169181
var width = _measureText(this.props.name);
170182

171183
return DOM.input({
172-
className: "jstree-rename-input " + this.props.fileClasses,
184+
className: "jstree-rename-input",
173185
type: "text",
174186
defaultValue: this.props.name,
175187
autoFocus: true,
176188
onKeyDown: this.handleKeyDown,
177189
onKeyUp: this.handleKeyUp,
190+
onClick: this.handleClick,
178191
onBlur: this.handleBlur,
179192
style: {
180193
width: width
@@ -432,8 +445,7 @@ define(function (require, exports, module) {
432445
actions: this.props.actions,
433446
entry: this.props.entry,
434447
name: this.props.name,
435-
parentPath: this.props.parentPath,
436-
fileClasses: fileClasses
448+
parentPath: this.props.parentPath
437449
});
438450
} else {
439451
// Need to flatten the argument list because getIcons returns an array
@@ -530,10 +542,11 @@ define(function (require, exports, module) {
530542
onKeyDown: this.handleKeyDown,
531543
onKeyUp: this.handleKeyUp,
532544
onBlur: this.handleBlur,
533-
ref: "name",
534545
style: {
535546
width: width
536-
}
547+
},
548+
onClick: this.handleClick,
549+
ref: "name"
537550
});
538551
}
539552
});
@@ -646,22 +659,26 @@ define(function (require, exports, module) {
646659
directoryClasses += " context-node";
647660
}
648661

649-
var nameDisplay;
662+
var nameDisplay, renameInput;
650663
if (entry.get("rename")) {
651-
nameDisplay = directoryRenameInput({
664+
renameInput = directoryRenameInput({
652665
actions: this.props.actions,
653666
entry: this.props.entry,
654667
name: this.props.name,
655668
parentPath: this.props.parentPath
656669
});
657-
} else {
658-
// Need to flatten the arguments because getIcons returns an array
659-
var aArgs = _.flatten([{
660-
href: "#",
661-
className: directoryClasses
662-
}, this.getIcons(), this.props.name], true);
663-
nameDisplay = DOM.a.apply(DOM.a, aArgs);
664670
}
671+
672+
// Need to flatten the arguments because getIcons returns an array
673+
var aArgs = _.flatten([{
674+
href: "#",
675+
className: directoryClasses
676+
}, this.getIcons()], true);
677+
if (!entry.get("rename")) {
678+
aArgs.push(this.props.name);
679+
}
680+
681+
nameDisplay = DOM.a.apply(DOM.a, aArgs);
665682

666683
return DOM.li({
667684
className: this.getClasses("jstree-" + nodeClass),
@@ -671,6 +688,7 @@ define(function (require, exports, module) {
671688
DOM.ins({
672689
className: "jstree-icon"
673690
}, " "),
691+
renameInput,
674692
nameDisplay,
675693
childNodes);
676694
}

src/project/ProjectManager.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ define(function (require, exports, module) {
11311131
model.setSelectionWidth($projectTreeContainer.width());
11321132

11331133
$(".main-view").click(function (jqEvent) {
1134-
if (jqEvent.target.className !== "jstree-rename-input") {
1134+
if (!jqEvent.target.classList.contains("jstree-rename-input")) {
11351135
forceFinishRename();
11361136
actionCreator.setContext(null);
11371137
}

src/styles/jsTreeTheme.less

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
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; }
34-
.jstree ins { display:inline-block; text-decoration:none; width:18px; height:18px; margin:0 0 0 0; padding:0; } +
35-
.jstree a { display:inline-block; line-height:16px; height:16px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; }
34+
.jstree ins { display:inline-block; text-decoration:none; width:18px; height:18px; margin:0 0 0 0; padding:0; }
3635
.jstree a:focus { outline: none; }
3736
.jstree a > ins { height:16px; width:16px; }
3837
.jstree a > .jstree-icon { margin-right:3px; }

0 commit comments

Comments
 (0)