Skip to content

[Repo Assist] refactor: extract duplicate mouse row-selection into helper #24

@github-actions

Description

@github-actions

🤖 This is an automated pull request from Repo Assist.

Summary

Left-click and right-click on the package list both contained an identical row-to-index calculation and detail-load sequence. This PR extracts it into a single select_package_at_row helper, eliminating the duplication.

Changes

  • New private select_package_at_row(app, row) function in handler.rs.
  • Left-click handler reduced to one call site.
  • Right-click handler reduced to one call site.
  • Minor comment cleanup (removed stale "Double-click" comment on right-click arm).

Why

Duplicate code is a maintenance hazard: any future fix (e.g. adjusting the scroll offset arithmetic) must be applied in two places. With the helper, it's one place.

No behaviour change.


Test Status

Infrastructure limitation: this project targets windows-latest runners and cannot be built/tested in the current Linux environment. The change is a pure refactor — no logic has been altered — and the diff has been reviewed by inspection. CI will validate it on Windows.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@cbb46ab386962aa371045839fc9998ee4e97ca64

Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch repo-assist/improve-mouse-selection-dedup-38d3e3df7f2fe625.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests.

Show patch preview (81 of 81 lines)
From c8ed4e78f1a802b81934cc9513139fe7f10b5d57 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Tue, 17 Mar 2026 06:20:42 +0000
Subject: [PATCH] refactor: extract duplicate mouse row-selection into helper

Left-click and right-click on the package list both ran the same
row-to-index calculation and detail-load logic verbatim. Extract
it into a `select_package_at_row` helper to eliminate the
duplication and make each call site a single line.

No behaviour change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 src/handler.rs | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/handler.rs b/src/handler.rs
index 3f74409..a048939 100644
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -262,6 +262,18 @@ fn load_detail_for_selected(app: &mut App) {
     }
 }
 
+/// Select the package row at the given terminal row coordinate and load its detail.
+fn select_package_at_row(app: &mut App, row: u16) {
+    let content_y = app.layout.list_content_y;
+    if row >= content_y {
+        let clicked_idx = (row - content_y) as usize + app.table_scroll_offset;
+        if clicked_idx < app.filtered_packages.len() {
+            app.selected = clicked_idx;
+            load_detail_for_selected(app);
+        }
+    }
+}
+
 fn handle_mouse(
     app: &mut App,
     mouse: crossterm::event::MouseEvent,
@@ -315,14 +327,7 @@ fn handle_mouse(
                     return Ok(false);
                 }
 
-                let content_y = app.layout.list_content_y;
-                if row >= content_y {
-                    let clicked_idx = (row - content_y) as usize + app.table_scroll_offset;
-                    if clicked_idx < app.filtered_packages.len() {
-                        app.selected = clicked_idx;
-                        load_detail_for_selected(app);
-                    }
-                }
+                select_package_at_row(app, row);
   
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions