fix: prevent auto-focus on mobile when opening diff viewer

Refactored focusInput to accept onMobile parameter to conditionally focus input based on platform, preventing annoying automatic keyboard popup on mobile devices when diff viewer opens/closes.
This commit is contained in:
Andrew Beal 2025-12-13 10:40:20 +00:00
parent 3e43d9f558
commit c59bfeb06c
2 changed files with 11 additions and 7 deletions

View file

@ -40,18 +40,21 @@
let diffOpen: boolean = false;
const diffOpenedRef: EventRef = eventService.on(Event.DiffOpened, () => { diffOpen = true; if (!Platform.isMobile){ focusInput(); } });
const diffClosedRef: EventRef = eventService.on(Event.DiffClosed, () => { diffOpen = false; if (!Platform.isMobile){ focusInput(); } });
const diffOpenedRef: EventRef = eventService.on(Event.DiffOpened, () => { diffOpen = true; focusInput(); });
const diffClosedRef: EventRef = eventService.on(Event.DiffClosed, () => { diffOpen = false; focusInput(); });
onDestroy(() => {
eventService.offref(diffOpenedRef);
eventService.offref(diffClosedRef);
});
export function focusInput() {
tick().then(() => {
textareaElement?.focus();
});
export function focusInput(onMobile: boolean = false) {
// don't focus on mobile, it's annoying
if (onMobile || !Platform.isMobile) {
tick().then(() => {
textareaElement?.focus();
});
}
}
$: if (userInstructionButton) {
@ -189,7 +192,7 @@
}
e?.preventDefault();
focusInput();
focusInput(true);
}
function handleInput() {

View file

@ -15,6 +15,7 @@
import type { SettingsService } from "Services/SettingsService";
import { Copy } from "Enums/Copy";
import { AbortService } from "Services/AbortService";
import { Platform } from "obsidian";
const plugin: VaultkeeperAIPlugin = Resolve<VaultkeeperAIPlugin>(Services.VaultkeeperAIPlugin);
const settingsService: SettingsService = Resolve<SettingsService>(Services.SettingsService);