mirror of
https://github.com/fbarrca/obsidian-inlineAI.git
synced 2026-07-22 11:50:24 +00:00
Fix bug: not applying setting changes until reload
This commit is contained in:
parent
f5da3175d4
commit
aec2999b6b
3 changed files with 18 additions and 2 deletions
|
|
@ -166,4 +166,13 @@ export class ChatApiManager {
|
|||
|
||||
return this.handleEditorUpdate(systemPrompt, userPrompt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the manager's settings and reinitializes the chat client.
|
||||
* @param settings - New configuration settings for the chat API.
|
||||
*/
|
||||
public updateSettings(settings: InlineAISettings): void {
|
||||
this.settings = settings;
|
||||
this.chatClient = this.initializeChatClient(settings);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,14 @@ import { diffExtension } from "./modules/diffExtension";
|
|||
|
||||
export default class InlineAIChatPlugin extends Plugin {
|
||||
settings: InlineAISettings = DEFAULT_SETTINGS;
|
||||
chatapi: ChatApiManager;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
const chatapi = new ChatApiManager(this.settings, this.app);
|
||||
this.chatapi = new ChatApiManager(this.settings, this.app);
|
||||
|
||||
this.registerEditorExtension([
|
||||
FloatingTooltipExtension(chatapi),
|
||||
FloatingTooltipExtension(this.chatapi),
|
||||
generatedResponseState,
|
||||
currentSelectionState,
|
||||
buildSelectionHiglightState,
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export class InlineAISettingsTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.provider = value as "openai" | "ollama" | "custom";
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.chatapi.updateSettings(this.plugin.settings);
|
||||
this.display(); // Refresh to update the API key field visibility
|
||||
})
|
||||
);
|
||||
|
|
@ -63,6 +64,7 @@ export class InlineAISettingsTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.model = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.chatapi.updateSettings(this.plugin.settings);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -80,6 +82,7 @@ export class InlineAISettingsTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.apiKey = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.chatapi.updateSettings(this.plugin.settings);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
@ -98,6 +101,7 @@ export class InlineAISettingsTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.customURL = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.chatapi.updateSettings(this.plugin.settings);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
@ -118,6 +122,7 @@ export class InlineAISettingsTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.selectionPrompt = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.chatapi.updateSettings(this.plugin.settings);
|
||||
});
|
||||
|
||||
// Add a CSS class for styling
|
||||
|
|
@ -135,6 +140,7 @@ export class InlineAISettingsTab extends PluginSettingTab {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.cursorPrompt = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.plugin.chatapi.updateSettings(this.plugin.settings);
|
||||
});
|
||||
|
||||
// Add a CSS class for styling
|
||||
|
|
|
|||
Loading…
Reference in a new issue