mirror of
https://github.com/fancive/obsidian-parallel-reader.git
synced 2026-07-22 06:53:43 +00:00
fix: address remaining Obsidian review bot required issues
- Remove unnecessary TFile cast (instanceof already narrows) - Remove await on non-Promise view methods (loadFor, renderLoading, renderError) - Remove async from CacheManager.touch() (no await expression) - Replace this-aliasing with captured locals in batch modal - Use CSS class instead of inline style for modal input width - Fix sentence case in settings UI text Change-Id: I2a222c6429eb7e4d69761cca8369956fef510054
This commit is contained in:
parent
de08ec778a
commit
da535cb064
4 changed files with 57 additions and 66 deletions
26
main.js
26
main.js
File diff suppressed because one or more lines are too long
65
main.ts
65
main.ts
|
|
@ -388,7 +388,7 @@ class ParallelReaderPlugin extends Plugin {
|
|||
.setIcon('trash')
|
||||
.onClick(async () => {
|
||||
await this.cacheManager.delete(file.path);
|
||||
new Notice(this.t('cacheClearedFile', { name: (file as TFile).basename }));
|
||||
new Notice(this.t('cacheClearedFile', { name: file.basename }));
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -499,14 +499,14 @@ class ParallelReaderPlugin extends Plugin {
|
|||
if (!force) {
|
||||
const entry = this.cacheManager.get(file.path);
|
||||
if (entry && cacheEntryMatches(entry, content, this.settings)) {
|
||||
await this.cacheTouch(file.path);
|
||||
this.cacheTouch(file.path);
|
||||
if (this.activeFileStillMatches(file))
|
||||
await view.loadFor(file, this.resolveCardAnchors(content, entry.cards), false);
|
||||
view.loadFor(file, this.resolveCardAnchors(content, entry.cards), false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await view.renderLoading(file, this.t('loadingGenerating'));
|
||||
view.renderLoading(file, this.t('loadingGenerating'));
|
||||
const maxDocChars = Number(this.settings.maxDocChars) || DEFAULT_SETTINGS.maxDocChars;
|
||||
if (content.length > maxDocChars) new Notice(this.t('longNoteTruncated', { count: maxDocChars }));
|
||||
new Notice(this.t('generatingNotice'));
|
||||
|
|
@ -530,7 +530,7 @@ class ParallelReaderPlugin extends Plugin {
|
|||
job.setPhase('saving');
|
||||
await this.cacheManager.put(file.path, content, rawCards, this.settings);
|
||||
job.throwIfCancelled();
|
||||
if (this.viewIsShowingFile(view, file)) await view.loadFor(file, sections, false);
|
||||
if (this.viewIsShowingFile(view, file)) view.loadFor(file, sections, false);
|
||||
const unanchored = sections.filter((s) => s.startLine < 0).length;
|
||||
new Notice(
|
||||
this.t('generationDone', {
|
||||
|
|
@ -545,13 +545,13 @@ class ParallelReaderPlugin extends Plugin {
|
|||
return;
|
||||
}
|
||||
if (e instanceof GenerationJobCancelledError) {
|
||||
if (view && this.viewIsShowingFile(view, file)) await view.renderError(file, this.t('cancelledError'));
|
||||
if (view && this.viewIsShowingFile(view, file)) view.renderError(file, this.t('cancelledError'));
|
||||
new Notice(this.t('cancelled'));
|
||||
return;
|
||||
}
|
||||
const kind = classifyGenerationError(e);
|
||||
console.error(e);
|
||||
if (view && this.viewIsShowingFile(view, file)) await view.renderError(file, e.message || String(e));
|
||||
if (view && this.viewIsShowingFile(view, file)) view.renderError(file, e.message || String(e));
|
||||
new Notice(this.t('generationFailed', { kind: kind === 'unknown' ? '' : ` (${kind})`, error: e.message || e }));
|
||||
});
|
||||
}
|
||||
|
|
@ -561,31 +561,28 @@ class ParallelReaderPlugin extends Plugin {
|
|||
new Notice(this.t('batchAlreadyRunning'));
|
||||
return;
|
||||
}
|
||||
const plugin = this;
|
||||
const selectFolderText = this.t('batchSelectFolder');
|
||||
const folderPromptText = this.t('batchFolderPrompt');
|
||||
const folderPath = await new Promise<string | null>((resolve) => {
|
||||
class FolderPromptModal extends Modal {
|
||||
private input!: HTMLInputElement;
|
||||
onOpen() {
|
||||
this.contentEl.createEl('p', { text: plugin.t('batchSelectFolder') });
|
||||
this.input = this.contentEl.createEl('input', { type: 'text' });
|
||||
this.input.placeholder = plugin.t('batchFolderPrompt');
|
||||
this.input.style.width = '100%';
|
||||
this.input.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
resolve(this.input.value.trim());
|
||||
this.close();
|
||||
}
|
||||
});
|
||||
this.contentEl.createEl('button', { text: 'OK' }).addEventListener('click', () => {
|
||||
resolve(this.input.value.trim());
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
onClose() {
|
||||
resolve(null);
|
||||
}
|
||||
}
|
||||
new FolderPromptModal(plugin.app).open();
|
||||
const modal = new Modal(this.app);
|
||||
modal.onOpen = () => {
|
||||
modal.contentEl.createEl('p', { text: selectFolderText });
|
||||
const field = modal.contentEl.createDiv({ cls: 'parallel-reader-modal-field' });
|
||||
const input = field.createEl('input', { type: 'text' });
|
||||
input.placeholder = folderPromptText;
|
||||
input.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
resolve(input.value.trim());
|
||||
modal.close();
|
||||
}
|
||||
});
|
||||
modal.contentEl.createEl('button', { text: 'OK' }).addEventListener('click', () => {
|
||||
resolve(input.value.trim());
|
||||
modal.close();
|
||||
});
|
||||
};
|
||||
modal.onClose = () => resolve(null);
|
||||
modal.open();
|
||||
});
|
||||
if (folderPath === null) return;
|
||||
const validation = validateBatchFolderInput(folderPath, (path) => {
|
||||
|
|
@ -661,15 +658,15 @@ class ParallelReaderPlugin extends Plugin {
|
|||
if (!view || !this.activeFileStillMatches(file)) return;
|
||||
const entry = this.cacheManager.get(file.path);
|
||||
if (!entry) {
|
||||
await view.loadFor(file, [], false);
|
||||
view.loadFor(file, [], false);
|
||||
view.renderEmptyWithHint(file);
|
||||
return;
|
||||
}
|
||||
const content = await this.app.vault.read(file);
|
||||
if (!this.activeFileStillMatches(file)) return;
|
||||
const stale = !cacheEntryMatches(entry, content, this.settings);
|
||||
await this.cacheTouch(file.path);
|
||||
await view.loadFor(file, this.resolveCardAnchors(content, entry.cards), stale);
|
||||
this.cacheTouch(file.path);
|
||||
view.loadFor(file, this.resolveCardAnchors(content, entry.cards), stale);
|
||||
}
|
||||
|
||||
bindScrollSync() {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ export class CacheManager {
|
|||
return this.cache[filePath] || null;
|
||||
}
|
||||
|
||||
async touch(filePath: string): Promise<CacheEntry | null> {
|
||||
touch(filePath: string): CacheEntry | null {
|
||||
const entry = touchCacheEntry(this.cache[filePath] || null);
|
||||
if (!entry) return null;
|
||||
this.cache[filePath] = entry;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
|
|||
.addDropdown((d) =>
|
||||
d
|
||||
.addOption('api', 'API / provider')
|
||||
.addOption('claude-code', 'Claude Code CLI')
|
||||
.addOption('claude-code', 'Claude code CLI')
|
||||
.addOption('codex', 'Codex CLI')
|
||||
.setValue(this.plugin.settings.backend)
|
||||
.onChange(async (v) => {
|
||||
|
|
@ -163,13 +163,10 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
|
|||
.setDesc(this.tr('settingApiKeyDesc'))
|
||||
.addText((t) => {
|
||||
t.inputEl.type = 'password';
|
||||
return t
|
||||
.setPlaceholder('sk-...')
|
||||
.setValue(this.plugin.settings.apiKey)
|
||||
.onChange((v) => {
|
||||
this.plugin.settings.apiKey = v.trim();
|
||||
this.plugin.saveSettingsDebounced();
|
||||
});
|
||||
return t.setValue(this.plugin.settings.apiKey).onChange((v) => {
|
||||
this.plugin.settings.apiKey = v.trim();
|
||||
this.plugin.saveSettingsDebounced();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -202,13 +199,10 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
|
|||
.setName(this.tr('settingHeadersName'))
|
||||
.setDesc(this.tr('settingHeadersDesc'))
|
||||
.addTextArea((t) =>
|
||||
t
|
||||
.setPlaceholder('cf-aig-authorization: Bearer ...')
|
||||
.setValue(this.plugin.settings.apiHeaders)
|
||||
.onChange((v) => {
|
||||
this.plugin.settings.apiHeaders = v;
|
||||
this.plugin.saveSettingsDebounced();
|
||||
}),
|
||||
t.setValue(this.plugin.settings.apiHeaders).onChange((v) => {
|
||||
this.plugin.settings.apiHeaders = v;
|
||||
this.plugin.saveSettingsDebounced();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl).setName(this.tr('settingMaxTokensName')).addText((t) =>
|
||||
|
|
@ -251,7 +245,7 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
|
|||
.setDesc(isCliBacked ? this.tr('settingModelDescCli') : this.tr('settingModelDescApi'))
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder(isCliBacked ? DEFAULT_SETTINGS.model : getApiPreset(this.plugin.settings).model || 'model-id')
|
||||
.setPlaceholder(isCliBacked ? DEFAULT_SETTINGS.model : getApiPreset(this.plugin.settings).model || 'Model-id')
|
||||
.setValue(this.plugin.settings.model)
|
||||
.onChange((v) => {
|
||||
this.plugin.settings.model = v.trim() || (isCliBacked ? DEFAULT_SETTINGS.model : '');
|
||||
|
|
@ -294,7 +288,7 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
|
|||
.setDesc(this.tr('settingCardRangeDesc'))
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder('min')
|
||||
.setPlaceholder('Min')
|
||||
.setValue(String(this.plugin.settings.minCards || DEFAULT_SETTINGS.minCards))
|
||||
.onChange((v) => {
|
||||
const n = parseInt(v, 10);
|
||||
|
|
@ -307,7 +301,7 @@ export class ParallelReaderSettingTab extends PluginSettingTab {
|
|||
)
|
||||
.addText((t) =>
|
||||
t
|
||||
.setPlaceholder('max')
|
||||
.setPlaceholder('Max')
|
||||
.setValue(String(this.plugin.settings.maxCards || DEFAULT_SETTINGS.maxCards))
|
||||
.onChange((v) => {
|
||||
const n = parseInt(v, 10);
|
||||
|
|
|
|||
Loading…
Reference in a new issue