Skip to content

Commit 6931ae2

Browse files
committed
Partially fix text box selection issue
There's an issue where the cursor position resets to the beginning of commit message boxes when you press somehwere near the actual input. This change fixes the issue in normal mode, but the issue persists with the floating modal. It seems unrelated to `focusManager.ts`, but will need to investigate later.
1 parent 4f74b1b commit 6931ae2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/ui/src/lib/focus/focusManager.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FModeManager } from '$lib/focus/fModeManager';
22
import { getNavigationAction, isInputElement, getElementDescription } from '$lib/focus/focusUtils';
33
import { focusNextTabIndex } from '$lib/focus/tabbable';
4-
import { removeFromArray, scrollIntoViewIfNeeded } from '$lib/focus/utils';
4+
import { isContentEditable, removeFromArray, scrollIntoViewIfNeeded } from '$lib/focus/utils';
55
import { parseHotkey, matchesHotkey } from '$lib/utils/hotkeySymbols';
66
import { mergeUnlisten } from '$lib/utils/mergeUnlisten';
77
import { InjectionToken } from '@gitbutler/core/context';
@@ -91,14 +91,14 @@ export class FocusManager {
9191

9292
if (e.target instanceof HTMLElement) {
9393
const focusableNode = this.findNearestFocusableElement(e.target);
94-
if (focusableNode) {
94+
if (focusableNode && focusableNode.element.contains(e.target)) {
9595
this.setActiveNode(focusableNode);
9696
this.setOutline(false);
9797
}
9898
}
9999

100100
// TODO: Find a way to update the focusable without causing target to blur.
101-
if (isInputElement(e.target)) {
101+
if (isInputElement(e.target) && !isContentEditable(e.target)) {
102102
e.target.focus();
103103
}
104104
}
@@ -358,7 +358,9 @@ export class FocusManager {
358358

359359
private updateCurrentNode(event: KeyboardEvent): FocusableNode | undefined {
360360
if (this.currentNode) return this.currentNode;
361-
if (event.key === 'Tab') return;
361+
// We don't want to go from no current to picking nearest navigable
362+
// descendant when modifier keys are pressed.
363+
if (['Tab', 'Shift', 'Ctrl', 'Meta'].includes(event.key)) return;
362364

363365
const firstNode = this.findNavigableDescendant(this.getDefaultRoot());
364366
if (firstNode) {

0 commit comments

Comments
 (0)