Use unknown return type for callbacks

This commit is contained in:
Andras Schmelczer 2025-08-17 15:12:31 +01:00
parent e73f147fbc
commit 81b81e30ff
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
16 changed files with 95 additions and 76 deletions

View file

@ -14,7 +14,7 @@ export const updateSelection = ({
}): void => {
spans.forEach((span) => {
if (fromA <= span.start) {
// The change covers the entirety of the selection
// the change covers the entirety of the selection
if (toA > span.end) {
span.start = toB;
span.end = toB;
@ -23,6 +23,8 @@ export const updateSelection = ({
let change = toB - toA;
if (change < 0) {
// it's a deletion
// if overlaps with the start, we can't move it back more than the deleted range
change = Math.max(change, fromA - span.start);
}
@ -31,6 +33,7 @@ export const updateSelection = ({
} else if (toA <= span.end) {
span.end += toB - toA;
} else if (toB <= span.end) {
// a deletion overlaps with the end, so we move the end
span.end = toB;
}
});

View file

@ -24,13 +24,12 @@ export class HistoryView extends ItemView {
super(leaf);
this.icon = HistoryView.ICON;
this.client.addSyncHistoryUpdateListener(
() =>
void this.updateView().catch((error: unknown) => {
this.client.logger.error(
`Failed to update history view: ${error}`
);
})
this.client.addSyncHistoryUpdateListener(async () =>
this.updateView().catch((error: unknown) => {
this.client.logger.error(
`Failed to update history view: ${error}`
);
})
);
}
@ -109,7 +108,15 @@ export class HistoryView extends ItemView {
this.historyContainer = container.createDiv({ cls: "logs-container" });
await this.updateView();
this.timer = setInterval(() => void this.updateView(), 1000);
this.timer = setInterval(
() =>
void this.updateView().catch((error: unknown) => {
this.client.logger.error(
`Failed to update history view: ${error}`
);
}),
1000
);
}
public async onClose(): Promise<void> {
@ -174,11 +181,17 @@ export class HistoryView extends ItemView {
null
) {
card.addEventListener("click", () => {
void this.app.workspace.openLinkText(
entry.details.relativePath,
entry.details.relativePath,
false
);
this.app.workspace
.openLinkText(
entry.details.relativePath,
entry.details.relativePath,
false
)
.catch((error: unknown) => {
this.client.logger.error(
`Failed to open link for ${entry.details.relativePath}: ${error}`
);
});
});
card.addClass("clickable");

View file

@ -16,7 +16,7 @@ export class SyncSettingsTab extends PluginSettingTab {
private readonly plugin: VaultLinkPlugin;
private readonly syncClient: SyncClient;
private readonly statusDescription: StatusDescription;
private statusDescriptionSubscription: (() => void) | undefined;
private statusDescriptionSubscription: (() => unknown) | undefined;
public constructor({
app,
@ -90,11 +90,12 @@ export class SyncSettingsTab extends PluginSettingTab {
cls: "description"
},
(descriptionContainer) => {
this.setStatusDescriptionSubscription((): void => {
this.statusDescription.renderStatusDescription(
this.setStatusDescriptionSubscription(
this.statusDescription.renderStatusDescription.bind(
this.statusDescription,
descriptionContainer
);
});
)
);
}
);
@ -339,7 +340,7 @@ export class SyncSettingsTab extends PluginSettingTab {
}
private setStatusDescriptionSubscription(
newSubscription?: () => void
newSubscription?: () => unknown
): void {
if (this.statusDescriptionSubscription) {
this.statusDescription.removeStatusChangeListener(
@ -360,7 +361,7 @@ export class SyncSettingsTab extends PluginSettingTab {
settingName: keyof SyncSettings
): [
DocumentFragment,
(newValue: SyncSettings[keyof SyncSettings]) => void
(newValue: SyncSettings[keyof SyncSettings]) => unknown
] {
const titleContainer = document.createDocumentFragment();
const title = titleContainer.createEl("div", {

View file

@ -42,9 +42,7 @@ export class StatusBar {
text: "VaultLink is disabled, click to configure",
cls: "initialize-button"
});
button.onclick = (): void => {
this.plugin.openSettings();
};
button.onclick = this.plugin.openSettings.bind(this.plugin);
return;
}

View file

@ -28,12 +28,12 @@ export class StatusDescription {
}
);
this.syncClient.addWebSocketStatusChangeListener(
() => void this.updateConnectionState()
this.syncClient.addWebSocketStatusChangeListener(async () =>
this.updateConnectionState()
);
this.syncClient.addOnSettingsChangeListener(
() => void this.updateConnectionState()
this.syncClient.addOnSettingsChangeListener(async () =>
this.updateConnectionState()
);
}
@ -42,10 +42,10 @@ export class StatusDescription {
this.updateDescription();
}
public addStatusChangeListener(listener: () => void): void {
public addStatusChangeListener(listener: () => unknown): void {
this.statusChangeListeners.push(listener);
}
public removeStatusChangeListener(listener: () => void): void {
public removeStatusChangeListener(listener: () => unknown): void {
this.statusChangeListeners = this.statusChangeListeners.filter(
(l) => l !== listener
);