@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.js CHANGED
@@ -1091,67 +1091,40 @@ exports.SelectionBridge = /*#__PURE__*/ function() {
1091
1091
  {
1092
1092
  key: "getVerticalMovePosition",
1093
1093
  value: /**
1094
- * 计算光标到下一行或上一行的位置
1095
- * @param currentPosition
1096
- * @param startLeft
1097
- * @param toNext
1098
- * @private
1094
+ * 通过遍历模型位置 + 视觉 rect 判断换行,计算光标到下一行或上一行的位置。
1095
+ * 不使用 Selection.modify(),避免复杂布局中的死循环。
1099
1096
  */ function getVerticalMovePosition(currentPosition, startLeft, toNext) {
1100
- var nativePos = this.findSelectedNodeAndOffset(currentPosition.slot, currentPosition.offset);
1101
- if (!nativePos) return currentPosition;
1102
- this.ignoreSelectionChange = true;
1103
- var sel = this.nativeSelection;
1104
- sel.removeAllRanges();
1105
- sel.setBaseAndExtent(nativePos.node, nativePos.offset, nativePos.node, nativePos.offset);
1106
- var startRect = getLayoutRectByRange(sel.getRangeAt(0).cloneRange());
1107
- var lastPos = currentPosition;
1108
- var prevRange = {
1109
- node: nativePos.node,
1110
- offset: nativePos.offset
1097
+ var _this = this;
1098
+ var startRect = this.getRect(currentPosition);
1099
+ if (!startRect) return currentPosition;
1100
+ var startTop = startRect.top;
1101
+ var startBottom = startTop + startRect.height;
1102
+ var step = toNext ? function(pos) {
1103
+ return _this.selection.getNextPositionByPosition(pos.slot, pos.offset);
1104
+ } : function(pos) {
1105
+ return _this.selection.getPreviousPositionByPosition(pos.slot, pos.offset);
1111
1106
  };
1107
+ var cur = currentPosition;
1112
1108
  while(true){
1113
- sel.modify('move', toNext ? 'forward' : 'backward', 'line');
1114
- var focusNode = sel.focusNode, focusOffset = sel.focusOffset;
1115
- if (!focusNode) break;
1116
- // 浏览器无法继续移动
1117
- if (prevRange && focusNode === prevRange.node && focusOffset === prevRange.offset) break;
1118
- prevRange = {
1119
- node: focusNode,
1120
- offset: focusOffset
1121
- };
1122
- // X 轴对齐
1123
- // const movedRect = getLayoutRectByRange(sel.getRangeAt(0).cloneRange())
1124
- // const xRefined = this.caretPositionFromPoint(startLeft, movedRect)
1125
- // if (xRefined) {
1126
- // focusNode = xRefined.offsetNode
1127
- // focusOffset = xRefined.offset
1128
- // }
1129
- var modelPos = this.getCorrectedPosition(focusNode, focusOffset, true);
1130
- if (!modelPos) {
1131
- lastPos = this.getDocumentBoundary(toNext);
1132
- break;
1109
+ var next = step(cur);
1110
+ if (next.slot === cur.slot && next.offset === cur.offset) break;
1111
+ var rect = this.getRect(next);
1112
+ if (!rect) break;
1113
+ cur = next;
1114
+ if (this.isDifferentLine(startTop, startBottom, rect, toNext)) {
1115
+ return this.refineXOnLine(cur, startLeft, rect);
1133
1116
  }
1134
- lastPos = modelPos;
1135
- var rect = this.getRect(modelPos);
1136
- // 仍未到达新行,继续 modify
1137
- if (this.isSameLine(startRect, rect, toNext)) continue;
1138
- // 已到达新行,沿该行微调 X
1139
- this.ignoreSelectionChange = false;
1140
- return this.refineXOnLine(modelPos, startLeft, rect);
1141
1117
  }
1142
- this.ignoreSelectionChange = false;
1143
- return lastPos;
1118
+ return this.getDocumentBoundary(toNext);
1144
1119
  }
1145
1120
  },
1146
1121
  {
1147
- key: "isSameLine",
1148
- value: /** 目标位置是否仍在当前视觉行内 */ function isSameLine(startRect, targetRect, toNext) {
1149
- var startBottom = startRect.top + startRect.height;
1150
- var targetBottom = targetRect.top + targetRect.height;
1122
+ key: "isDifferentLine",
1123
+ value: /** 目标位置是否已离开起始行 */ function isDifferentLine(startTop, startBottom, targetRect, toNext) {
1151
1124
  if (toNext) {
1152
- return targetRect.top <= startRect.top || targetBottom <= startBottom;
1125
+ return targetRect.top >= startBottom;
1153
1126
  }
1154
- return targetRect.top >= startRect.top || targetBottom >= startBottom;
1127
+ return targetRect.top + targetRect.height <= startTop;
1155
1128
  }
1156
1129
  },
1157
1130
  {
@@ -2210,9 +2183,7 @@ exports.MagicInput = /*#__PURE__*/ function(Input) {
2210
2183
  }), stream.fromEvent(textarea, 'focus').subscribe(function() {
2211
2184
  _this.nativeFocus = true;
2212
2185
  }), this.caret.onStyleChange.subscribe(function(style) {
2213
- Object.assign(textarea.style, {
2214
- fontSize: style.fontSize
2215
- });
2186
+ Object.assign(textarea.style, style);
2216
2187
  }));
2217
2188
  this.handleInput(textarea);
2218
2189
  this.handleShortcut(textarea);
@@ -2456,7 +2427,7 @@ exports.MagicInput = /*#__PURE__*/ function(Input) {
2456
2427
  border: 'none',
2457
2428
  width: '100%',
2458
2429
  display: 'block',
2459
- height: '16px',
2430
+ height: '100%',
2460
2431
  position: 'absolute',
2461
2432
  left: 0,
2462
2433
  bottom: this.isWindows ? '3px' : '0'