Skip to content

Commit 3746232

Browse files
committed
fix: track drag movement to distinguish jitter from intentional single-char selection
1 parent 3c6ec0c commit 3746232

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/selection-manager.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class SelectionManager {
4343
private selectionStart: { col: number; absoluteRow: number } | null = null;
4444
private selectionEnd: { col: number; absoluteRow: number } | null = null;
4545
private isSelecting: boolean = false;
46+
private dragMovedToNewCell: boolean = false; // Track if drag moved to a different cell
4647
private mouseDownTarget: EventTarget | null = null; // Track where mousedown occurred
4748

4849
// Track rows that need redraw for clearing old selection
@@ -453,6 +454,7 @@ export class SelectionManager {
453454
this.selectionStart = { col: cell.col, absoluteRow };
454455
this.selectionEnd = null; // Don't highlight until drag
455456
this.isSelecting = true;
457+
this.dragMovedToNewCell = false;
456458
}
457459
});
458460

@@ -465,6 +467,14 @@ export class SelectionManager {
465467
const cell = this.pixelToCell(e.offsetX, e.offsetY);
466468
const absoluteRow = this.viewportRowToAbsolute(cell.row);
467469
this.selectionEnd = { col: cell.col, absoluteRow };
470+
471+
// Track if mouse has moved to a different cell than the start
472+
if (
473+
this.selectionStart &&
474+
(cell.col !== this.selectionStart.col || absoluteRow !== this.selectionStart.absoluteRow)
475+
) {
476+
this.dragMovedToNewCell = true;
477+
}
468478
this.requestRender();
469479

470480
// Check if near edges for auto-scroll
@@ -549,14 +559,9 @@ export class SelectionManager {
549559
this.isSelecting = false;
550560
this.stopAutoScroll();
551561

552-
// Check if this was a click without drag, or a click with sub-cell jitter
553-
// (mouse moved but stayed in the same cell). Either way, no real selection.
554-
if (
555-
!this.selectionEnd ||
556-
(this.selectionStart &&
557-
this.selectionStart.col === this.selectionEnd.col &&
558-
this.selectionStart.absoluteRow === this.selectionEnd.absoluteRow)
559-
) {
562+
// Check if this was a click without drag, or sub-cell jitter.
563+
// If the mouse never moved to a different cell, treat as a click.
564+
if (!this.selectionEnd || !this.dragMovedToNewCell) {
560565
this.clearSelection();
561566
return;
562567
}

0 commit comments

Comments
 (0)