Skip to content

Commit 2dbb2cf

Browse files
committed
fix(kubectl-ctx): fix namespace mouse click not working during search
1 parent bc0d791 commit 2dbb2cf

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

kubectl-ctx/Panel.qml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ Item {
2121
target: root.main
2222
function onActiveContextChanged() {
2323
nsDropdown.visible = false;
24-
nsFilterText = "";
24+
nsSearchInput.clearSearch();
2525
}
2626
}
2727

2828
property string nsFilterText: ""
2929
property int nsHighlightIndex: 0
3030

31-
function nsFiltered() {
32-
return (main?.namespaces ?? []).filter(n =>
33-
n.toLowerCase().includes(root.nsFilterText.toLowerCase()));
31+
readonly property var nsFilteredList: {
32+
var all = main?.namespaces ?? [];
33+
var q = root.nsFilterText.toLowerCase();
34+
return q === "" ? all : all.filter(n => n.toLowerCase().includes(q));
3435
}
3536

3637
function nsSelectHighlighted() {
37-
var list = root.nsFiltered();
38+
var list = root.nsFilteredList;
3839
if (list.length === 0) return;
3940
var idx = Math.max(0, Math.min(root.nsHighlightIndex, list.length - 1));
4041
nsDropdown.visible = false;
41-
root.nsFilterText = "";
42-
root.nsHighlightIndex = 0;
42+
nsSearchInput.clearSearch();
4343
if (main) main.switchNamespace(list[idx]);
4444
}
4545

@@ -295,9 +295,8 @@ Item {
295295
Qt.callLater(function() {
296296
if (nsSearchInput.inputItem) nsSearchInput.inputItem.forceActiveFocus();
297297
});
298-
} else {
299-
root.nsFilterText = "";
300-
root.nsHighlightIndex = 0;
298+
} else {
299+
nsSearchInput.clearSearch();
301300
}
302301
}
303302
}
@@ -313,32 +312,35 @@ Item {
313312
id: nsSearchInput
314313
Layout.fillWidth: true
315314
placeholderText: pluginApi?.tr("panel.nsSearch")
316-
text: root.nsFilterText
317315
onTextChanged: {
318316
root.nsFilterText = text;
319317
root.nsHighlightIndex = 0;
320318
}
319+
function clearSearch() {
320+
root.nsFilterText = "";
321+
root.nsHighlightIndex = 0;
322+
text = "";
323+
}
321324
Keys.onUpPressed: {
322325
root.nsHighlightIndex = Math.max(0, root.nsHighlightIndex - 1);
323326
}
324327
Keys.onDownPressed: {
325-
var max = root.nsFiltered().length - 1;
328+
var max = root.nsFilteredList.length - 1;
326329
root.nsHighlightIndex = Math.min(max, root.nsHighlightIndex + 1);
327330
}
328331
Keys.onReturnPressed: root.nsSelectHighlighted()
329332
Keys.onEnterPressed: root.nsSelectHighlighted()
330333
Keys.onEscapePressed: {
331334
nsDropdown.visible = false;
332-
root.nsFilterText = "";
333-
root.nsHighlightIndex = 0;
335+
nsSearchInput.clearSearch();
334336
}
335337
}
336338

337339
NScrollView {
338340
id: nsListScroll
339341
Layout.fillWidth: true
340342
Layout.preferredHeight: {
341-
var filtered = root.nsFiltered();
343+
var filtered = root.nsFilteredList;
342344
var count = filtered.length;
343345
if (count === 0) return Math.round(32 * Style.uiScaleRatio);
344346
var rowH = nsListColumn.children.length > 0
@@ -347,15 +349,15 @@ Item {
347349
return Math.min(count, 4) * rowH;
348350
}
349351
horizontalPolicy: ScrollBar.AlwaysOff
350-
verticalPolicy: root.nsFiltered().length > 4 ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
352+
verticalPolicy: root.nsFilteredList.length > 4 ? ScrollBar.AsNeeded : ScrollBar.AlwaysOff
351353

352354
ColumnLayout {
353355
id: nsListColumn
354356
width: nsListScroll.availableWidth
355357
spacing: 0
356358

357359
Repeater {
358-
model: root.nsFiltered()
360+
model: root.nsFilteredList
359361
delegate: ContextRow {
360362
required property string modelData
361363
required property int index
@@ -366,15 +368,14 @@ Item {
366368
highlighted: index === root.nsHighlightIndex
367369
onActivated: name => {
368370
nsDropdown.visible = false;
369-
root.nsFilterText = "";
370-
root.nsHighlightIndex = 0;
371+
nsSearchInput.clearSearch();
371372
if (main) main.switchNamespace(name);
372373
}
373374
}
374375
}
375376

376377
NText {
377-
visible: root.nsFiltered().length === 0
378+
visible: root.nsFilteredList.length === 0
378379
text: pluginApi?.tr("panel.noNamespaces")
379380
pointSize: Style.fontSizeS
380381
color: Color.mOnSurfaceVariant

0 commit comments

Comments
 (0)