-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Cleaner fix for #2761 (Project tree selection incorrect after opening file by means other than sidebar) #3398
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,17 +195,32 @@ define(function (require, exports, module) { | |
function _documentSelectionFocusChange() { | ||
var curDoc = DocumentManager.getCurrentDocument(); | ||
if (curDoc && _hasFileSelectionFocus()) { | ||
$("#project-files-container li").is(function (index) { | ||
var entry = $(this).data("entry"); | ||
if (entry && entry.fullPath === curDoc.file.fullPath && !_projectTree.jstree("is_selected", $(this))) { | ||
//we don't want to trigger another selection change event, so manually deselect | ||
//and select without sending out notifications | ||
_projectTree.jstree("deselect_all"); | ||
_projectTree.jstree("select_node", $(this), false); | ||
var nodeFound = $("#project-files-container li").is(function (index) { | ||
var $treeNode = $(this), | ||
entry = $treeNode.data("entry"); | ||
if (entry && entry.fullPath === curDoc.file.fullPath) { | ||
if (!_projectTree.jstree("is_selected", $treeNode)) { | ||
if ($treeNode.parents(".jstree-closed").length) { | ||
//don't auto-expand tree to show file - but remember it if parent is manually expanded later | ||
_projectTree.jstree("deselect_all"); | ||
_lastSelected = $treeNode; | ||
} else { | ||
//we don't want to trigger another selection change event, so manually deselect | ||
//and select without sending out notifications | ||
_projectTree.jstree("deselect_all"); | ||
_projectTree.jstree("select_node", $treeNode, false); // sets _lastSelected | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
}); | ||
|
||
// file is outside project subtree, or in a folder that's never been expanded yet | ||
if (!nodeFound) { | ||
_projectTree.jstree("deselect_all"); | ||
_lastSelected = null; | ||
} | ||
} else if (_projectTree !== null) { | ||
_projectTree.jstree("deselect_all"); | ||
_lastSelected = null; | ||
|
@@ -915,11 +930,8 @@ define(function (require, exports, module) { | |
function showInTree(entry) { | ||
return _findTreeNode(entry) | ||
.done(function ($node) { | ||
_projectTree.jstree("deselect_node", _lastSelected); | ||
_lastSelected = null; | ||
_projectTree.jstree("select_node", $node); | ||
_lastSelected = $node; | ||
_redraw(true, true); | ||
// jsTree will automatically expand parent nodes to ensure visible | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this comment: "jsTree will automatically expand parent nodes to ensure visible". Isn't that what your fix is trying to avoid ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that's restoring the previous code. Maybe that comment is incorrect? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that's correct -- that is what this code does, but this code is no longer invoked when you click a Find in Files result (see deletion in FindInFiles.js). This is now only invoked by the 'Show in File Tree' command. |
||
_projectTree.jstree("select_node", $node, false); | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the comment in this block, I tried this:
Result:
Folder expands. File is not visibly selected.
Expected:
File in editor to be selected in file tree once it becomes exposed
Should that be expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not ideal... but would you mind spinning that off as a separate bug? I fixed one similar bug as part of this pull request (see cases in unit tests), but I think these are basically separate issues from #2761.
#2761 was about a much more confusing issue -- a file is highlighted in the tree but it's not the file shown in the editor. In this case we just leave the folder highlighted, which is far less likely to be confusing. (And we already have a number of cases where a folder is even expected to be highlighted in the tree instead of the file that's open, so it's probably something users will have seen before).