Skip to content

Commit e53e6fa

Browse files
luoxuanzaoQoder-AI
andauthored
refactor: clear strict-review findings in composer bridge and settings tab (#38)
- Bind native textarea accessors to the element with precise types in ComposerBridge, clearing the unbound-method and no-unsafe-return findings from the type-checked review rules - Route the legacy (<1.13) settings locale refresh through a private renderLegacySettings() instead of the deprecated display() self-call Co-authored-by: QoderAI (Qwen 3.8 Max) <qoder_ai@qoder.com>
1 parent c4c6fd2 commit e53e6fa

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

‎src/features/chat/ui/composer/composer-bridge.ts‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,45 +142,48 @@ export class ComposerBridge {
142142
};
143143

144144
private installSourceInterceptors(): void {
145-
const nativeValueGet = this.descriptors.value.get!;
146-
const nativeValueSet = this.descriptors.value.set!;
147-
const nativeSelectionStartGet = this.descriptors.selectionStart.get!;
148-
const nativeSelectionStartSet = this.descriptors.selectionStart.set!;
149-
const nativeSelectionEndGet = this.descriptors.selectionEnd.get!;
150-
const nativeSelectionEndSet = this.descriptors.selectionEnd.set!;
151-
const nativePlaceholderGet = this.descriptors.placeholder.get!;
152-
const nativePlaceholderSet = this.descriptors.placeholder.set!;
153145
const sourceEl = this.sourceEl;
146+
// Bind the native accessors to the element up front: they must always run
147+
// with the textarea as `this`, and the bound references carry precise
148+
// types instead of the descriptors' `any` signatures.
149+
const nativeValueGet = this.descriptors.value.get!.bind(sourceEl) as () => string;
150+
const nativeValueSet = this.descriptors.value.set!.bind(sourceEl) as (value: string) => void;
151+
const nativeSelectionStartGet = this.descriptors.selectionStart.get!.bind(sourceEl) as () => number;
152+
const nativeSelectionStartSet = this.descriptors.selectionStart.set!.bind(sourceEl) as (position: number | null) => void;
153+
const nativeSelectionEndGet = this.descriptors.selectionEnd.get!.bind(sourceEl) as () => number;
154+
const nativeSelectionEndSet = this.descriptors.selectionEnd.set!.bind(sourceEl) as (position: number | null) => void;
155+
const nativePlaceholderGet = this.descriptors.placeholder.get!.bind(sourceEl) as () => string;
156+
const nativePlaceholderSet = this.descriptors.placeholder.set!.bind(sourceEl) as (value: string) => void;
154157

155158
Object.defineProperty(sourceEl, 'value', {
156159
configurable: true,
157-
get: () => nativeValueGet.call(sourceEl),
160+
get: () => nativeValueGet(),
158161
set: (value: string) => {
159-
nativeValueSet.call(sourceEl, value);
162+
nativeValueSet(value);
160163
this.syncComposerFromSource();
161164
},
162165
});
163166
Object.defineProperty(sourceEl, 'selectionStart', {
164167
configurable: true,
165-
get: () => nativeSelectionStartGet.call(sourceEl),
168+
get: () => nativeSelectionStartGet(),
166169
set: (position: number | null) => {
167-
nativeSelectionStartSet.call(sourceEl, position);
170+
nativeSelectionStartSet(position);
168171
this.syncComposerSelectionFromSource();
169172
},
170173
});
171174
Object.defineProperty(sourceEl, 'selectionEnd', {
172175
configurable: true,
173-
get: () => nativeSelectionEndGet.call(sourceEl),
176+
get: () => nativeSelectionEndGet(),
174177
set: (position: number | null) => {
175-
nativeSelectionEndSet.call(sourceEl, position);
178+
nativeSelectionEndSet(position);
176179
this.syncComposerSelectionFromSource();
177180
},
178181
});
179182
Object.defineProperty(sourceEl, 'placeholder', {
180183
configurable: true,
181-
get: () => nativePlaceholderGet.call(sourceEl),
184+
get: () => nativePlaceholderGet(),
182185
set: (value: string) => {
183-
nativePlaceholderSet.call(sourceEl, value);
186+
nativePlaceholderSet(value);
184187
if (!this.destroyed) this.composer.setPlaceholder(value);
185188
},
186189
});

‎src/features/settings/settings-tab.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,16 @@ export class QoderianSettingTab extends PluginSettingTab {
480480
}
481481

482482
/**
483-
* Imperative renderer for Obsidian versions older than 1.13.0, which
483+
* Imperative entry point for Obsidian versions older than 1.13.0, which
484484
* never consult getSettingDefinitions(). Kept as the documented fallback
485485
* and sharing the same builders as the declarative render rows.
486486
*/
487487
display(): void {
488+
this.renderLegacySettings();
489+
}
490+
491+
/** Rebuilds the legacy page; re-invoked directly after a locale change. */
492+
private renderLegacySettings(): void {
488493
const { containerEl } = this;
489494
containerEl.empty();
490495
containerEl.addClass('qoderian-settings');
@@ -536,7 +541,7 @@ export class QoderianSettingTab extends PluginSettingTab {
536541
}
537542
this.plugin.settings.locale = locale;
538543
await this.plugin.saveSettings();
539-
this.display();
544+
this.renderLegacySettings();
540545
this.refreshViewChrome();
541546
});
542547
});

0 commit comments

Comments
 (0)