@textbus/platform-browser 5.4.10 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +26 -55
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -55
- package/dist/index.js.map +1 -1
- package/dist/selection-bridge.d.ts +4 -7
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1087,67 +1087,40 @@ var SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1087
1087
|
{
|
|
1088
1088
|
key: "getVerticalMovePosition",
|
|
1089
1089
|
value: /**
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
* @param startLeft
|
|
1093
|
-
* @param toNext
|
|
1094
|
-
* @private
|
|
1090
|
+
* 通过遍历模型位置 + 视觉 rect 判断换行,计算光标到下一行或上一行的位置。
|
|
1091
|
+
* 不使用 Selection.modify(),避免复杂布局中的死循环。
|
|
1095
1092
|
*/ function getVerticalMovePosition(currentPosition, startLeft, toNext) {
|
|
1096
|
-
var
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
var
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
node: nativePos.node,
|
|
1106
|
-
offset: nativePos.offset
|
|
1093
|
+
var _this = this;
|
|
1094
|
+
var startRect = this.getRect(currentPosition);
|
|
1095
|
+
if (!startRect) return currentPosition;
|
|
1096
|
+
var startTop = startRect.top;
|
|
1097
|
+
var startBottom = startTop + startRect.height;
|
|
1098
|
+
var step = toNext ? function(pos) {
|
|
1099
|
+
return _this.selection.getNextPositionByPosition(pos.slot, pos.offset);
|
|
1100
|
+
} : function(pos) {
|
|
1101
|
+
return _this.selection.getPreviousPositionByPosition(pos.slot, pos.offset);
|
|
1107
1102
|
};
|
|
1103
|
+
var cur = currentPosition;
|
|
1108
1104
|
while(true){
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
offset: focusOffset
|
|
1117
|
-
};
|
|
1118
|
-
// X 轴对齐
|
|
1119
|
-
// const movedRect = getLayoutRectByRange(sel.getRangeAt(0).cloneRange())
|
|
1120
|
-
// const xRefined = this.caretPositionFromPoint(startLeft, movedRect)
|
|
1121
|
-
// if (xRefined) {
|
|
1122
|
-
// focusNode = xRefined.offsetNode
|
|
1123
|
-
// focusOffset = xRefined.offset
|
|
1124
|
-
// }
|
|
1125
|
-
var modelPos = this.getCorrectedPosition(focusNode, focusOffset, true);
|
|
1126
|
-
if (!modelPos) {
|
|
1127
|
-
lastPos = this.getDocumentBoundary(toNext);
|
|
1128
|
-
break;
|
|
1105
|
+
var next = step(cur);
|
|
1106
|
+
if (next.slot === cur.slot && next.offset === cur.offset) break;
|
|
1107
|
+
var rect = this.getRect(next);
|
|
1108
|
+
if (!rect) break;
|
|
1109
|
+
cur = next;
|
|
1110
|
+
if (this.isDifferentLine(startTop, startBottom, rect, toNext)) {
|
|
1111
|
+
return this.refineXOnLine(cur, startLeft, rect);
|
|
1129
1112
|
}
|
|
1130
|
-
lastPos = modelPos;
|
|
1131
|
-
var rect = this.getRect(modelPos);
|
|
1132
|
-
// 仍未到达新行,继续 modify
|
|
1133
|
-
if (this.isSameLine(startRect, rect, toNext)) continue;
|
|
1134
|
-
// 已到达新行,沿该行微调 X
|
|
1135
|
-
this.ignoreSelectionChange = false;
|
|
1136
|
-
return this.refineXOnLine(modelPos, startLeft, rect);
|
|
1137
1113
|
}
|
|
1138
|
-
this.
|
|
1139
|
-
return lastPos;
|
|
1114
|
+
return this.getDocumentBoundary(toNext);
|
|
1140
1115
|
}
|
|
1141
1116
|
},
|
|
1142
1117
|
{
|
|
1143
|
-
key: "
|
|
1144
|
-
value: /**
|
|
1145
|
-
var startBottom = startRect.top + startRect.height;
|
|
1146
|
-
var targetBottom = targetRect.top + targetRect.height;
|
|
1118
|
+
key: "isDifferentLine",
|
|
1119
|
+
value: /** 目标位置是否已离开起始行 */ function isDifferentLine(startTop, startBottom, targetRect, toNext) {
|
|
1147
1120
|
if (toNext) {
|
|
1148
|
-
return targetRect.top
|
|
1121
|
+
return targetRect.top >= startBottom;
|
|
1149
1122
|
}
|
|
1150
|
-
return targetRect.top
|
|
1123
|
+
return targetRect.top + targetRect.height <= startTop;
|
|
1151
1124
|
}
|
|
1152
1125
|
},
|
|
1153
1126
|
{
|
|
@@ -2206,9 +2179,7 @@ var MagicInput = /*#__PURE__*/ function(Input) {
|
|
|
2206
2179
|
}), fromEvent(textarea, 'focus').subscribe(function() {
|
|
2207
2180
|
_this.nativeFocus = true;
|
|
2208
2181
|
}), this.caret.onStyleChange.subscribe(function(style) {
|
|
2209
|
-
Object.assign(textarea.style,
|
|
2210
|
-
fontSize: style.fontSize
|
|
2211
|
-
});
|
|
2182
|
+
Object.assign(textarea.style, style);
|
|
2212
2183
|
}));
|
|
2213
2184
|
this.handleInput(textarea);
|
|
2214
2185
|
this.handleShortcut(textarea);
|
|
@@ -2452,7 +2423,7 @@ var MagicInput = /*#__PURE__*/ function(Input) {
|
|
|
2452
2423
|
border: 'none',
|
|
2453
2424
|
width: '100%',
|
|
2454
2425
|
display: 'block',
|
|
2455
|
-
height: '
|
|
2426
|
+
height: '100%',
|
|
2456
2427
|
position: 'absolute',
|
|
2457
2428
|
left: 0,
|
|
2458
2429
|
bottom: this.isWindows ? '3px' : '0'
|