MCPcopy Create free account
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / initCodeMirror

Method initCodeMirror

src/code_view.ts:1102–1263  ·  view source on GitHub ↗
(root: HTMLElement)

Source from the content-addressed store, hash-verified

1100 }
1101
1102 private initCodeMirror(root: HTMLElement): void {
1103 const baseExtensions = [
1104 baseTheme,
1105 this.fontSizeCompartment.of(this.getFontSizeExtension()), // 字体大小管理
1106 this.lineNumbersCompartment.of(this.getLineNumbersExtension()),
1107 this.languageCompartment.of([]), // Start with empty, will be updated in onLoadFile
1108 highlightSpecialChars(),
1109 history(),
1110 foldGutter(),
1111 drawSelection(),
1112 indentOnInput(),
1113 bracketMatching(),
1114 closeBrackets(),
1115 highlightActiveLine(),
1116 indentUnit.of(" "),
1117 // 不使用默认的 search 扩展,改用自定义搜索面板
1118 highlightSelectionMatches(), // 高亮选中文本的匹配项
1119 keymap.of([
1120 ...defaultKeymap,
1121 ...historyKeymap,
1122 indentWithTab
1123 ]),
1124 // 使用最高优先级注册自定义快捷键,防止被 Obsidian 全局快捷键拦截
1125 Prec.highest(keymap.of([
1126 {
1127 key: "Mod-s",
1128 run: () => {
1129 void this.save();
1130 return true;
1131 }
1132 },
1133 {
1134 key: "Mod-f",
1135 run: () => {
1136 this.openSearchFromHotkey("find");
1137 return true;
1138 }
1139 },
1140 {
1141 key: "Mod-h",
1142 run: () => {
1143 this.openSearchFromHotkey("replace");
1144 return true;
1145 }
1146 },
1147 // macOS: Cmd+Alt+F is a common "Replace" shortcut (Cmd+H is reserved by the OS).
1148 {
1149 key: "Mod-Alt-f",
1150 run: () => {
1151 this.openSearchFromHotkey("replace");
1152 return true;
1153 }
1154 }
1155 ])),
1156 EditorView.updateListener.of((update) => {
1157 if (update.docChanged) {
1158 // 如果正在设置数据,不标记为 dirty
1159 if (this.isSettingData) {

Callers 1

initEditorMethod · 0.95

Calls 12

getFontSizeExtensionMethod · 0.95
saveMethod · 0.95
openSearchFromHotkeyMethod · 0.95
updateTitleMethod · 0.95
getThemeExtensionMethod · 0.95
toggleSearchPanelMethod · 0.95
getPluginMethod · 0.95
setupZoomHandlerMethod · 0.95
tFunction · 0.90

Tested by

no test coverage detected