Skip to content

Commit 8dca360

Browse files
authored
Merge branch 'Acode-Foundation:main' into main
2 parents 93b3ca7 + d97ce3c commit 8dca360

45 files changed

Lines changed: 412 additions & 164 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/nightly-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
# Only run this step, if not called from another workflow. And a previous step is successful with releasedRequired=true
250250
id: release
251251
if: ${{ ! inputs.skip_tagging_and_releases && steps.check-nightly-tag-force-update.outcome == 'success' && env.releaseRequired == 'true' && !inputs.is_PR }}
252-
uses: softprops/action-gh-release@v2
252+
uses: softprops/action-gh-release@v3
253253
env:
254254
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
255255
with:

bun.lock

Lines changed: 12 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 7 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
"cordova": "13.0.0",
156156
"core-js": "^3.47.0",
157157
"dayjs": "^1.11.19",
158-
"dompurify": "^3.3.2",
158+
"dompurify": "^3.4.0",
159159
"escape-string-regexp": "^5.0.0",
160160
"esprima": "^4.0.1",
161161
"filesize": "^11.0.13",

src/cm/lineNumberSelection.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { EditorSelection } from "@codemirror/state";
2+
import type { BlockInfo, EditorView } from "@codemirror/view";
3+
4+
type LineInfo = Pick<BlockInfo, "from" | "to"> | null | undefined;
5+
6+
type LineNumberClickEvent = Pick<
7+
MouseEvent,
8+
| "button"
9+
| "shiftKey"
10+
| "altKey"
11+
| "ctrlKey"
12+
| "metaKey"
13+
| "preventDefault"
14+
| "defaultPrevented"
15+
>;
16+
17+
function toDocumentOffset(
18+
value: number | null | undefined,
19+
fallback = 0,
20+
): number {
21+
const resolved = value != null ? Number(value) : fallback;
22+
return Number.isFinite(resolved) ? resolved : fallback;
23+
}
24+
25+
/**
26+
* Resolve the selection range for a clicked document line.
27+
* Includes the trailing line break when one exists to mirror Ace's
28+
* full-line selection behavior.
29+
*/
30+
export function getLineSelectionRange(
31+
state: EditorView["state"],
32+
line: LineInfo,
33+
): { from: number; to: number } | null {
34+
if (!line) return null;
35+
const from = Math.max(0, toDocumentOffset(line.from));
36+
const to = Math.max(from, toDocumentOffset(line.to, from));
37+
return {
38+
from,
39+
to: Math.min(to + 1, state.doc.length),
40+
};
41+
}
42+
43+
function getCurrentSelectionLineRange(state: EditorView["state"]): {
44+
from: number;
45+
to: number;
46+
} {
47+
const selection = state.selection.main;
48+
const startLine = state.doc.lineAt(selection.from);
49+
const endPos = selection.empty
50+
? selection.head
51+
: Math.max(selection.to - 1, selection.from);
52+
const endLine = state.doc.lineAt(endPos);
53+
const startRange = getLineSelectionRange(state, startLine);
54+
const endRange = getLineSelectionRange(state, endLine);
55+
56+
return {
57+
from: startRange?.from ?? selection.from,
58+
to: endRange?.to ?? selection.to,
59+
};
60+
}
61+
62+
function createLineSelection(range: {
63+
from: number;
64+
to: number;
65+
}): EditorSelection {
66+
return EditorSelection.single(range.to, range.from);
67+
}
68+
69+
function createExtendedLineSelection(
70+
state: EditorView["state"],
71+
clickedRange: { from: number; to: number },
72+
): EditorSelection {
73+
const currentRange = getCurrentSelectionLineRange(state);
74+
const from = Math.min(currentRange.from, clickedRange.from);
75+
const to = Math.max(currentRange.to, clickedRange.to);
76+
77+
if (clickedRange.from <= currentRange.from) {
78+
return EditorSelection.single(to, from);
79+
}
80+
81+
return EditorSelection.single(from, to);
82+
}
83+
84+
/**
85+
* Select the clicked line from the line-number gutter.
86+
* Shift-click extends the current selection by whole lines.
87+
* Other modified or non-primary clicks are ignored so they don't interfere
88+
* with context menus or alternate selection gestures.
89+
*/
90+
export function handleLineNumberClick(
91+
view: EditorView | null | undefined,
92+
line: LineInfo,
93+
event: LineNumberClickEvent | null | undefined,
94+
): boolean {
95+
if (!view || !event || event.defaultPrevented) return false;
96+
if ((event.button ?? 0) !== 0) return false;
97+
if (event.altKey || event.ctrlKey || event.metaKey) {
98+
return false;
99+
}
100+
101+
const range = getLineSelectionRange(view.state, line);
102+
if (!range) return false;
103+
104+
event.preventDefault();
105+
view.dispatch({
106+
selection: event.shiftKey
107+
? createExtendedLineSelection(view.state, range)
108+
: createLineSelection(range),
109+
userEvent: event.shiftKey ? "select.extend.pointer" : "select.pointer",
110+
});
111+
view.focus();
112+
return true;
113+
}
114+
115+
export default handleLineNumberClick;

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
}

0 commit comments

Comments
 (0)