Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Changes from 2 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
43 changes: 43 additions & 0 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,50 @@ define(function (require, exports, module) {
// install scroller shadows
ViewUtils.addScrollerShadow(_projectTree.get(0));

var findEventHandler = function (type, namespace, selector) {
var events = $._data(_projectTree[0], "events"),
eventsForType = events ? events[type] : null,
event = eventsForType ? _.find(eventsForType, function (e) {
return e.namespace === namespace && e.selector === selector;
}) : null,
eventHandler = event ? event.handler : null;
if (!eventHandler) {
console.error(type + "." + namespace + " " + selector + " handler not found!");
}
return eventHandler;
};
var createCustomHandler = function(originalHandler) {
return function (event) {
var $node = $(event.target).parent("li");
if (event.ctrlKey || event.metaKey) {
if (event.altKey) {
// collapse subtree
// note: expanding using open_all is a bad idea due to poor performance
if ($node.is(".jstree-open")) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the other part of my confusion was that cmd+alt doesn't open all. If there is a performance hit with open all then let's just open the node that was clicked on as if alt wasn't pressed.

_projectTree.jstree("close_all", $node);
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return true 'cause we handled the event. Same below.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not returning to anything, it is just used so that it doesn't drop into the original behavior case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zaggino the if (event.altKey)... branch doesn't seem to do anything differently than without using the ctrl key. I'm not sure what it's supposed to do but, after using it, it felt like ctrl+click doesn't work anymore.

/cc: @larz0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the intended behaviour:

ctrl+click willl expand - collapse all siblings of the one that has been clicked

ctrl+alt+click will collapse just the one tree clicked, and all of its children (it doesn't work reverse for expand because it's slow)

point is if I have a tree open like

a
    -b
         -b1
         -b2
         -b3
    -c
         -c1
              -cc1
    -d

clicking ctrl+alt on a will cause all children to collapse, so if I open a again, I'll see only b,c,d and not b1,b2,b3,c1,cc1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh... I think I understand the problem now. You need to handle clicking on the label too not just the disclosure triangle. Alt+clicking on the label is handled by jstree and feels somewhat unpredictable.

}
} else {
// toggle siblings
var methodName = $node.is(".jstree-open") ? "close_node" : "open_node";
$node.parent().children("li").each(function () {
_projectTree.jstree(methodName, $(this));
});
return;
}
}
// original behaviour
originalHandler.apply(this, arguments);
};
};
var originalHrefHandler = findEventHandler("click", "jstree", "a");
var originalInsHandler = findEventHandler("click", "jstree", "li > ins");

_projectTree
.off("click.jstree", "a")
.on("click.jstree", "a", createCustomHandler(originalHrefHandler))
.off("click.jstree", "li > ins")
.on("click.jstree", "li > ins", createCustomHandler(originalInsHandler))
.unbind("dblclick.jstree")
.bind("dblclick.jstree", function (event) {
var entry = $(event.target).closest("li").data("entry");
Expand Down