Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,9 @@
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
element.focus();
// Use preventScroll to avoid browser auto-scrolling when focusing
// This preserves scroll state during tab switching and cursor restoration
element.focus({ preventScroll: true });
return;
}
currentOffset += nodeLength;
Expand All @@ -862,7 +864,9 @@
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
element.focus();
// Use preventScroll to avoid browser auto-scrolling when focusing
// This preserves scroll state during tab switching and cursor restoration
element.focus({ preventScroll: true });
}
} catch {
// Silently handle cursor restoration errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ export class TextareaController {
}

public focus(): void {
this.element.focus();
// Use preventScroll to avoid browser auto-scrolling when focusing
// This is critical for:
// 1. New tab opening - scroll should start at top, not at first focused node
// 2. Tab switching - scroll position should be restored, not overridden by focus
// 3. Arrow navigation - maintains scroll state during node-to-node navigation
this.element.focus({ preventScroll: true });

if (this.pendingCursorPosition !== null) {
this.setCursorPosition(this.pendingCursorPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ export class CursorPositioningService {
}

// Focus if requested
// Use preventScroll to avoid browser auto-scrolling when focusing
// This preserves scroll state during tab switching and new tab opening
if (focus) {
textarea.focus();
textarea.focus({ preventScroll: true });
}

// Set cursor position
Expand Down Expand Up @@ -132,8 +134,10 @@ export class CursorPositioningService {
const clampedPosition = Math.max(0, Math.min(position, maxPosition));

// Focus if requested
// Use preventScroll to avoid browser auto-scrolling when focusing
// This preserves scroll state during tab switching and new tab opening
if (focus) {
textarea.focus();
textarea.focus({ preventScroll: true });
}

// Set cursor position
Expand Down Expand Up @@ -187,8 +191,10 @@ export class CursorPositioningService {
absolutePosition += column;

// Focus if requested
// Use preventScroll to avoid browser auto-scrolling when focusing
// This preserves scroll state during tab switching and new tab opening
if (focus) {
textarea.focus();
textarea.focus({ preventScroll: true });
}

// Set cursor position
Expand Down