3 Commits
Author SHA1 Message Date
AlexKucera 38c977b9aa Removes redundant settings header
Simplifies the user interface by removing an unnecessary
settings header that is no longer needed for functionality
clarity or user guidance.
2025-11-09 22:13:02 +01:00
AlexKucera fa59c14cbd Improves error notices and settings descriptions
Refines user-facing text in error notices and settings to improve
clarity and user experience. Standardizes settings header creation,
updates placeholder text, and simplifies setting descriptions.
2025-11-09 17:29:05 +01:00
AlexKucera 1f69c568bb Refines settings UI and error handling
Simplifies commentary prompt assignments and streamlines
the Freewriting Cleanup Plugin command registration.

Improves consistency and readability in the settings interface
by standardizing heading and button labels. Removes redundant
model selection logging.

This enhances user experience by making the interface
more intuitive and declutters the codebase for easier maintenance.
2025-11-09 17:17:37 +01:00
5 changed files with 49 additions and 58 deletions

No files matched your search

+1 -1
View File
@@ -78,7 +78,7 @@ export class AnthropicClient {
} else if (commentaryStyle === 'custom') {
throw new ConfigurationError('Custom commentary style requires a custom prompt. Please provide customCommentaryPrompt.');
} else {
commentaryPrompt = COMMENTARY_PRESETS[commentaryStyle as Exclude<CommentaryStyle, 'custom'>];
commentaryPrompt = COMMENTARY_PRESETS[commentaryStyle];
}
}
+1 -1
View File
@@ -92,7 +92,7 @@ export class CleanupCommand {
} else if (error instanceof ServiceUnavailableError) {
new Notice(error.message);
} else if (error instanceof InvalidResponseError) {
new Notice('Received an unexpected response from Claude. Please try again.');
new Notice('Received an unexpected response from Claude. Please try again');
} else if (error instanceof NetworkError) {
new Notice('Network error. Check your connection and try again.');
} else if (error instanceof Error) {
+2 -2
View File
@@ -72,7 +72,7 @@ export default class FreewritingCleanupPlugin extends Plugin {
*/
async loadSettings(): Promise<FreewritingCleanupData | null> {
const data = await this.loadData() as FreewritingCleanupData | null;
const { modelCache, ...persisted } = data ?? {};
const { ...persisted } = data ?? {};
this.settings = {
...DEFAULT_SETTINGS,
...(persisted as Partial<FreewritingCleanupSettings>)
@@ -111,7 +111,7 @@ export default class FreewritingCleanupPlugin extends Plugin {
*/
private registerCommand() {
this.addCommand({
id: 'freewriting-cleanup-cleanup-text',
id: 'cleanup-text',
name: 'Clean up text',
editorCallback: async (editor: Editor, view: MarkdownView) => {
await this.executeCleanupCommand(editor, view);
+22 -28
View File
@@ -1,7 +1,6 @@
// ABOUTME: Service class for orchestrating freewriting text cleanup operations
// ABOUTME: Handles validation, API coordination, and result formatting
import { Notice } from 'obsidian';
import { AnthropicClient } from '../api/anthropicClient';
import { FreewritingCleanupSettings, CleanupResult, ANTHROPIC_LIMITS } from '../types';
import { ApiKeyError, TextTooLongError } from '../errors';
@@ -64,36 +63,31 @@ export class CleanupService {
const startTime = Date.now();
try {
const { cleanedText, commentary, usage } = await this.client.cleanupText(
text,
settings.model,
settings.cleanupPrompt,
settings.enableCommentary,
settings.commentaryStyle,
settings.customCommentaryPrompt
);
const { cleanedText, commentary, usage } = await this.client.cleanupText(
text,
settings.model,
settings.cleanupPrompt,
settings.enableCommentary,
settings.commentaryStyle,
settings.customCommentaryPrompt
);
const duration = Date.now() - startTime;
const duration = Date.now() - startTime;
const result: CleanupResult = {
originalText: text,
cleanedText,
commentary,
timestamp: new Date(),
model: settings.model,
tokensUsed: {
input: usage?.input_tokens ?? 0,
output: usage?.output_tokens ?? 0
},
duration
};
const result: CleanupResult = {
originalText: text,
cleanedText,
commentary,
timestamp: new Date(),
model: settings.model,
tokensUsed: {
input: usage?.input_tokens ?? 0,
output: usage?.output_tokens ?? 0
},
duration
};
return result;
} catch (error) {
// Let the command layer handle user feedback to avoid duplicate notices
throw error;
}
return result;
}
/**
+23 -26
View File
@@ -54,7 +54,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
private scheduleSave(): void {
if (this.saveDebounce !== null) window.clearTimeout(this.saveDebounce);
this.saveDebounce = window.setTimeout(() => {
this.plugin.saveSettings();
void this.plugin.saveSettings();
this.saveDebounce = null;
}, 300);
}
@@ -70,8 +70,6 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl('h2', { text: 'Freewriting Cleanup Settings' });
// Load models asynchronously in the background
this.loadModels()
.then(() => {
@@ -86,13 +84,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - API Configuration
containerEl.createEl('h3', { text: 'API Configuration' });
new Setting(containerEl).setName('API configuration').setHeading();
new Setting(containerEl)
.setName('Anthropic API Key')
.setName('Anthropic API key')
.setDesc('Your Anthropic API key for Claude. Get one at https://console.anthropic.com/')
.addText(text => text
.setPlaceholder('sk-ant-...')
.setPlaceholder('Enter API key')
.setValue(this.plugin.settings.apiKey)
.onChange(async (value) => {
this.plugin.settings.apiKey = value;
@@ -115,17 +113,17 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
});
new Setting(containerEl)
.setName('Test API Key')
.setName('Test API key')
.setDesc('Test your API key to verify it works correctly')
.addButton(button => button
.setButtonText('Test Connection')
.setButtonText('Test connection')
.onClick(async () => {
await this.testApiKey(button);
}));
new Setting(containerEl)
.setName('Claude Model')
.setDesc('Which Claude model to use for text cleanup')
.setName('Claude model')
.setDesc('Claude model to use for text cleanup')
.addDropdown(dropdown => {
this.modelDropdown = dropdown;
this.populateModelDropdown(dropdown);
@@ -139,16 +137,16 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Cleanup Configuration
containerEl.createEl('h3', { text: 'Cleanup Configuration' });
new Setting(containerEl).setName('Cleanup configuration').setHeading();
new Setting(containerEl)
.setName('Cleanup Prompt')
.setDesc('Instructions for how Claude should clean up your freewriting text')
.setName('Cleanup prompt')
.setDesc('Instructions for how to clean up your freewriting text')
.addTextArea(textArea => {
textArea
.setPlaceholder('Enter your cleanup instructions...')
.setValue(this.plugin.settings.cleanupPrompt)
.onChange(async (value) => {
.onChange((value) => {
this.plugin.settings.cleanupPrompt = value;
this.scheduleSave();
});
@@ -160,14 +158,14 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Commentary Configuration
containerEl.createEl('h3', { text: 'AI Commentary' });
new Setting(containerEl).setName('AI commentary').setHeading();
new Setting(containerEl)
.setName('AI should comment on text')
.setDesc('After cleaning up your text, AI will provide thoughtful commentary on your freewriting session')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.enableCommentary)
.onChange(async (value) => {
.onChange((value) => {
this.plugin.settings.enableCommentary = value;
this.scheduleSave();
this.display(); // Refresh to show/hide commentary options
@@ -175,7 +173,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
if (this.plugin.settings.enableCommentary) {
new Setting(containerEl)
.setName('Commentary Style')
.setName('Commentary style')
.setDesc('Choose the type of feedback AI should provide')
.addDropdown(dropdown => {
COMMENTARY_STYLES.forEach(style => {
@@ -184,7 +182,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
});
dropdown
.setValue(this.plugin.settings.commentaryStyle)
.onChange(async (value) => {
.onChange((value) => {
this.plugin.settings.commentaryStyle = value as CommentaryStyle;
this.scheduleSave();
this.display(); // Refresh to show/hide custom prompt
@@ -193,13 +191,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
if (this.plugin.settings.commentaryStyle === 'custom') {
new Setting(containerEl)
.setName('Custom Commentary Prompt')
.setName('Custom commentary prompt')
.setDesc('Instructions for how AI should comment on your freewriting')
.addTextArea(textArea => {
textArea
.setPlaceholder('Enter your commentary instructions...')
.setValue(this.plugin.settings.customCommentaryPrompt)
.onChange(async (value) => {
.onChange((value) => {
this.plugin.settings.customCommentaryPrompt = value;
this.scheduleSave();
});
@@ -210,7 +208,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
});
} else {
// Show the current preset for reference
const presetText = COMMENTARY_PRESETS[this.plugin.settings.commentaryStyle as Exclude<CommentaryStyle, 'custom'>];
const presetText = COMMENTARY_PRESETS[this.plugin.settings.commentaryStyle];
const descDiv = containerEl.createDiv({ cls: 'setting-item-description freewriting-cleanup-description' });
descDiv.empty();
descDiv.createEl('strong', { text: 'Selected style: ' });
@@ -220,7 +218,7 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Usage Information
containerEl.createEl('h3', { text: 'Usage Information' });
new Setting(containerEl).setName('Usage information').setHeading();
const usageDiv = containerEl.createDiv();
usageDiv.empty();
@@ -243,13 +241,13 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
// MARK: - Reset Settings
containerEl.createEl('h3', { text: 'Reset' });
new Setting(containerEl).setName('Reset').setHeading();
new Setting(containerEl)
.setName('Reset to Defaults')
.setName('Reset to defaults')
.setDesc('Reset all settings to their default values')
.addButton(button => button
.setButtonText('Reset Settings')
.setButtonText('Reset settings')
.setWarning()
.onClick(async () => {
await this.resetSettings();
@@ -334,7 +332,6 @@ export class FreewritingCleanupSettingTab extends PluginSettingTab {
const newModel = this.availableModels[0].id;
this.plugin.settings.model = newModel;
this.modelDropdown.setValue(newModel);
console.log(`Model '${currentModel}' no longer available, switched to '${newModel}'`);
}
}