Skip to content

Commit

Permalink
Fix #712 When clicking in a scrolled tree for the first time, focus i…
Browse files Browse the repository at this point in the history
…s not set properly
  • Loading branch information
mar10 committed Aug 26, 2017
1 parent 0eb1ad3 commit d8d6e53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 1 addition & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand All @@ -16,16 +17,13 @@ indent_size = 2

[*.js]
indent_style = tab
indent_size = 4

[*.coffee]
indent_style = space
indent_size = 2

[*.md]
indent_style = space
indent_size = 4

[*.py]
indent_style = space
indent_size = 4
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* [Fixed] #761: dnd5 throws exception when tree is empty
* Updated jsdoc to 3.5

# Branch click-folder
* Undo commit #712 / #713 to fix regressions #748, #763, #764

# 2.23.0 / 2017-05-27
* **The external dependency on jQuery UI was removed**.
A new library `jquery.fancytree-all-deps.min.js` is now added to the
Expand Down
21 changes: 15 additions & 6 deletions src/jquery.fancytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,7 @@ function Fancytree(widget) {
this.activeNode = null;
this.focusNode = null;
this._hasFocus = null;
this._lastMousedownNode = null;
this._enableUpdate = true;
// this._dirtyRoots = null;
this.lastSelectedNode = null;
Expand Down Expand Up @@ -4375,6 +4376,8 @@ $.extend(Fancytree.prototype,
* @param {boolean} [flag=true]
*/
treeSetFocus: function(ctx, flag, callOpts) {
var targetNode;

flag = (flag !== false);

// this.debug("treeSetFocus(" + flag + "), callOpts: ", callOpts, this.hasFocus());
Expand All @@ -4391,7 +4394,8 @@ $.extend(Fancytree.prototype,
this.$container.toggleClass("fancytree-treefocus", flag);
this._triggerTreeEvent(flag ? "focusTree" : "blurTree");
if( flag && !this.activeNode ) {
this.getFirstChild() && this.getFirstChild().setFocus();
targetNode = this._lastMousedownNode || this.getFirstChild();
targetNode && targetNode.setFocus();
}
}
},
Expand Down Expand Up @@ -4658,10 +4662,12 @@ $.widget("ui.fancytree",
}else{
tree._callHook("treeSetFocus", tree, flag);
}

}).on("selectstart" + ns, "span.fancytree-title", function(event){
// prevent mouse-drags to select text ranges
// tree.debug("<span title> got event " + event.type);
event.preventDefault();

}).on("keydown" + ns, function(event){
// TODO: also bind keyup and keypress
// tree.debug("got event " + event.type + ", hasFocus:" + tree.hasFocus());
Expand Down Expand Up @@ -4692,8 +4698,14 @@ $.widget("ui.fancytree",
} finally {
tree.phase = prevPhase;
}

}).on("mousedown" + ns, function(event){
// #412: store the clicked node, so we can use it when we get a focusin event
var et = FT.getEventTarget(event);
that.tree.debug("event(" + event.type + "): node: ", et.node);
that.tree._lastMousedownNode = et ? et.node : null;

}).on("click" + ns + " dblclick" + ns, function(event){
// that.tree.debug("event(" + event + "): !");
if(opts.disabled){
return true;
}
Expand All @@ -4703,7 +4715,7 @@ $.widget("ui.fancytree",
tree = that.tree,
prevPhase = tree.phase;

// that.tree.debug("event(" + event.type + "): node: ", node);
that.tree.debug("event(" + event.type + "): node: ", node);
if( !node ){
return true; // Allow bubbling of other events
}
Expand All @@ -4722,9 +4734,6 @@ $.widget("ui.fancytree",
ctx.targetType = et.type;
return ( tree._triggerNodeEvent("dblclick", ctx, event) === false ) ? false : tree._callHook("nodeDblclick", ctx);
}
// } catch(e) {
// // var _ = null; // DT issue 117 // TODO
// $.error(e);
} finally {
tree.phase = prevPhase;
}
Expand Down

0 comments on commit d8d6e53

Please sign in to comment.