Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
68 changes: 67 additions & 1 deletion src/cm/supportedModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,72 @@ function escapeRegExp(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}

async function shouldAutoCloseTags(): Promise<boolean> {
const { default: appSettings } = await import("lib/settings");
return appSettings.value.autoCloseTags !== false;
}

function createLanguageLoader(name: string, lang: LanguageDescription) {
const normalizedName = normalizeModeKey(name);

switch (normalizedName) {
case "html":
return async () => {
const { html } = await import("@codemirror/lang-html");
return html({ autoCloseTags: await shouldAutoCloseTags() });
};

case "xml":
return async () => {
const { xml } = await import("@codemirror/lang-xml");
return xml({ autoCloseTags: await shouldAutoCloseTags() });
};

case "vue":
return async () => {
const [{ vue }, { html }] = await Promise.all([
import("@codemirror/lang-vue"),
import("@codemirror/lang-html"),
]);
return vue({
base: html({ autoCloseTags: await shouldAutoCloseTags() }),
});
};

case "angular":
return async () => {
const [{ angular }, { html }] = await Promise.all([
import("@codemirror/lang-angular"),
import("@codemirror/lang-html"),
]);
return angular({
base: html({
autoCloseTags: await shouldAutoCloseTags(),
selfClosingTags: true,
}),
});
};

case "php":
return async () => {
const [{ php }, { html }] = await Promise.all([
import("@codemirror/lang-php"),
import("@codemirror/lang-html"),
]);
const htmlSupport = html({
autoCloseTags: await shouldAutoCloseTags(),
matchClosingTags: false,
});
return [
php({ baseLanguage: htmlSupport.language }),
htmlSupport.support,
];
};
}

return typeof lang.load === "function" ? () => lang.load!() : null;
}

// 1) Always register a plain text fallback
addMode("Text", "txt|text|log|plain", "Plain Text", () => []);

Expand Down Expand Up @@ -106,7 +172,7 @@ for (const lang of languages as readonly LanguageDescription[]) {

// Wrap language-data loader as our modelist language provider
// lang.load() returns a Promise<Extension>; we let the editor handle async loading
const loader = typeof lang.load === "function" ? () => lang.load!() : null;
const loader = createLanguageLoader(name, lang);

addMode(modeId, pattern, name, loader, {
aliases,
Expand Down
4 changes: 3 additions & 1 deletion src/lang/ar-ye.json
Original file line number Diff line number Diff line change
Expand Up @@ -721,5 +721,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/be-by.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,5 +723,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/bn-bd.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/cs-cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
2 changes: 2 additions & 0 deletions src/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"invalid backup file": "Invalid backup file",
"add path": "Add path",
"live autocompletion": "Live autocompletion",
"auto close tags": "Auto close tags",
"file properties": "File properties",
"path": "Path",
"type": "Type",
Expand Down Expand Up @@ -662,6 +663,7 @@
"settings-info-editor-line-numbers": "Show line numbers in the gutter.",
"settings-info-editor-lint-gutter": "Show diagnostics and lint markers in the gutter.",
"settings-info-editor-live-autocomplete": "Show suggestions while you type.",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
"settings-info-editor-rainbow-brackets": "Color matching brackets by nesting depth.",
"settings-info-editor-relative-line-numbers": "Show distance from the current line.",
"settings-info-editor-rtl-text": "Switch right-to-left behavior per line.",
Expand Down
4 changes: 3 additions & 1 deletion src/lang/es-sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/fr-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/he-il.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,5 +723,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/hi-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,5 +723,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/hu-hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Biztosan bezárja a kiválasztott lapokat? A nem mentett módosítások elvesznek, és ez a művelet nem vonható vissza.",
"close tabs to right": "Jobbra lévő lapok bezárása",
"close tabs to left": "Balra lévő lapok bezárása",
"close other tabs": "Többi lap bezárása"
"close other tabs": "Többi lap bezárása",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/id-id.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,5 +723,7 @@
"close selected tabs warning": "Apakah Anda yakin ingin menutup tab terpilih? Anda akan kehilangan perubahan yang belum disimpan dan aksi ini tidak dapat dibatalkan.",
"close tabs to right": "Tutup Kanan",
"close tabs to left": "Tutup Kiri",
"close other tabs": "Tutup Lainnya"
"close other tabs": "Tutup Lainnya",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/ir-fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,5 +723,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/it-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/ja-jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/ko-kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/ml-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/mm-unicode.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/mm-zawgyi.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/pl-pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/pu-in.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/ru-ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/tl-ph.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/tr-tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/uk-ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/uz-uz.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/vi-vn.json
Original file line number Diff line number Diff line change
Expand Up @@ -723,5 +723,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "确定要关闭选中的标签页吗?未保存的更改将丢失且无法恢复。",
"close tabs to right": "关闭右侧标签页",
"close tabs to left": "关闭左侧标签页",
"close other tabs": "关闭其他标签页"
"close other tabs": "关闭其他标签页",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "確定要關閉選取的標籤頁嗎?未保存的變更將會遺失且無法恢復。",
"close tabs to right": "關閉右側標籤頁",
"close tabs to left": "關閉左側標籤頁",
"close other tabs": "關閉其他標籤頁"
"close other tabs": "關閉其他標籤頁",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
4 changes: 3 additions & 1 deletion src/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -722,5 +722,7 @@
"close selected tabs warning": "Are you sure you want to close the selected tabs? You will lose the unsaved changes and this action cannot be reversed.",
"close tabs to right": "Close Right",
"close tabs to left": "Close Left",
"close other tabs": "Close Others"
"close other tabs": "Close Others",
"auto close tags": "Auto close tags",
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
}
5 changes: 5 additions & 0 deletions src/lib/editorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,11 @@ async function EditorManager($header, $body) {
applyOptions(["liveAutoCompletion"]);
});

appSettings.on("update:autoCloseTags", function () {
const file = manager.activeFile;
if (file?.type === "editor") applyFileToEditor(file);
});

appSettings.on("update:linenumbers", function () {
updateMargin(true);
updateEditorLineNumbersFromSettings();
Expand Down
1 change: 1 addition & 0 deletions src/lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class Settings {
fullscreen: false,
floatingButton: !this.#IS_TABLET,
liveAutoCompletion: true,
autoCloseTags: true,
showPrintMargin: false,
printMargin: 80,
scrollbarSize: 20,
Expand Down
Loading