@expensify/react-native-live-markdown 0.1.114 → 0.1.116
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/lib/commonjs/web/cursorUtils.js +15 -4
- package/lib/commonjs/web/cursorUtils.js.map +1 -1
- package/lib/module/web/cursorUtils.js +15 -4
- package/lib/module/web/cursorUtils.js.map +1 -1
- package/lib/parser/react-native-live-markdown-parser.js +1 -1
- package/lib/typescript/src/web/cursorUtils.d.ts.map +1 -1
- package/package.json +1 -1
- package/parser/react-native-live-markdown-parser.js +1 -1
- package/src/web/cursorUtils.ts +16 -4
package/src/web/cursorUtils.ts
CHANGED
|
@@ -145,18 +145,30 @@ function scrollCursorIntoView(target: HTMLInputElement) {
|
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
const
|
|
148
|
+
const caretRects = selection.getRangeAt(0).getClientRects();
|
|
149
|
+
|
|
150
|
+
// we'll find the caretRect from the DOMRectList above with the largest bottom value
|
|
151
|
+
let currentCaretRect = caretRects[0];
|
|
152
|
+
if (currentCaretRect) {
|
|
153
|
+
for (let i = 1; i < caretRects.length; i++) {
|
|
154
|
+
const caretRect = caretRects[i];
|
|
155
|
+
if (caretRect && caretRect.bottom > currentCaretRect.bottom) {
|
|
156
|
+
currentCaretRect = caretRect;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
149
161
|
const editableRect = target.getBoundingClientRect();
|
|
150
162
|
|
|
151
163
|
// Adjust for padding and border
|
|
152
164
|
const paddingTop = parseFloat(window.getComputedStyle(target).paddingTop);
|
|
153
165
|
const borderTop = parseFloat(window.getComputedStyle(target).borderTopWidth);
|
|
154
166
|
|
|
155
|
-
if (
|
|
156
|
-
const topToCaret =
|
|
167
|
+
if (currentCaretRect && !(currentCaretRect.top >= editableRect.top + paddingTop + borderTop && currentCaretRect.bottom <= editableRect.bottom - 2 * (paddingTop - borderTop))) {
|
|
168
|
+
const topToCaret = currentCaretRect.top - editableRect.top;
|
|
157
169
|
const inputHeight = editableRect.height;
|
|
158
170
|
// Chrome Rects don't include padding & border, so we're adding them manually
|
|
159
|
-
const inputOffset =
|
|
171
|
+
const inputOffset = currentCaretRect.height - inputHeight + paddingTop + borderTop + (BrowserUtils.isChromium ? 0 : 4 * (paddingTop + borderTop));
|
|
160
172
|
|
|
161
173
|
target.scrollTo(0, topToCaret + target.scrollTop + inputOffset);
|
|
162
174
|
}
|