Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions src/features/chat/ui/composer/composer-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,45 +142,48 @@ export class ComposerBridge {
};

private installSourceInterceptors(): void {
const nativeValueGet = this.descriptors.value.get!;
const nativeValueSet = this.descriptors.value.set!;
const nativeSelectionStartGet = this.descriptors.selectionStart.get!;
const nativeSelectionStartSet = this.descriptors.selectionStart.set!;
const nativeSelectionEndGet = this.descriptors.selectionEnd.get!;
const nativeSelectionEndSet = this.descriptors.selectionEnd.set!;
const nativePlaceholderGet = this.descriptors.placeholder.get!;
const nativePlaceholderSet = this.descriptors.placeholder.set!;
const sourceEl = this.sourceEl;
// Bind the native accessors to the element up front: they must always run
// with the textarea as `this`, and the bound references carry precise
// types instead of the descriptors' `any` signatures.
const nativeValueGet = this.descriptors.value.get!.bind(sourceEl) as () => string;
const nativeValueSet = this.descriptors.value.set!.bind(sourceEl) as (value: string) => void;
const nativeSelectionStartGet = this.descriptors.selectionStart.get!.bind(sourceEl) as () => number;
const nativeSelectionStartSet = this.descriptors.selectionStart.set!.bind(sourceEl) as (position: number | null) => void;
const nativeSelectionEndGet = this.descriptors.selectionEnd.get!.bind(sourceEl) as () => number;
const nativeSelectionEndSet = this.descriptors.selectionEnd.set!.bind(sourceEl) as (position: number | null) => void;
const nativePlaceholderGet = this.descriptors.placeholder.get!.bind(sourceEl) as () => string;
const nativePlaceholderSet = this.descriptors.placeholder.set!.bind(sourceEl) as (value: string) => void;

Object.defineProperty(sourceEl, 'value', {
configurable: true,
get: () => nativeValueGet.call(sourceEl),
get: () => nativeValueGet(),
set: (value: string) => {
nativeValueSet.call(sourceEl, value);
nativeValueSet(value);
this.syncComposerFromSource();
},
});
Object.defineProperty(sourceEl, 'selectionStart', {
configurable: true,
get: () => nativeSelectionStartGet.call(sourceEl),
get: () => nativeSelectionStartGet(),
set: (position: number | null) => {
nativeSelectionStartSet.call(sourceEl, position);
nativeSelectionStartSet(position);
this.syncComposerSelectionFromSource();
},
});
Object.defineProperty(sourceEl, 'selectionEnd', {
configurable: true,
get: () => nativeSelectionEndGet.call(sourceEl),
get: () => nativeSelectionEndGet(),
set: (position: number | null) => {
nativeSelectionEndSet.call(sourceEl, position);
nativeSelectionEndSet(position);
this.syncComposerSelectionFromSource();
},
});
Object.defineProperty(sourceEl, 'placeholder', {
configurable: true,
get: () => nativePlaceholderGet.call(sourceEl),
get: () => nativePlaceholderGet(),
set: (value: string) => {
nativePlaceholderSet.call(sourceEl, value);
nativePlaceholderSet(value);
if (!this.destroyed) this.composer.setPlaceholder(value);
},
});
Expand Down
9 changes: 7 additions & 2 deletions src/features/settings/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,16 @@ export class QoderianSettingTab extends PluginSettingTab {
}

/**
* Imperative renderer for Obsidian versions older than 1.13.0, which
* Imperative entry point for Obsidian versions older than 1.13.0, which
* never consult getSettingDefinitions(). Kept as the documented fallback
* and sharing the same builders as the declarative render rows.
*/
display(): void {
this.renderLegacySettings();
}

/** Rebuilds the legacy page; re-invoked directly after a locale change. */
private renderLegacySettings(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.addClass('qoderian-settings');
Expand Down Expand Up @@ -536,7 +541,7 @@ export class QoderianSettingTab extends PluginSettingTab {
}
this.plugin.settings.locale = locale;
await this.plugin.saveSettings();
this.display();
this.renderLegacySettings();
this.refreshViewChrome();
});
});
Expand Down
Loading