完全跑通1.0版本
This commit is contained in:
37
frontend/node_modules/element-plus/lib/hooks/use-cursor/index.js
generated
vendored
Normal file
37
frontend/node_modules/element-plus/lib/hooks/use-cursor/index.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
//#region ../../packages/hooks/use-cursor/index.ts
|
||||
function useCursor(input) {
|
||||
let selectionInfo;
|
||||
function recordCursor() {
|
||||
if (input.value == void 0) return;
|
||||
const { selectionStart, selectionEnd, value } = input.value;
|
||||
if (selectionStart == null || selectionEnd == null) return;
|
||||
selectionInfo = {
|
||||
selectionStart,
|
||||
selectionEnd,
|
||||
value,
|
||||
beforeTxt: value.slice(0, Math.max(0, selectionStart)),
|
||||
afterTxt: value.slice(Math.max(0, selectionEnd))
|
||||
};
|
||||
}
|
||||
function setCursor() {
|
||||
if (input.value == void 0 || selectionInfo == void 0) return;
|
||||
const { value } = input.value;
|
||||
const { beforeTxt, afterTxt, selectionStart } = selectionInfo;
|
||||
if (beforeTxt == void 0 || afterTxt == void 0 || selectionStart == void 0) return;
|
||||
let startPos = value.length;
|
||||
if (value.endsWith(afterTxt)) startPos = value.length - afterTxt.length;
|
||||
else if (value.startsWith(beforeTxt)) startPos = beforeTxt.length;
|
||||
else {
|
||||
const beforeLastChar = beforeTxt[selectionStart - 1];
|
||||
const newIndex = value.indexOf(beforeLastChar, selectionStart - 1);
|
||||
if (newIndex !== -1) startPos = newIndex + 1;
|
||||
}
|
||||
input.value.setSelectionRange(startPos, startPos);
|
||||
}
|
||||
return [recordCursor, setCursor];
|
||||
}
|
||||
//#endregion
|
||||
exports.useCursor = useCursor;
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
Reference in New Issue
Block a user