mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 18:01:22 +00:00
Fix tree selector focus behavior (#1142)
* fix(coding-agent): tree selector focuses nearest visible ancestor When the selected entry is not visible (filtered out by mode change or a metadata entry like model_change), walk up the parent chain to find the nearest visible ancestor instead of jumping to the last item. Fixes selection behavior for: - Initial selection when currentLeafId is a metadata entry - Filter switching, e.g. Ctrl+U for user-only mode * fix(coding-agent): tree selector preserves selection through empty filters When switching to a filter with no results, e.g. labeled-only with no labels and back, the cursor would reset to the first message instead of the original selection. Track lastSelectedId as a class member and only update it when filteredNodes is non-empty, preserving the selection across empty filter results. * test(coding-agent): add tree selector filter and selection tests - Test metadata entry handling (model_change, thinking_level_change) - Test filter switching with parent traversal (default ↔ user-only) - Test empty filter preservation (labeled-only with no labels)
This commit is contained in:
parent
43be54c237
commit
4ca7bbe450
3 changed files with 332 additions and 29 deletions
|
|
@ -3352,15 +3352,6 @@ export class InteractiveMode {
|
|||
const tree = this.sessionManager.getTree();
|
||||
const realLeafId = this.sessionManager.getLeafId();
|
||||
|
||||
// Find the visible leaf for display (skip metadata entries like labels)
|
||||
let visibleLeafId = realLeafId;
|
||||
while (visibleLeafId) {
|
||||
const entry = this.sessionManager.getEntry(visibleLeafId);
|
||||
if (!entry) break;
|
||||
if (entry.type !== "label" && entry.type !== "custom") break;
|
||||
visibleLeafId = entry.parentId ?? null;
|
||||
}
|
||||
|
||||
if (tree.length === 0) {
|
||||
this.showStatus("No entries in session");
|
||||
return;
|
||||
|
|
@ -3369,11 +3360,11 @@ export class InteractiveMode {
|
|||
this.showSelector((done) => {
|
||||
const selector = new TreeSelectorComponent(
|
||||
tree,
|
||||
visibleLeafId,
|
||||
realLeafId,
|
||||
this.ui.terminal.rows,
|
||||
async (entryId) => {
|
||||
// Selecting the visible leaf is a no-op (already there)
|
||||
if (entryId === visibleLeafId) {
|
||||
// Selecting the current leaf is a no-op (already there)
|
||||
if (entryId === realLeafId) {
|
||||
done();
|
||||
this.showStatus("Already at this point");
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue