Skip to content

Commit 33d784e

Browse files
committed
fix indent guide setting issue
1 parent c09dc06 commit 33d784e

File tree

3 files changed

+79
-29
lines changed

3 files changed

+79
-29
lines changed

src/cm/mainEditorExtensions.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { Extension } from "@codemirror/state";
2+
import { EditorView, scrollPastEnd } from "@codemirror/view";
3+
4+
interface MainEditorExtensionOptions {
5+
emmetExtensions?: Extension[];
6+
baseExtensions?: Extension[];
7+
commandKeymapExtension?: Extension;
8+
themeExtension?: Extension;
9+
pointerCursorVisibilityExtension?: Extension;
10+
shiftClickSelectionExtension?: Extension;
11+
touchSelectionUpdateExtension?: Extension;
12+
searchExtension?: Extension;
13+
readOnlyExtension?: Extension;
14+
optionExtensions?: Extension[];
15+
}
16+
17+
function pushExtension(target: Extension[], extension?: Extension): void {
18+
if (extension == null) return;
19+
target.push(extension);
20+
}
21+
22+
export const fixedHeightTheme = EditorView.theme({
23+
"&": { height: "100%" },
24+
".cm-scroller": { height: "100%", overflow: "auto" },
25+
});
26+
27+
export function createMainEditorExtensions(
28+
options: MainEditorExtensionOptions = {},
29+
): Extension[] {
30+
const extensions: Extension[] = [];
31+
32+
if (options.emmetExtensions?.length) {
33+
extensions.push(...options.emmetExtensions);
34+
}
35+
if (options.baseExtensions?.length) {
36+
extensions.push(...options.baseExtensions);
37+
}
38+
39+
pushExtension(extensions, options.commandKeymapExtension);
40+
pushExtension(extensions, options.themeExtension);
41+
extensions.push(fixedHeightTheme);
42+
extensions.push(scrollPastEnd());
43+
pushExtension(extensions, options.pointerCursorVisibilityExtension);
44+
pushExtension(extensions, options.shiftClickSelectionExtension);
45+
pushExtension(extensions, options.touchSelectionUpdateExtension);
46+
pushExtension(extensions, options.searchExtension);
47+
pushExtension(extensions, options.readOnlyExtension);
48+
49+
if (options.optionExtensions?.length) {
50+
extensions.push(...options.optionExtensions);
51+
}
52+
53+
return extensions;
54+
}
55+
56+
export default createMainEditorExtensions;

src/lib/editorManager.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
highlightWhitespace,
1717
keymap,
1818
lineNumbers,
19-
scrollPastEnd,
2019
} from "@codemirror/view";
2120
import {
2221
abbreviationTracker,
@@ -27,6 +26,7 @@ import {
2726
wrapWithAbbreviation,
2827
} from "@emmetio/codemirror6-plugin";
2928
import createBaseExtensions from "cm/baseExtensions";
29+
import createMainEditorExtensions from "cm/mainEditorExtensions";
3030
import {
3131
setKeyBindings as applyKeyBindings,
3232
executeCommand,
@@ -163,12 +163,6 @@ async function EditorManager($header, $body) {
163163
},
164164
});
165165

166-
// Make CodeMirror fill the container height and manage scrolling internally
167-
const fixedHeightTheme = EditorView.theme({
168-
"&": { height: "100%" },
169-
".cm-scroller": { height: "100%", overflow: "auto" },
170-
});
171-
172166
const pointerCursorVisibilityExtension = EditorView.updateListener.of(
173167
(update) => {
174168
if (!update.selectionSet) return;
@@ -764,24 +758,25 @@ async function EditorManager($header, $body) {
764758
// Create minimal CodeMirror editor
765759
const editorState = EditorState.create({
766760
doc: "",
767-
extensions: [
761+
extensions: createMainEditorExtensions({
768762
// Emmet needs highest precedence so place before default keymaps
769-
...createEmmetExtensionSet({ syntax: EmmetKnownSyntax.html }),
770-
...createBaseExtensions(),
771-
getCommandKeymapExtension(),
772-
// Default theme
773-
themeCompartment.of(oneDark),
774-
fixedHeightTheme,
775-
scrollPastEnd(),
763+
emmetExtensions: createEmmetExtensionSet({
764+
syntax: EmmetKnownSyntax.html,
765+
}),
766+
baseExtensions: createBaseExtensions(),
767+
commandKeymapExtension: getCommandKeymapExtension(),
768+
themeExtension: themeCompartment.of(oneDark),
776769
pointerCursorVisibilityExtension,
777770
shiftClickSelectionExtension,
778771
touchSelectionUpdateExtension,
779-
search(),
772+
searchExtension: search(),
780773
// Ensure read-only can be toggled later via compartment
781-
readOnlyCompartment.of(EditorState.readOnly.of(false)),
774+
readOnlyExtension: readOnlyCompartment.of(
775+
EditorState.readOnly.of(false),
776+
),
782777
// Editor options driven by settings via compartments
783-
...getBaseExtensionsFromOptions(),
784-
],
778+
optionExtensions: getBaseExtensionsFromOptions(),
779+
}),
785780
});
786781

787782
const editor = new EditorView({
@@ -1128,22 +1123,20 @@ async function EditorManager($header, $body) {
11281123
function applyFileToEditor(file) {
11291124
if (!file || file.type !== "editor") return;
11301125
const syntax = getEmmetSyntaxForFile(file);
1131-
const baseExtensions = [
1126+
const baseExtensions = createMainEditorExtensions({
11321127
// Emmet needs to precede default keymaps so tracker Tab wins over indent
1133-
...createEmmetExtensionSet({ syntax }),
1134-
...createBaseExtensions(),
1135-
getCommandKeymapExtension(),
1128+
emmetExtensions: createEmmetExtensionSet({ syntax }),
1129+
baseExtensions: createBaseExtensions(),
1130+
commandKeymapExtension: getCommandKeymapExtension(),
11361131
// keep compartment in the state to allow dynamic theme changes later
1137-
themeCompartment.of(oneDark),
1138-
fixedHeightTheme,
1139-
scrollPastEnd(),
1132+
themeExtension: themeCompartment.of(oneDark),
11401133
pointerCursorVisibilityExtension,
11411134
shiftClickSelectionExtension,
11421135
touchSelectionUpdateExtension,
1143-
search(),
1136+
searchExtension: search(),
11441137
// Keep dynamic compartments across state swaps
1145-
...getBaseExtensionsFromOptions(),
1146-
];
1138+
optionExtensions: getBaseExtensionsFromOptions(),
1139+
});
11471140
const exts = [...baseExtensions];
11481141
maybeAttachEmmetCompletions(exts, syntax);
11491142
try {

src/lib/settings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class Settings {
179179
showSponsorSidebarApp: true,
180180
showAnnotations: false,
181181
lintGutter: true,
182+
indentGuides: true,
182183
rainbowBrackets: true,
183184
pluginsDisabled: {}, // pluginId: true/false
184185
lsp: {

0 commit comments

Comments
 (0)