Skip to content

Commit c559d16

Browse files
luoxuanzaoQoder-AI
andcommitted
feat(chat): open the settings window from the view header
Reaching a Qoderian setting meant diving into Obsidian's settings pane. Put a gear button beside the feedback button in the view header that opens the settings page in its own window, so the sidebar and chat stay in place. Co-authored-by: QoderAI <qoder_ai@qoder.com>
1 parent 80c1a12 commit c559d16

6 files changed

Lines changed: 138 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ version with its date and start a fresh empty `[Unreleased]` above it.
1313

1414
### Added
1515

16+
- A settings button in the view header opens Qoderian's settings window in
17+
place, instead of navigating into Obsidian's settings.
1618
- Show the added external context path after dropping a folder or file, surface
1719
rejected additions, and show the context count even for a single path.
1820
- Drag files and folders from your operating system (e.g. macOS Finder) onto

‎src/features/chat/chat-view.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { setButtonTooltip } from '../../shared/dom/tooltip';
1515
import { createIconSvg, QODER_ICON,QODERIAN_ICON_ID } from '../../shared/icons';
1616
import { openFeedbackModal } from '../feedback/ui/feedback-modal';
17+
import { QoderianSettingsModal } from '../settings/settings-modal';
1718
import type { HistoryConversationStatus } from './controllers/conversation-controller';
1819
import {
1920
sendTabInputMessageFromExplicitEnterShortcut,
@@ -230,6 +231,11 @@ export class QoderianView extends ItemView {
230231
setIcon(feedbackBtn, 'message-circle-question');
231232
setButtonTooltip(feedbackBtn, t('commands.submitFeedback'));
232233
feedbackBtn.addEventListener('click', () => this.openFeedback());
234+
235+
const settingsBtn = headerActions.createDiv({ cls: 'qoderian-header-btn' });
236+
setIcon(settingsBtn, 'settings');
237+
setButtonTooltip(settingsBtn, t('settings.title'));
238+
settingsBtn.addEventListener('click', () => this.openSettings());
233239
}
234240

235241
/**
@@ -307,6 +313,10 @@ export class QoderianView extends ItemView {
307313
});
308314
}
309315

316+
private openSettings(): void {
317+
new QoderianSettingsModal(this.plugin).open();
318+
}
319+
310320
private buildInputFooter(): void {
311321
if (!this.viewContainerEl) return;
312322

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Modal } from 'obsidian';
2+
3+
import { t } from '../../i18n/i18n';
4+
import type QoderianPlugin from '../../main';
5+
import { QoderianSettingTab } from './settings-tab';
6+
7+
/** Qoderian-owned settings window that does not navigate into Obsidian settings. */
8+
export class QoderianSettingsModal extends Modal {
9+
private settingsTab: QoderianSettingTab | null = null;
10+
11+
constructor(private readonly plugin: QoderianPlugin) {
12+
super(plugin.app);
13+
}
14+
15+
onOpen(): void {
16+
this.modalEl.addClass('qoderian-settings-modal');
17+
this.contentEl.addClass('qoderian-settings-modal-content');
18+
this.titleEl.setText(t('settings.title'));
19+
20+
const settingsTab = new QoderianSettingTab(this.app, this.plugin);
21+
settingsTab.containerEl = this.contentEl;
22+
settingsTab.display();
23+
this.settingsTab = settingsTab;
24+
}
25+
26+
onClose(): void {
27+
this.settingsTab?.hide();
28+
this.settingsTab = null;
29+
this.contentEl.empty();
30+
}
31+
}

‎src/style/settings/base.css‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
/* Settings page - remove separator lines from setting items */
2+
.qoderian-settings-modal {
3+
width: min(920px, calc(100vw - 48px));
4+
max-width: 920px;
5+
height: min(86vh, 900px);
6+
}
7+
8+
.qoderian-settings-modal-content {
9+
overflow-y: auto;
10+
overscroll-behavior: contain;
11+
padding-inline-end: 8px;
12+
}
13+
214
.qoderian-settings .setting-item {
315
border-top: none;
416
}

‎tests/__mocks__/obsidian.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ export class Modal {
208208
empty: jest.fn(),
209209
addClass: jest.fn(),
210210
};
211+
modalEl: any = {
212+
addClass: jest.fn(),
213+
};
214+
titleEl: any = {
215+
setText: jest.fn(),
216+
};
211217

212218
constructor(app: any) {
213219
this.app = app;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { createMockEl } from '@test/helpers/mock-element';
2+
3+
import { QoderianSettingsModal } from '@/features/settings/settings-modal';
4+
5+
let lastModalInstance: any;
6+
const mockSettingsTab = {
7+
containerEl: null as any,
8+
display: jest.fn(),
9+
hide: jest.fn(),
10+
};
11+
12+
jest.mock('obsidian', () => {
13+
const actual = jest.requireActual('obsidian');
14+
15+
class MockModal {
16+
app: any;
17+
modalEl: any = { addClass: jest.fn() };
18+
titleEl: any = { setText: jest.fn() };
19+
contentEl: any = createMockEl();
20+
21+
constructor(app: any) {
22+
this.app = app;
23+
// eslint-disable-next-line @typescript-eslint/no-this-alias
24+
lastModalInstance = this;
25+
}
26+
27+
open() {
28+
this.onOpen();
29+
}
30+
31+
close() {
32+
this.onClose();
33+
}
34+
35+
onOpen() {
36+
// Overridden by subclass
37+
}
38+
39+
onClose() {
40+
// Overridden by subclass
41+
}
42+
}
43+
44+
return { ...actual, Modal: MockModal };
45+
});
46+
47+
jest.mock('@/features/settings/settings-tab', () => ({
48+
QoderianSettingTab: jest.fn().mockImplementation(() => mockSettingsTab),
49+
}));
50+
51+
describe('QoderianSettingsModal', () => {
52+
beforeEach(() => {
53+
mockSettingsTab.containerEl = null;
54+
mockSettingsTab.display.mockClear();
55+
mockSettingsTab.hide.mockClear();
56+
});
57+
58+
it('renders the settings tab inside the settings window', () => {
59+
new QoderianSettingsModal({ app: {} } as any).open();
60+
61+
expect(lastModalInstance.modalEl.addClass).toHaveBeenCalledWith('qoderian-settings-modal');
62+
expect(lastModalInstance.titleEl.setText).toHaveBeenCalledWith('Qoderian Settings');
63+
expect(mockSettingsTab.containerEl).toBe(lastModalInstance.contentEl);
64+
expect(mockSettingsTab.display).toHaveBeenCalledTimes(1);
65+
});
66+
67+
it('detaches the settings tab when the window closes', () => {
68+
const modal = new QoderianSettingsModal({ app: {} } as any);
69+
modal.open();
70+
const emptySpy = jest.spyOn(modal.contentEl, 'empty');
71+
72+
modal.close();
73+
74+
expect(mockSettingsTab.hide).toHaveBeenCalledTimes(1);
75+
expect(emptySpy).toHaveBeenCalledTimes(1);
76+
});
77+
});

0 commit comments

Comments
 (0)