@textbus/platform-browser 5.4.10 → 5.4.11

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 CHANGED
@@ -1087,67 +1087,40 @@ var SelectionBridge = /*#__PURE__*/ function() {
1087
1087
  {
1088
1088
  key: "getVerticalMovePosition",
1089
1089
  value: /**
1090
- * 计算光标到下一行或上一行的位置
1091
- * @param currentPosition
1092
- * @param startLeft
1093
- * @param toNext
1094
- * @private
1090
+ * 通过遍历模型位置 + 视觉 rect 判断换行,计算光标到下一行或上一行的位置。
1091
+ * 不使用 Selection.modify(),避免复杂布局中的死循环。
1095
1092
  */ function getVerticalMovePosition(currentPosition, startLeft, toNext) {
1096
- var nativePos = this.findSelectedNodeAndOffset(currentPosition.slot, currentPosition.offset);
1097
- if (!nativePos) return currentPosition;
1098
- this.ignoreSelectionChange = true;
1099
- var sel = this.nativeSelection;
1100
- sel.removeAllRanges();
1101
- sel.setBaseAndExtent(nativePos.node, nativePos.offset, nativePos.node, nativePos.offset);
1102
- var startRect = getLayoutRectByRange(sel.getRangeAt(0).cloneRange());
1103
- var lastPos = currentPosition;
1104
- var prevRange = {
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
- sel.modify('move', toNext ? 'forward' : 'backward', 'line');
1110
- var focusNode = sel.focusNode, focusOffset = sel.focusOffset;
1111
- if (!focusNode) break;
1112
- // 浏览器无法继续移动
1113
- if (prevRange && focusNode === prevRange.node && focusOffset === prevRange.offset) break;
1114
- prevRange = {
1115
- node: focusNode,
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.ignoreSelectionChange = false;
1139
- return lastPos;
1114
+ return this.getDocumentBoundary(toNext);
1140
1115
  }
1141
1116
  },
1142
1117
  {
1143
- key: "isSameLine",
1144
- value: /** 目标位置是否仍在当前视觉行内 */ function isSameLine(startRect, targetRect, toNext) {
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 <= startRect.top || targetBottom <= startBottom;
1121
+ return targetRect.top >= startBottom;
1149
1122
  }
1150
- return targetRect.top >= startRect.top || targetBottom >= startBottom;
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: '16px',
2426
+ height: '100%',
2456
2427
  position: 'absolute',
2457
2428
  left: 0,
2458
2429
  bottom: this.isWindows ? '3px' : '0'