Skip to content

Commit bb7ebec

Browse files
feat(editor): add setting to disable HTML tag auto closing (#2051)
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 2ef5d86 commit bb7ebec

35 files changed

+172
-31
lines changed

src/cm/supportedModes.ts

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,72 @@ function escapeRegExp(value: string): string {
5757
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5858
}
5959

60+
async function shouldAutoCloseTags(): Promise<boolean> {
61+
const { default: appSettings } = await import("lib/settings");
62+
return appSettings.value.autoCloseTags !== false;
63+
}
64+
65+
function createLanguageLoader(name: string, lang: LanguageDescription) {
66+
const normalizedName = normalizeModeKey(name);
67+
68+
switch (normalizedName) {
69+
case "html":
70+
return async () => {
71+
const { html } = await import("@codemirror/lang-html");
72+
return html({ autoCloseTags: await shouldAutoCloseTags() });
73+
};
74+
75+
case "xml":
76+
return async () => {
77+
const { xml } = await import("@codemirror/lang-xml");
78+
return xml({ autoCloseTags: await shouldAutoCloseTags() });
79+
};
80+
81+
case "vue":
82+
return async () => {
83+
const [{ vue }, { html }] = await Promise.all([
84+
import("@codemirror/lang-vue"),
85+
import("@codemirror/lang-html"),
86+
]);
87+
return vue({
88+
base: html({ autoCloseTags: await shouldAutoCloseTags() }),
89+
});
90+
};
91+
92+
case "angular":
93+
return async () => {
94+
const [{ angular }, { html }] = await Promise.all([
95+
import("@codemirror/lang-angular"),
96+
import("@codemirror/lang-html"),
97+
]);
98+
return angular({
99+
base: html({
100+
autoCloseTags: await shouldAutoCloseTags(),
101+
selfClosingTags: true,
102+
}),
103+
});
104+
};
105+
106+
case "php":
107+
return async () => {
108+
const [{ php }, { html }] = await Promise.all([
109+
import("@codemirror/lang-php"),
110+
import("@codemirror/lang-html"),
111+
]);
112+
const htmlSupport = html({
113+
autoCloseTags: await shouldAutoCloseTags(),
114+
matchClosingTags: false,
115+
});
116+
return [
117+
php({ baseLanguage: htmlSupport.language }),
118+
htmlSupport.support,
119+
];
120+
};
121+
}
122+
123+
return typeof lang.load === "function" ? () => lang.load!() : null;
124+
}
125+
60126
// 1) Always register a plain text fallback
61127
addMode("Text", "txt|text|log|plain", "Plain Text", () => []);
62128

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

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

111177
addMode(modeId, pattern, name, loader, {
112178
aliases,

src/lang/ar-ye.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,5 +721,7 @@
721721
"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.",
722722
"close tabs to right": "Close Right",
723723
"close tabs to left": "Close Left",
724-
"close other tabs": "Close Others"
724+
"close other tabs": "Close Others",
725+
"auto close tags": "Auto close tags",
726+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
725727
}

src/lang/be-by.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,5 +723,7 @@
723723
"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.",
724724
"close tabs to right": "Close Right",
725725
"close tabs to left": "Close Left",
726-
"close other tabs": "Close Others"
726+
"close other tabs": "Close Others",
727+
"auto close tags": "Auto close tags",
728+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727729
}

src/lang/bn-bd.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,5 +722,7 @@
722722
"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.",
723723
"close tabs to right": "Close Right",
724724
"close tabs to left": "Close Left",
725-
"close other tabs": "Close Others"
725+
"close other tabs": "Close Others",
726+
"auto close tags": "Auto close tags",
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
726728
}

src/lang/cs-cz.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,5 +722,7 @@
722722
"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.",
723723
"close tabs to right": "Close Right",
724724
"close tabs to left": "Close Left",
725-
"close other tabs": "Close Others"
725+
"close other tabs": "Close Others",
726+
"auto close tags": "Auto close tags",
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
726728
}

src/lang/de-de.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,5 +722,7 @@
722722
"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.",
723723
"close tabs to right": "Close Right",
724724
"close tabs to left": "Close Left",
725-
"close other tabs": "Close Others"
725+
"close other tabs": "Close Others",
726+
"auto close tags": "Auto close tags",
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
726728
}

src/lang/en-us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
"invalid backup file": "Invalid backup file",
131131
"add path": "Add path",
132132
"live autocompletion": "Live autocompletion",
133+
"auto close tags": "Auto close tags",
133134
"file properties": "File properties",
134135
"path": "Path",
135136
"type": "Type",
@@ -662,6 +663,7 @@
662663
"settings-info-editor-line-numbers": "Show line numbers in the gutter.",
663664
"settings-info-editor-lint-gutter": "Show diagnostics and lint markers in the gutter.",
664665
"settings-info-editor-live-autocomplete": "Show suggestions while you type.",
666+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files.",
665667
"settings-info-editor-rainbow-brackets": "Color matching brackets by nesting depth.",
666668
"settings-info-editor-relative-line-numbers": "Show distance from the current line.",
667669
"settings-info-editor-rtl-text": "Switch right-to-left behavior per line.",

src/lang/es-sv.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,5 +722,7 @@
722722
"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.",
723723
"close tabs to right": "Close Right",
724724
"close tabs to left": "Close Left",
725-
"close other tabs": "Close Others"
725+
"close other tabs": "Close Others",
726+
"auto close tags": "Auto close tags",
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
726728
}

src/lang/fr-fr.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,5 +722,7 @@
722722
"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.",
723723
"close tabs to right": "Close Right",
724724
"close tabs to left": "Close Left",
725-
"close other tabs": "Close Others"
725+
"close other tabs": "Close Others",
726+
"auto close tags": "Auto close tags",
727+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
726728
}

src/lang/he-il.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,5 +723,7 @@
723723
"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.",
724724
"close tabs to right": "Close Right",
725725
"close tabs to left": "Close Left",
726-
"close other tabs": "Close Others"
726+
"close other tabs": "Close Others",
727+
"auto close tags": "Auto close tags",
728+
"settings-info-editor-auto-close-tags": "Automatically insert closing tags in HTML, XML, Vue, Angular, and PHP template files."
727729
}

0 commit comments

Comments
 (0)