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

Function focusCodeMirror

vditor/src/ts/codeBlock/codeMirrorManager.ts:1694–1735  ·  view source on GitHub ↗
(
    blockElement: HTMLElement,
    collapseToStart = true,
    vditor?: IVditor,
)

Source from the content-addressed store, hash-verified

1692 preserveEditorScroll(vditor, apply);
1693};
1694
1695export const focusCodeMirror = (
1696 blockElement: HTMLElement,
1697 collapseToStart = true,
1698 vditor?: IVditor,
1699) => {
1700 if (!blockElement) {
1701 return;
1702 }
1703 if (!bindings.get(blockElement) && vditor) {
1704 if (isLazyManagedCodeBlock(blockElement)) {
1705 enforceMaxMounted(vditor, blockElement);
1706 }
1707 mountCodeMirror(blockElement, vditor, true);
1708 }
1709 const binding = bindings.get(blockElement);
1710 if (!binding) {
1711 return;
1712 }
1713 const hadFocus = binding.view.hasFocus;
1714 const applyFocus = () => {
1715 focusCmViewWithoutScroll(binding.view);
1716 if (!hadFocus) {
1717 if (collapseToStart) {
1718 binding.view.dispatch({
1719 selection: { anchor: 0, head: 0 },
1720 scrollIntoView: false,
1721 });
1722 } else {
1723 const length = binding.view.state.doc.length;
1724 binding.view.dispatch({
1725 selection: { anchor: length, head: length },
1726 scrollIntoView: false,
1727 });
1728 }
1729 }
1730 };
1731 if (vditor) {
1732 preserveEditorScroll(vditor, applyFocus);
1733 } else {
1734 applyFocus();
1735 }
1736};
1737
1738/** @deprecated use focusCodeMirror */

Callers 9

processKeydownFunction · 0.90
syncMathBlockDisplayModeFunction · 0.85
enterSpecialBlockEditFunction · 0.85
focusAdjacentEditorBlockFunction · 0.85
removeCmCodeBlockFunction · 0.85
applyFunction · 0.85
focusCodeBlockFunction · 0.85

Calls 6

preserveEditorScrollFunction · 0.90
isLazyManagedCodeBlockFunction · 0.85
enforceMaxMountedFunction · 0.85
mountCodeMirrorFunction · 0.85
applyFocusFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected