MCPcopy Create free account
hub / github.com/cweijan/vscode-office / removeCmCodeBlock

Function removeCmCodeBlock

vditor/src/ts/codeBlock/codeMirrorManager.ts:1258–1334  ·  view source on GitHub ↗
(vditor: IVditor, blockElement: HTMLElement)

Source from the content-addressed store, hash-verified

1256 },
1257 ]));
1258
1259export const removeCmCodeBlock = (vditor: IVditor, blockElement: HTMLElement) => {
1260 if (!isCmCodeBlock(blockElement)) {
1261 return;
1262 }
1263
1264 const editor = getModeEditor(vditor);
1265 if (!editor) {
1266 blockElement.remove();
1267 return;
1268 }
1269
1270 const previousElement = blockElement.previousElementSibling as HTMLElement | null;
1271 const nextElement = blockElement.nextElementSibling as HTMLElement | null;
1272
1273 const binding = bindings.get(blockElement);
1274 if (binding) {
1275 window.clearTimeout(binding.syncTimer);
1276 window.clearTimeout(binding.previewTimer);
1277 binding.syncCode.textContent = binding.view.state.doc.toString();
1278 binding.view.destroy();
1279 bindings.delete(blockElement);
1280 binding.editPre.querySelector(".cm-editor")?.remove();
1281 }
1282 removeCodeBlockChrome(blockElement);
1283 blockElement.remove();
1284
1285 focusEditorWithoutScroll(editor);
1286 const range = getEditorRange(vditor);
1287
1288 if (previousElement) {
1289 if (isCmCodeBlock(previousElement)) {
1290 focusCodeMirror(previousElement, false, vditor);
1291 } else {
1292 range.selectNodeContents(previousElement);
1293 range.collapse(false);
1294 setSelectionFocus(range);
1295 if (vditor.currentMode === "ir") {
1296 expandMarker(range, vditor.ir.element);
1297 syncIrMathBlockAfterExpand(vditor, range);
1298 }
1299 }
1300 } else if (nextElement) {
1301 if (isCmCodeBlock(nextElement)) {
1302 focusCodeMirror(nextElement, true, vditor);
1303 } else {
1304 range.selectNodeContents(nextElement);
1305 range.collapse(true);
1306 setSelectionFocus(range);
1307 if (vditor.currentMode === "ir") {
1308 expandMarker(range, vditor.ir.element);
1309 syncIrMathBlockAfterExpand(vditor, range);
1310 }
1311 }
1312 } else {
1313 editor.insertAdjacentHTML("beforeend", `<p data-block="0">${Constants.ZWSP}<wbr></p>`);
1314 setRangeByWbr(editor, range);
1315 setSelectionFocus(range);

Callers 2

bindDeleteButtonFunction · 0.90

Calls 15

removeCodeBlockChromeFunction · 0.90
getEditorRangeFunction · 0.90
setSelectionFocusFunction · 0.90
expandMarkerFunction · 0.90
setRangeByWbrFunction · 0.90
afterRenderEventFunction · 0.90
processAfterRenderFunction · 0.90
isCmCodeBlockFunction · 0.85
focusCodeMirrorFunction · 0.85
addToUndoStackMethod · 0.80
getModeEditorFunction · 0.70

Tested by

no test coverage detected