🐛 Fixed the issue of scroll wheel modifying font size and the problem of automatic language detection failing

This commit is contained in:
2026-03-28 22:35:09 +08:00
parent 6e49516962
commit 03191a219f
8 changed files with 216 additions and 141 deletions

View File

@@ -68,13 +68,20 @@ function createDetectionMap(): Map<string, SupportedLanguage> {
LANGUAGES.forEach(lang => {
if (lang.detectIds) {
lang.detectIds.forEach(detectId => {
map.set(detectId, lang.token);
// 保留首个映射,避免重复 detectId 覆盖更基础的语言,例如 js -> ts。
if (!map.has(detectId)) {
map.set(detectId, lang.token);
}
});
}
});
return map;
}
function createWorkerUrl(): URL {
return new URL(`${import.meta.env.BASE_URL}langdetect-worker.js`, window.location.href);
}
/**
* 检测ID到语言token的映射表
*/
@@ -131,7 +138,7 @@ class LanguageDetectionWorker {
*/
private initWorker(): void {
try {
this.worker = new Worker('/langdetect-worker.js');
this.worker = new Worker(createWorkerUrl());
this.worker.onmessage = (event) => {
const response: WorkerResponse = event.data;
const request = this.pendingRequests.get(response.idx);
@@ -316,4 +323,4 @@ export async function detectLanguages(contents: string[]): Promise<LanguageDetec
} finally {
worker.destroy();
}
}
}