Fix wrong selected-task count in the task bulk-actions context menu

handleContextMenu (and the shift-click range-selection path) resolved the
target row via props.tasks[index], but index is the row's position in the
sorted/rendered row model (table.getRowModel().rows), not the raw prop
array — the two orders rarely match once the default created_at sort is
applied. This caused right-click (and shift-click) to select the wrong row,
corrupting the count shown in TaskBulkActionsMenu. Both call sites now
resolve the task from the actual row data instead of an index lookup into
the unsorted array, matching the pattern ShotsDataTable.vue already used
correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-18 13:19:42 +08:00
parent e628c99498
commit f013e1cf25
@@ -34,7 +34,7 @@
]"
@click="handleRowClick(row.original, $event, index)"
@dblclick="handleRowDoubleClick(row.original)"
@contextmenu="handleContextMenu($event, index)"
@contextmenu="handleContextMenu($event, row.original)"
>
<TableCell
v-for="cell in row.getVisibleCells()"
@@ -219,14 +219,16 @@ const handleRowClick = (task: Task, event: MouseEvent, index: number) => {
const end = Math.max(lastClickedIndex.value, index)
const newSelection: Record<string, boolean> = {}
// Index into the sorted/rendered row model, not props.tasks — the raw prop array
// order doesn't match the displayed (sorted) order.
const displayedRows = table.getRowModel().rows
for (let i = start; i <= end; i++) {
const id = String(props.tasks[i].id)
const id = String(displayedRows[i].original.id)
newSelection[id] = true
}
// Update rowSelection - create completely new object to trigger reactivity
rowSelection.value = newSelection
console.log('Shift-click selection updated:', rowSelection.value)
lastClickedIndex.value = index
} else if (event.ctrlKey || event.metaKey) {
// Ctrl/Cmd+Click: Toggle selection
@@ -252,17 +254,9 @@ const handleRowDoubleClick = (task: Task) => {
emit('row-double-click', task)
}
const handleContextMenu = (event: MouseEvent, index: number) => {
const handleContextMenu = (event: MouseEvent, rightClickedTask: Task) => {
event.preventDefault()
// Prevent context menu on empty table areas
if (props.tasks.length === 0) {
return
}
const rightClickedTask = props.tasks[index]
if (!rightClickedTask) return
const taskId = String(rightClickedTask.id)
// If right-clicked row is not selected, add it to selection