|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
| 1 | +using System.Collections.Generic; |
3 | 2 | using Unity.UIWidgets.foundation;
|
4 | 3 | using Unity.UIWidgets.gestures;
|
5 | 4 | using Unity.UIWidgets.painting;
|
@@ -327,16 +326,34 @@ int _handleControl(bool rightArrow, bool leftArrow, bool ctrl, int newOffset) {
|
327 | 326 |
|
328 | 327 | int _handleHorizontalArrows(bool rightArrow, bool leftArrow, bool shift, int newOffset) {
|
329 | 328 | if (rightArrow && this._extentOffset < this.text.text.Length) {
|
330 |
| - newOffset += 1; |
331 |
| - if (shift) { |
332 |
| - this._previousCursorLocation += 1; |
| 329 | + if (newOffset < this.text.text.Length - 1 && char.IsHighSurrogate(this.text.text[newOffset])) { |
| 330 | + // handle emoji, which takes 2 bytes |
| 331 | + newOffset += 2; |
| 332 | + if (shift) { |
| 333 | + this._previousCursorLocation += 2; |
| 334 | + } |
| 335 | + } |
| 336 | + else { |
| 337 | + newOffset += 1; |
| 338 | + if (shift) { |
| 339 | + this._previousCursorLocation += 1; |
| 340 | + } |
333 | 341 | }
|
334 | 342 | }
|
335 | 343 |
|
336 | 344 | if (leftArrow && this._extentOffset > 0) {
|
337 |
| - newOffset -= 1; |
338 |
| - if (shift) { |
339 |
| - this._previousCursorLocation -= 1; |
| 345 | + if (newOffset > 1 && char.IsLowSurrogate(this.text.text[newOffset - 1])) { |
| 346 | + // handle emoji, which takes 2 bytes |
| 347 | + newOffset -= 2; |
| 348 | + if (shift) { |
| 349 | + this._previousCursorLocation -= 2; |
| 350 | + } |
| 351 | + } |
| 352 | + else { |
| 353 | + newOffset -= 1; |
| 354 | + if (shift) { |
| 355 | + this._previousCursorLocation -= 1; |
| 356 | + } |
340 | 357 | }
|
341 | 358 | }
|
342 | 359 |
|
@@ -483,11 +500,20 @@ void _handleShortcuts(KeyCommand cmd) {
|
483 | 500 | void _handleDelete() {
|
484 | 501 | var selection = this.selection;
|
485 | 502 | if (selection.textAfter(this.text.text).isNotEmpty()) {
|
486 |
| - this.textSelectionDelegate.textEditingValue = new TextEditingValue( |
487 |
| - text: selection.textBefore(this.text.text) |
488 |
| - + selection.textAfter(this.text.text).Substring(1), |
489 |
| - selection: TextSelection.collapsed(offset: selection.start) |
490 |
| - ); |
| 503 | + if (char.IsHighSurrogate(this.text.text[selection.end])) { |
| 504 | + this.textSelectionDelegate.textEditingValue = new TextEditingValue( |
| 505 | + text: selection.textBefore(this.text.text) |
| 506 | + + selection.textAfter(this.text.text).Substring(2), |
| 507 | + selection: TextSelection.collapsed(offset: selection.start) |
| 508 | + ); |
| 509 | + } |
| 510 | + else { |
| 511 | + this.textSelectionDelegate.textEditingValue = new TextEditingValue( |
| 512 | + text: selection.textBefore(this.text.text) |
| 513 | + + selection.textAfter(this.text.text).Substring(1), |
| 514 | + selection: TextSelection.collapsed(offset: selection.start) |
| 515 | + ); |
| 516 | + } |
491 | 517 | }
|
492 | 518 | else {
|
493 | 519 | this.textSelectionDelegate.textEditingValue = new TextEditingValue(
|
@@ -877,7 +903,7 @@ public TextPosition getParagraphForward(TextPosition position, TextAffinity? aff
|
877 | 903 |
|
878 | 904 | public TextPosition getParagraphBackward(TextPosition position, TextAffinity? affinity = null) {
|
879 | 905 | var lineCount = this._textPainter.getLineCount();
|
880 |
| - |
| 906 | + |
881 | 907 | Paragraph.LineRange line = null;
|
882 | 908 | for (int i = lineCount - 1; i >= 0; --i) {
|
883 | 909 | line = this._textPainter.getLineRange(i);
|
@@ -1160,7 +1186,8 @@ void _paintCaret(Canvas canvas, Offset effectiveOffset, TextPosition textPositio
|
1160 | 1186 | }
|
1161 | 1187 | }
|
1162 | 1188 |
|
1163 |
| - public void setFloatingCursor(FloatingCursorDragState? state, Offset boundedOffset, TextPosition lastTextPosition, |
| 1189 | + public void setFloatingCursor(FloatingCursorDragState? state, Offset boundedOffset, |
| 1190 | + TextPosition lastTextPosition, |
1164 | 1191 | float? resetLerpValue = null) {
|
1165 | 1192 | D.assert(boundedOffset != null);
|
1166 | 1193 | D.assert(lastTextPosition != null);
|
|
0 commit comments