Skip to content

Commit 5c27378

Browse files
committed
Fix quicksearch for non-Latin character
Close mar10#909
1 parent 7dd753d commit 5c27378

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [Fixed] #896 _requireExtension: order managment
66
* [Fixed] #899 Creating duplicate icon when removing node using extension columnview
77
* [Fixed] #900 ColumnView Extension - Toggle between parent and children not working
8+
* [Fixed] #909 With quicksearch enabled, does not search for non-Latin character
89

910
# 2.30.0 / 2018-09-02
1011
* [Changed] ext-edit trigger 'clickActive' now only triggers if no modifier keys

src/jquery.fancytree.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
9: "tab",
6262
10: "return",
6363
13: "return",
64-
// 16: null, 17: null, 18: null, // ignore shift, ctrl, alt
64+
// 16: null, 17: null, 18: null, // ignore shift, ctrl, alt
6565
19: "pause",
6666
20: "capslock",
6767
27: "esc",
@@ -78,6 +78,7 @@
7878
46: "del",
7979
59: ";",
8080
61: "=",
81+
// 91: null, 93: null, // ignore left and right meta
8182
96: "0",
8283
97: "1",
8384
98: "2",
@@ -120,6 +121,13 @@
120121
221: "]",
121122
222: "'",
122123
},
124+
MODIFIERS = {
125+
16: "shift",
126+
17: "ctrl",
127+
18: "alt",
128+
91: "meta",
129+
93: "meta",
130+
},
123131
MOUSE_BUTTONS = { 0: "", 1: "left", 2: "middle", 3: "right" },
124132
// Boolean attributes that can be set with equivalent class names in the LI tags
125133
// Note: v2.23: checkbox and hideCheckbox are *not* in this list
@@ -3805,8 +3813,8 @@
38053813
ctx.targetType === "title" &&
38063814
ctx.options.clickFolderMode === 4
38073815
) {
3808-
// this.nodeSetFocus(ctx);
3809-
// this._callHook("nodeSetActive", ctx, true);
3816+
// this.nodeSetFocus(ctx);
3817+
// this._callHook("nodeSetActive", ctx, true);
38103818
this._callHook("nodeToggleExpanded", ctx);
38113819
}
38123820
// TODO: prevent text selection on dblclicks
@@ -3830,19 +3838,18 @@
38303838
tree = ctx.tree,
38313839
opts = ctx.options,
38323840
which = event.which,
3833-
whichChar = String.fromCharCode(which),
3834-
clean = !(
3835-
event.altKey ||
3836-
event.ctrlKey ||
3837-
event.metaKey ||
3838-
event.shiftKey
3839-
),
3841+
// #909: Use event.key, to get unicode characters.
3842+
// We can't use `/\w/.test(key)`, because that would
3843+
// only detect plain ascii alpha-numerics. But we still need
3844+
// to ignore modifier-only, whitespace, cursor-keys, etc.
3845+
key = event.key || String.fromCharCode(which),
3846+
isAlnum = !MODIFIERS[which] && !SPECIAL_KEYCODES[which],
38403847
$target = $(event.target),
38413848
handled = true,
38423849
activate = !(event.ctrlKey || !opts.autoActivate);
38433850

38443851
// (node || FT).debug("ftnode.nodeKeydown(" + event.type + "): ftnode:" + this + ", charCode:" + event.charCode + ", keyCode: " + event.keyCode + ", which: " + event.which);
3845-
// FT.debug("eventToString", which, '"' + String.fromCharCode(which) + '"', '"' + FT.eventToString(event) + '"');
3852+
// FT.debug( "eventToString(): " + FT.eventToString(event) + ", key='" + key + "', isAlnum: " + isAlnum );
38463853

38473854
// Set focus to active (or first node) if no other node has the focus yet
38483855
if (!node) {
@@ -3856,9 +3863,7 @@
38563863

38573864
if (
38583865
opts.quicksearch &&
3859-
clean &&
3860-
/\w/.test(whichChar) &&
3861-
!SPECIAL_KEYCODES[which] && // #659
3866+
isAlnum &&
38623867
!$target.is(":input:enabled")
38633868
) {
38643869
// Allow to search for longer streaks if typed in quickly
@@ -3867,7 +3872,7 @@
38673872
tree.lastQuicksearchTerm = "";
38683873
}
38693874
tree.lastQuicksearchTime = stamp;
3870-
tree.lastQuicksearchTerm += whichChar;
3875+
tree.lastQuicksearchTerm += key;
38713876
// tree.debug("quicksearch find", tree.lastQuicksearchTerm);
38723877
matchNode = tree.findNextNode(
38733878
tree.lastQuicksearchTerm,

0 commit comments

Comments
 (0)