-
请问定位光标到上一次的位置呢?
2021-04-10 02:13我把源码中的
getEditorRange
,setSelectionFocus
扒下来实现了const getEditorRange = (vditor):Range => { let range: Range; const element = vditor[vditor.currentMode].element; if (getSelection().rangeCount > 0) { range = getSelection().getRangeAt(0); if (element.isEqualNode(range.startContainer) || element.contains(range.startContainer)) { return range; } } if (vditor[vditor.currentMode].range) { return vditor[vditor.currentMode].range; } element.focus(); range = element.ownerDocument.createRange(); range.setStart(element, 0); range.collapse(true); return range; }; const setSelectionFocus = (range: Range) => { const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); }
我为什么要扒下来?一开始我是采用导入的方式的
import { getEditorRange } from 'vditor/src/ts/util/selection';
引用
getEditorRange
后提示我找不到VDITOR_VERSION
,然后我引用如下import { VDITOR_VERSION } from 'vditor/src/ts/constants'; import { getEditorRange } from 'vditor/src/ts/util/selection';
还是报错。。。。无奈只好 copy 到方法中来了
求更好的实现方法