slate-react 0.72.4-2022010232811 → 0.72.4-2022011114342
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/CHANGELOG.md +7 -2
- package/dist/components/android/android-editable.d.ts.map +1 -1
- package/dist/components/android/android-input-manager.d.ts.map +1 -1
- package/dist/index.es.js +229 -278
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +225 -272
- package/dist/index.js.map +1 -1
- package/dist/slate-react.js +225 -272
- package/dist/slate-react.min.js +1 -1
- package/dist/utils/weak-maps.d.ts +0 -7
- package/dist/utils/weak-maps.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# slate-react
|
|
2
2
|
|
|
3
|
-
## 0.72.4-
|
|
3
|
+
## 0.72.4-2022011114342
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- [#4753](https://github.com/ianstormtaylor/slate/pull/4753) [`e9a46ad2`](https://github.com/ianstormtaylor/slate/commit/e9a46ad29e0376a45051c4a8100c5678784b785c) Thanks [@alessiogaldy](https://github.com/alessiogaldy)! - Fix "editor.insertText never gets called inside plugins on android"
|
|
8
8
|
|
|
9
|
-
* [#
|
|
9
|
+
* [#4779](https://github.com/ianstormtaylor/slate/pull/4779) [`345b8fc9`](https://github.com/ianstormtaylor/slate/commit/345b8fc9e8f073674c006098bd843823309db2e2) Thanks [@alessiogaldy](https://github.com/alessiogaldy)! - Android editable updates
|
|
10
|
+
|
|
11
|
+
- Remove logic to delay handling of text insertion
|
|
12
|
+
- Call Transforms.setSelection before Editor.insertText to adjust position
|
|
13
|
+
|
|
14
|
+
- [#4755](https://github.com/ianstormtaylor/slate/pull/4755) [`8daa77e9`](https://github.com/ianstormtaylor/slate/commit/8daa77e9fab6b222ad796b420b86f3ec88999a39) Thanks [@jhurwitz](https://github.com/jhurwitz)! - fix useFocused hook
|
|
10
15
|
|
|
11
16
|
## 0.72.2
|
|
12
17
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android-editable.d.ts","sourceRoot":"","sources":["../../packages/slate-react/src/components/android/android-editable.tsx"],"names":[],"mappings":";AACA,OAAO,EAAU,OAAO,EAAuC,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"android-editable.d.ts","sourceRoot":"","sources":["../../packages/slate-react/src/components/android/android-editable.tsx"],"names":[],"mappings":";AACA,OAAO,EAAU,OAAO,EAAuC,MAAM,OAAO,CAAA;AA2B5E,OAAO,EAAE,aAAa,EAAa,MAAM,aAAa,CAAA;AAqBtD,eAAO,MAAM,eAAe,UAAW,aAAa,KAAG,GAAG,CAAC,OAshB1D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android-input-manager.d.ts","sourceRoot":"","sources":["../../packages/slate-react/src/components/android/android-input-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"android-input-manager.d.ts","sourceRoot":"","sources":["../../packages/slate-react/src/components/android/android-input-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAmBvD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,qBAAa,mBAAmB;IAClB,OAAO,CAAC,MAAM;IAAe,OAAO,CAAC,UAAU;gBAAvC,MAAM,EAAE,WAAW,EAAU,UAAU,EAAE,MAAM,IAAI;IAKvE;;;;OAIG;IAEH,KAAK,cAAe,cAAc,EAAE,UAYnC;IAED;;;;OAIG;IAEH,OAAO,CAAC,kBAAkB,CAkBzB;IAED;;OAEG;IAEH,OAAO,CAAC,UAAU,CAsBjB;IAED;;OAEG;IAEH,OAAO,CAAC,WAAW,CAoBlB;IAED;;OAEG;IAEH,OAAO,CAAC,wBAAwB,CAY/B;IAED;;OAEG;IAEH,OAAO,CAAC,cAAc,CAOrB;IAED;;OAEG;IACH,OAAO,CAAC,eAAe,CAWtB;CACF;AAED,eAAe,mBAAmB,CAAA"}
|
package/dist/index.es.js
CHANGED
|
@@ -181,13 +181,6 @@ var EDITOR_TO_KEY_TO_ELEMENT = new WeakMap();
|
|
|
181
181
|
|
|
182
182
|
var IS_READ_ONLY = new WeakMap();
|
|
183
183
|
var IS_FOCUSED = new WeakMap();
|
|
184
|
-
var IS_COMPOSING = new WeakMap();
|
|
185
|
-
var IS_ON_COMPOSITION_END = new WeakMap();
|
|
186
|
-
/**
|
|
187
|
-
* Weak maps for saving text on composition stage.
|
|
188
|
-
*/
|
|
189
|
-
|
|
190
|
-
var EDITOR_ON_COMPOSITION_TEXT = new WeakMap();
|
|
191
184
|
/**
|
|
192
185
|
* Weak map for associating the context `onChange` context with the plugin.
|
|
193
186
|
*/
|
|
@@ -2162,233 +2155,6 @@ var isDOMEventHandled = (event, handler) => {
|
|
|
2162
2155
|
return event.defaultPrevented;
|
|
2163
2156
|
};
|
|
2164
2157
|
|
|
2165
|
-
/**
|
|
2166
|
-
* Returns the number of characters that are the same at the beginning of the
|
|
2167
|
-
* String.
|
|
2168
|
-
*
|
|
2169
|
-
* @param prev the previous text
|
|
2170
|
-
* @param next the next text
|
|
2171
|
-
* @returns the offset of the start of the difference; null if there is no difference
|
|
2172
|
-
*/
|
|
2173
|
-
|
|
2174
|
-
function getDiffStart(prev, next) {
|
|
2175
|
-
var length = Math.min(prev.length, next.length);
|
|
2176
|
-
|
|
2177
|
-
for (var i = 0; i < length; i++) {
|
|
2178
|
-
if (prev.charAt(i) !== next.charAt(i)) return i;
|
|
2179
|
-
}
|
|
2180
|
-
|
|
2181
|
-
if (prev.length !== next.length) return length;
|
|
2182
|
-
return null;
|
|
2183
|
-
}
|
|
2184
|
-
/**
|
|
2185
|
-
* Returns the number of characters that are the same at the end of the String
|
|
2186
|
-
* up to `max`. Max prevents double-counting characters when there are
|
|
2187
|
-
* multiple duplicate characters around the diff area.
|
|
2188
|
-
*
|
|
2189
|
-
* @param prev the previous text
|
|
2190
|
-
* @param next the next text
|
|
2191
|
-
* @param max the max length to test.
|
|
2192
|
-
* @returns number of characters that are the same at the end of the string
|
|
2193
|
-
*/
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
function getDiffEnd(prev, next, max) {
|
|
2197
|
-
var prevLength = prev.length;
|
|
2198
|
-
var nextLength = next.length;
|
|
2199
|
-
var length = Math.min(prevLength, nextLength, max);
|
|
2200
|
-
|
|
2201
|
-
for (var i = 0; i < length; i++) {
|
|
2202
|
-
var prevChar = prev.charAt(prevLength - i - 1);
|
|
2203
|
-
var nextChar = next.charAt(nextLength - i - 1);
|
|
2204
|
-
if (prevChar !== nextChar) return i;
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
if (prev.length !== next.length) return length;
|
|
2208
|
-
return null;
|
|
2209
|
-
}
|
|
2210
|
-
/**
|
|
2211
|
-
* Takes two strings and returns an object representing two offsets. The
|
|
2212
|
-
* first, `start` represents the number of characters that are the same at
|
|
2213
|
-
* the front of the String. The `end` represents the number of characters
|
|
2214
|
-
* that are the same at the end of the String.
|
|
2215
|
-
*
|
|
2216
|
-
* Returns null if they are identical.
|
|
2217
|
-
*
|
|
2218
|
-
* @param prev the previous text
|
|
2219
|
-
* @param next the next text
|
|
2220
|
-
* @returns the difference text range; null if there are no differences.
|
|
2221
|
-
*/
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
function getDiffOffsets(prev, next) {
|
|
2225
|
-
if (prev === next) return null;
|
|
2226
|
-
var start = getDiffStart(prev, next);
|
|
2227
|
-
if (start === null) return null;
|
|
2228
|
-
var maxEnd = Math.min(prev.length - start, next.length - start);
|
|
2229
|
-
var end = getDiffEnd(prev, next, maxEnd);
|
|
2230
|
-
if (end === null) return null;
|
|
2231
|
-
return {
|
|
2232
|
-
start,
|
|
2233
|
-
end
|
|
2234
|
-
};
|
|
2235
|
-
}
|
|
2236
|
-
/**
|
|
2237
|
-
* Takes a text string and returns a slice from the string at the given text range
|
|
2238
|
-
*
|
|
2239
|
-
* @param text the text
|
|
2240
|
-
* @param offsets the text range
|
|
2241
|
-
* @returns the text slice at text range
|
|
2242
|
-
*/
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
function sliceText(text, offsets) {
|
|
2246
|
-
return text.slice(offsets.start, text.length - offsets.end);
|
|
2247
|
-
}
|
|
2248
|
-
/**
|
|
2249
|
-
* Takes two strings and returns a smart diff that can be used to describe the
|
|
2250
|
-
* change in a way that can be used as operations like inserting, removing or
|
|
2251
|
-
* replacing text.
|
|
2252
|
-
*
|
|
2253
|
-
* @param prev the previous text
|
|
2254
|
-
* @param next the next text
|
|
2255
|
-
* @returns the text difference
|
|
2256
|
-
*/
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
function diffText(prev, next) {
|
|
2260
|
-
if (prev === undefined || next === undefined) return null;
|
|
2261
|
-
var offsets = getDiffOffsets(prev, next);
|
|
2262
|
-
if (offsets == null) return null;
|
|
2263
|
-
var insertText = sliceText(next, offsets);
|
|
2264
|
-
var removeText = sliceText(prev, offsets);
|
|
2265
|
-
return {
|
|
2266
|
-
start: offsets.start,
|
|
2267
|
-
end: prev.length - offsets.end,
|
|
2268
|
-
insertText,
|
|
2269
|
-
removeText
|
|
2270
|
-
};
|
|
2271
|
-
}
|
|
2272
|
-
function combineInsertedText(insertedText) {
|
|
2273
|
-
return insertedText.reduce((acc, _ref) => {
|
|
2274
|
-
var {
|
|
2275
|
-
text
|
|
2276
|
-
} = _ref;
|
|
2277
|
-
return "".concat(acc).concat(text.insertText);
|
|
2278
|
-
}, '');
|
|
2279
|
-
}
|
|
2280
|
-
function getTextInsertion(editor, domNode) {
|
|
2281
|
-
var node = ReactEditor.toSlateNode(editor, domNode);
|
|
2282
|
-
|
|
2283
|
-
if (!Text$1.isText(node)) {
|
|
2284
|
-
return undefined;
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
var prevText = node.text;
|
|
2288
|
-
var nextText = domNode.textContent; // textContent will pad an extra \n when the textContent ends with an \n
|
|
2289
|
-
|
|
2290
|
-
if (nextText.endsWith('\n')) {
|
|
2291
|
-
nextText = nextText.slice(0, nextText.length - 1);
|
|
2292
|
-
} // If the text is no different, there is no diff.
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
if (nextText !== prevText) {
|
|
2296
|
-
var textDiff = diffText(prevText, nextText);
|
|
2297
|
-
|
|
2298
|
-
if (textDiff !== null) {
|
|
2299
|
-
var textPath = ReactEditor.findPath(editor, node);
|
|
2300
|
-
return {
|
|
2301
|
-
text: textDiff,
|
|
2302
|
-
path: textPath
|
|
2303
|
-
};
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2307
|
-
return undefined;
|
|
2308
|
-
}
|
|
2309
|
-
function normalizeTextInsertionRange(editor, range, _ref2) {
|
|
2310
|
-
var {
|
|
2311
|
-
path,
|
|
2312
|
-
text
|
|
2313
|
-
} = _ref2;
|
|
2314
|
-
var insertionRange = {
|
|
2315
|
-
anchor: {
|
|
2316
|
-
path,
|
|
2317
|
-
offset: text.start
|
|
2318
|
-
},
|
|
2319
|
-
focus: {
|
|
2320
|
-
path,
|
|
2321
|
-
offset: text.end
|
|
2322
|
-
}
|
|
2323
|
-
};
|
|
2324
|
-
|
|
2325
|
-
if (!range || !Range.isCollapsed(range)) {
|
|
2326
|
-
return insertionRange;
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
var {
|
|
2330
|
-
insertText,
|
|
2331
|
-
removeText
|
|
2332
|
-
} = text;
|
|
2333
|
-
var isSingleCharacterInsertion = insertText.length === 1 || removeText.length === 1;
|
|
2334
|
-
/**
|
|
2335
|
-
* This code handles edge cases that arise from text diffing when the
|
|
2336
|
-
* inserted or removed character is a single character, and the character
|
|
2337
|
-
* right before or after the anchor is the same as the one being inserted or
|
|
2338
|
-
* removed.
|
|
2339
|
-
*
|
|
2340
|
-
* Take this example: hello|o
|
|
2341
|
-
*
|
|
2342
|
-
* If another `o` is inserted at the selection's anchor in the example above,
|
|
2343
|
-
* it should be inserted at the anchor, but using text diffing, we actually
|
|
2344
|
-
* detect that the character was inserted after the second `o`:
|
|
2345
|
-
*
|
|
2346
|
-
* helloo[o]|
|
|
2347
|
-
*
|
|
2348
|
-
* Instead, in these very specific edge cases, we assume that the character
|
|
2349
|
-
* needs to be inserted after the anchor rather than where the diff was found:
|
|
2350
|
-
*
|
|
2351
|
-
* hello[o]|o
|
|
2352
|
-
*/
|
|
2353
|
-
|
|
2354
|
-
if (isSingleCharacterInsertion && Path.equals(range.anchor.path, path)) {
|
|
2355
|
-
var [_text] = Array.from(Editor.nodes(editor, {
|
|
2356
|
-
at: range,
|
|
2357
|
-
match: Text$1.isText
|
|
2358
|
-
}));
|
|
2359
|
-
|
|
2360
|
-
if (_text) {
|
|
2361
|
-
var [node] = _text;
|
|
2362
|
-
var {
|
|
2363
|
-
anchor
|
|
2364
|
-
} = range;
|
|
2365
|
-
var characterBeforeAnchor = node.text[anchor.offset - 1];
|
|
2366
|
-
var characterAfterAnchor = node.text[anchor.offset];
|
|
2367
|
-
|
|
2368
|
-
if (insertText.length === 1 && insertText === characterAfterAnchor) {
|
|
2369
|
-
// Assume text should be inserted at the anchor
|
|
2370
|
-
return range;
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
if (removeText.length === 1 && removeText === characterBeforeAnchor) {
|
|
2374
|
-
// Assume text should be removed right before the anchor
|
|
2375
|
-
return {
|
|
2376
|
-
anchor: {
|
|
2377
|
-
path,
|
|
2378
|
-
offset: anchor.offset - 1
|
|
2379
|
-
},
|
|
2380
|
-
focus: {
|
|
2381
|
-
path,
|
|
2382
|
-
offset: anchor.offset
|
|
2383
|
-
}
|
|
2384
|
-
};
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
return insertionRange;
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
2158
|
/**
|
|
2393
2159
|
* An auto-incrementing identifier for keys.
|
|
2394
2160
|
*/
|
|
@@ -2958,6 +2724,233 @@ var ReactEditor = {
|
|
|
2958
2724
|
|
|
2959
2725
|
};
|
|
2960
2726
|
|
|
2727
|
+
/**
|
|
2728
|
+
* Returns the number of characters that are the same at the beginning of the
|
|
2729
|
+
* String.
|
|
2730
|
+
*
|
|
2731
|
+
* @param prev the previous text
|
|
2732
|
+
* @param next the next text
|
|
2733
|
+
* @returns the offset of the start of the difference; null if there is no difference
|
|
2734
|
+
*/
|
|
2735
|
+
|
|
2736
|
+
function getDiffStart(prev, next) {
|
|
2737
|
+
var length = Math.min(prev.length, next.length);
|
|
2738
|
+
|
|
2739
|
+
for (var i = 0; i < length; i++) {
|
|
2740
|
+
if (prev.charAt(i) !== next.charAt(i)) return i;
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2743
|
+
if (prev.length !== next.length) return length;
|
|
2744
|
+
return null;
|
|
2745
|
+
}
|
|
2746
|
+
/**
|
|
2747
|
+
* Returns the number of characters that are the same at the end of the String
|
|
2748
|
+
* up to `max`. Max prevents double-counting characters when there are
|
|
2749
|
+
* multiple duplicate characters around the diff area.
|
|
2750
|
+
*
|
|
2751
|
+
* @param prev the previous text
|
|
2752
|
+
* @param next the next text
|
|
2753
|
+
* @param max the max length to test.
|
|
2754
|
+
* @returns number of characters that are the same at the end of the string
|
|
2755
|
+
*/
|
|
2756
|
+
|
|
2757
|
+
|
|
2758
|
+
function getDiffEnd(prev, next, max) {
|
|
2759
|
+
var prevLength = prev.length;
|
|
2760
|
+
var nextLength = next.length;
|
|
2761
|
+
var length = Math.min(prevLength, nextLength, max);
|
|
2762
|
+
|
|
2763
|
+
for (var i = 0; i < length; i++) {
|
|
2764
|
+
var prevChar = prev.charAt(prevLength - i - 1);
|
|
2765
|
+
var nextChar = next.charAt(nextLength - i - 1);
|
|
2766
|
+
if (prevChar !== nextChar) return i;
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
if (prev.length !== next.length) return length;
|
|
2770
|
+
return null;
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Takes two strings and returns an object representing two offsets. The
|
|
2774
|
+
* first, `start` represents the number of characters that are the same at
|
|
2775
|
+
* the front of the String. The `end` represents the number of characters
|
|
2776
|
+
* that are the same at the end of the String.
|
|
2777
|
+
*
|
|
2778
|
+
* Returns null if they are identical.
|
|
2779
|
+
*
|
|
2780
|
+
* @param prev the previous text
|
|
2781
|
+
* @param next the next text
|
|
2782
|
+
* @returns the difference text range; null if there are no differences.
|
|
2783
|
+
*/
|
|
2784
|
+
|
|
2785
|
+
|
|
2786
|
+
function getDiffOffsets(prev, next) {
|
|
2787
|
+
if (prev === next) return null;
|
|
2788
|
+
var start = getDiffStart(prev, next);
|
|
2789
|
+
if (start === null) return null;
|
|
2790
|
+
var maxEnd = Math.min(prev.length - start, next.length - start);
|
|
2791
|
+
var end = getDiffEnd(prev, next, maxEnd);
|
|
2792
|
+
if (end === null) return null;
|
|
2793
|
+
return {
|
|
2794
|
+
start,
|
|
2795
|
+
end
|
|
2796
|
+
};
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Takes a text string and returns a slice from the string at the given text range
|
|
2800
|
+
*
|
|
2801
|
+
* @param text the text
|
|
2802
|
+
* @param offsets the text range
|
|
2803
|
+
* @returns the text slice at text range
|
|
2804
|
+
*/
|
|
2805
|
+
|
|
2806
|
+
|
|
2807
|
+
function sliceText(text, offsets) {
|
|
2808
|
+
return text.slice(offsets.start, text.length - offsets.end);
|
|
2809
|
+
}
|
|
2810
|
+
/**
|
|
2811
|
+
* Takes two strings and returns a smart diff that can be used to describe the
|
|
2812
|
+
* change in a way that can be used as operations like inserting, removing or
|
|
2813
|
+
* replacing text.
|
|
2814
|
+
*
|
|
2815
|
+
* @param prev the previous text
|
|
2816
|
+
* @param next the next text
|
|
2817
|
+
* @returns the text difference
|
|
2818
|
+
*/
|
|
2819
|
+
|
|
2820
|
+
|
|
2821
|
+
function diffText(prev, next) {
|
|
2822
|
+
if (prev === undefined || next === undefined) return null;
|
|
2823
|
+
var offsets = getDiffOffsets(prev, next);
|
|
2824
|
+
if (offsets == null) return null;
|
|
2825
|
+
var insertText = sliceText(next, offsets);
|
|
2826
|
+
var removeText = sliceText(prev, offsets);
|
|
2827
|
+
return {
|
|
2828
|
+
start: offsets.start,
|
|
2829
|
+
end: prev.length - offsets.end,
|
|
2830
|
+
insertText,
|
|
2831
|
+
removeText
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
function combineInsertedText(insertedText) {
|
|
2835
|
+
return insertedText.reduce((acc, _ref) => {
|
|
2836
|
+
var {
|
|
2837
|
+
text
|
|
2838
|
+
} = _ref;
|
|
2839
|
+
return "".concat(acc).concat(text.insertText);
|
|
2840
|
+
}, '');
|
|
2841
|
+
}
|
|
2842
|
+
function getTextInsertion(editor, domNode) {
|
|
2843
|
+
var node = ReactEditor.toSlateNode(editor, domNode);
|
|
2844
|
+
|
|
2845
|
+
if (!Text$1.isText(node)) {
|
|
2846
|
+
return undefined;
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
var prevText = node.text;
|
|
2850
|
+
var nextText = domNode.textContent; // textContent will pad an extra \n when the textContent ends with an \n
|
|
2851
|
+
|
|
2852
|
+
if (nextText.endsWith('\n')) {
|
|
2853
|
+
nextText = nextText.slice(0, nextText.length - 1);
|
|
2854
|
+
} // If the text is no different, there is no diff.
|
|
2855
|
+
|
|
2856
|
+
|
|
2857
|
+
if (nextText !== prevText) {
|
|
2858
|
+
var textDiff = diffText(prevText, nextText);
|
|
2859
|
+
|
|
2860
|
+
if (textDiff !== null) {
|
|
2861
|
+
var textPath = ReactEditor.findPath(editor, node);
|
|
2862
|
+
return {
|
|
2863
|
+
text: textDiff,
|
|
2864
|
+
path: textPath
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
return undefined;
|
|
2870
|
+
}
|
|
2871
|
+
function normalizeTextInsertionRange(editor, range, _ref2) {
|
|
2872
|
+
var {
|
|
2873
|
+
path,
|
|
2874
|
+
text
|
|
2875
|
+
} = _ref2;
|
|
2876
|
+
var insertionRange = {
|
|
2877
|
+
anchor: {
|
|
2878
|
+
path,
|
|
2879
|
+
offset: text.start
|
|
2880
|
+
},
|
|
2881
|
+
focus: {
|
|
2882
|
+
path,
|
|
2883
|
+
offset: text.end
|
|
2884
|
+
}
|
|
2885
|
+
};
|
|
2886
|
+
|
|
2887
|
+
if (!range || !Range.isCollapsed(range)) {
|
|
2888
|
+
return insertionRange;
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
var {
|
|
2892
|
+
insertText,
|
|
2893
|
+
removeText
|
|
2894
|
+
} = text;
|
|
2895
|
+
var isSingleCharacterInsertion = insertText.length === 1 || removeText.length === 1;
|
|
2896
|
+
/**
|
|
2897
|
+
* This code handles edge cases that arise from text diffing when the
|
|
2898
|
+
* inserted or removed character is a single character, and the character
|
|
2899
|
+
* right before or after the anchor is the same as the one being inserted or
|
|
2900
|
+
* removed.
|
|
2901
|
+
*
|
|
2902
|
+
* Take this example: hello|o
|
|
2903
|
+
*
|
|
2904
|
+
* If another `o` is inserted at the selection's anchor in the example above,
|
|
2905
|
+
* it should be inserted at the anchor, but using text diffing, we actually
|
|
2906
|
+
* detect that the character was inserted after the second `o`:
|
|
2907
|
+
*
|
|
2908
|
+
* helloo[o]|
|
|
2909
|
+
*
|
|
2910
|
+
* Instead, in these very specific edge cases, we assume that the character
|
|
2911
|
+
* needs to be inserted after the anchor rather than where the diff was found:
|
|
2912
|
+
*
|
|
2913
|
+
* hello[o]|o
|
|
2914
|
+
*/
|
|
2915
|
+
|
|
2916
|
+
if (isSingleCharacterInsertion && Path.equals(range.anchor.path, path)) {
|
|
2917
|
+
var [_text] = Array.from(Editor.nodes(editor, {
|
|
2918
|
+
at: range,
|
|
2919
|
+
match: Text$1.isText
|
|
2920
|
+
}));
|
|
2921
|
+
|
|
2922
|
+
if (_text) {
|
|
2923
|
+
var [node] = _text;
|
|
2924
|
+
var {
|
|
2925
|
+
anchor
|
|
2926
|
+
} = range;
|
|
2927
|
+
var characterBeforeAnchor = node.text[anchor.offset - 1];
|
|
2928
|
+
var characterAfterAnchor = node.text[anchor.offset];
|
|
2929
|
+
|
|
2930
|
+
if (insertText.length === 1 && insertText === characterAfterAnchor) {
|
|
2931
|
+
// Assume text should be inserted at the anchor
|
|
2932
|
+
return range;
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
if (removeText.length === 1 && removeText === characterBeforeAnchor) {
|
|
2936
|
+
// Assume text should be removed right before the anchor
|
|
2937
|
+
return {
|
|
2938
|
+
anchor: {
|
|
2939
|
+
path,
|
|
2940
|
+
offset: anchor.offset - 1
|
|
2941
|
+
},
|
|
2942
|
+
focus: {
|
|
2943
|
+
path,
|
|
2944
|
+
offset: anchor.offset
|
|
2945
|
+
}
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
return insertionRange;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2961
2954
|
function gatherMutationData(editor, mutations) {
|
|
2962
2955
|
var addedNodes = [];
|
|
2963
2956
|
var removedNodes = [];
|
|
@@ -3179,15 +3172,7 @@ class AndroidInputManager {
|
|
|
3179
3172
|
var {
|
|
3180
3173
|
selection,
|
|
3181
3174
|
marks
|
|
3182
|
-
} = this.editor; //
|
|
3183
|
-
// Text will be inserted on compositionend event.
|
|
3184
|
-
|
|
3185
|
-
if (IS_COMPOSING.get(this.editor) || IS_ON_COMPOSITION_END.get(this.editor)) {
|
|
3186
|
-
EDITOR_ON_COMPOSITION_TEXT.set(this.editor, insertedText);
|
|
3187
|
-
IS_ON_COMPOSITION_END.set(this.editor, false);
|
|
3188
|
-
return;
|
|
3189
|
-
} // Insert the batched text diffs
|
|
3190
|
-
|
|
3175
|
+
} = this.editor; // Insert the batched text diffs
|
|
3191
3176
|
|
|
3192
3177
|
insertedText.forEach(insertion => {
|
|
3193
3178
|
var text = insertion.text.insertText;
|
|
@@ -3205,6 +3190,7 @@ class AndroidInputManager {
|
|
|
3205
3190
|
});
|
|
3206
3191
|
this.editor.marks = null;
|
|
3207
3192
|
} else {
|
|
3193
|
+
Transforms.setSelection(this.editor, at);
|
|
3208
3194
|
Editor.insertText(this.editor, text);
|
|
3209
3195
|
}
|
|
3210
3196
|
});
|
|
@@ -3813,39 +3799,6 @@ var AndroidEditable = props => {
|
|
|
3813
3799
|
setTimeout(() => {
|
|
3814
3800
|
state.isComposing && setIsComposing(false);
|
|
3815
3801
|
state.isComposing = false;
|
|
3816
|
-
IS_COMPOSING.set(editor, false);
|
|
3817
|
-
IS_ON_COMPOSITION_END.set(editor, true);
|
|
3818
|
-
var insertedText = EDITOR_ON_COMPOSITION_TEXT.get(editor) || []; // `insertedText` is set in `MutationObserver` constructor.
|
|
3819
|
-
// If open phone keyboard association function, `CompositionEvent` will be triggered.
|
|
3820
|
-
|
|
3821
|
-
if (!insertedText.length) {
|
|
3822
|
-
return;
|
|
3823
|
-
}
|
|
3824
|
-
|
|
3825
|
-
EDITOR_ON_COMPOSITION_TEXT.set(editor, []);
|
|
3826
|
-
var {
|
|
3827
|
-
selection,
|
|
3828
|
-
marks
|
|
3829
|
-
} = editor;
|
|
3830
|
-
insertedText.forEach(insertion => {
|
|
3831
|
-
var text = insertion.text.insertText;
|
|
3832
|
-
var at = normalizeTextInsertionRange(editor, selection, insertion);
|
|
3833
|
-
|
|
3834
|
-
if (marks) {
|
|
3835
|
-
var node = _objectSpread({
|
|
3836
|
-
text
|
|
3837
|
-
}, marks);
|
|
3838
|
-
|
|
3839
|
-
Transforms.insertNodes(editor, node, {
|
|
3840
|
-
match: Text$1.isText,
|
|
3841
|
-
at,
|
|
3842
|
-
select: true
|
|
3843
|
-
});
|
|
3844
|
-
editor.marks = null;
|
|
3845
|
-
} else {
|
|
3846
|
-
Editor.insertText(editor, text);
|
|
3847
|
-
}
|
|
3848
|
-
});
|
|
3849
3802
|
}, RESOLVE_DELAY);
|
|
3850
3803
|
}
|
|
3851
3804
|
}, [attributes.onCompositionEnd]),
|
|
@@ -3853,14 +3806,12 @@ var AndroidEditable = props => {
|
|
|
3853
3806
|
if (hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionUpdate)) {
|
|
3854
3807
|
!state.isComposing && setIsComposing(true);
|
|
3855
3808
|
state.isComposing = true;
|
|
3856
|
-
IS_COMPOSING.set(editor, true);
|
|
3857
3809
|
}
|
|
3858
3810
|
}, [attributes.onCompositionUpdate]),
|
|
3859
3811
|
onCompositionStart: useCallback(event => {
|
|
3860
3812
|
if (hasEditableTarget(editor, event.target) && !isEventHandled(event, attributes.onCompositionStart)) {
|
|
3861
3813
|
!state.isComposing && setIsComposing(true);
|
|
3862
3814
|
state.isComposing = true;
|
|
3863
|
-
IS_COMPOSING.set(editor, true);
|
|
3864
3815
|
}
|
|
3865
3816
|
}, [attributes.onCompositionStart]),
|
|
3866
3817
|
onPaste: useCallback(event => {
|