- Improve mobile keyboard focus ux in diff view events

- Improve readFile error message for non-existent files
This commit is contained in:
Andrew Beal 2025-12-07 13:43:09 +00:00
parent 3e0aaaf736
commit 9b67c45a78
3 changed files with 8 additions and 9 deletions

View file

@ -3,7 +3,6 @@ import { Services } from "Services/Services";
import { SystemInstruction } from "./SystemPrompt";
import type { FileSystemService } from "Services/FileSystemService";
import type { SettingsService } from "Services/SettingsService";
import { Notice } from "obsidian";
export interface IPrompt {
systemInstruction(): string;
@ -26,10 +25,6 @@ export class AIPrompt implements IPrompt {
public async userInstruction(): Promise<string> {
const result = await this.fileSystemService.readFile(this.settingsService.settings.userInstruction, true);
if (result instanceof Error) {
new Notice("Failed to load user instructions!");
return "";
}
return result;
return result instanceof Error ? "" : result;
}
}

View file

@ -39,8 +39,9 @@
let userRequest = "";
let diffOpen: boolean = false;
const diffOpenedRef: EventRef = eventService.on(Event.DiffOpened, () => { diffOpen = true; focusInput(); });
const diffClosedRef: EventRef = eventService.on(Event.DiffClosed, () => { diffOpen = false; focusInput(); });
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(); } });
onDestroy(() => {
eventService.offref(diffOpenedRef);

View file

@ -19,7 +19,10 @@ export class FileSystemService {
public async readFile(filePath: string, allowAccessToPluginRoot: boolean = false): Promise<string | Error> {
const file: TAbstractFile | null = this.vaultService.getAbstractFileByPath(filePath, allowAccessToPluginRoot);
if (file && file instanceof TFile) {
if (file == null) {
return Exception.new(`File does not exist: ${filePath}`);
}
if (file instanceof TFile) {
return await this.vaultService.read(file, allowAccessToPluginRoot);
}
return Exception.new(`Path is a folder, not a file: ${filePath}`);