Browse Source
Use TextLine.GetBackspaceCaretCharacterHit for the backspace delete handling (#16135)
pull/16153/head
Benedikt Stebner
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
13 additions and
0 deletions
-
src/Avalonia.Controls/TextBox.cs
|
|
|
@ -1442,6 +1442,17 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
var backspacePosition = characterHit.FirstCharacterIndex + characterHit.TrailingLength; |
|
|
|
|
|
|
|
var lineIndex = _presenter.TextLayout.GetLineIndexFromCharacterIndex(caretIndex, true); |
|
|
|
|
|
|
|
var backspaceCharacterHit = _presenter.TextLayout.TextLines[lineIndex] |
|
|
|
.GetBackspaceCaretCharacterHit(new CharacterHit(caretIndex)); |
|
|
|
|
|
|
|
if (backspaceCharacterHit.FirstCharacterIndex > backspacePosition && |
|
|
|
backspaceCharacterHit.FirstCharacterIndex < caretIndex) |
|
|
|
{ |
|
|
|
backspacePosition = backspaceCharacterHit.FirstCharacterIndex; |
|
|
|
} |
|
|
|
|
|
|
|
if (caretIndex != backspacePosition) |
|
|
|
{ |
|
|
|
var start = Math.Min(backspacePosition, caretIndex); |
|
|
|
@ -1456,6 +1467,8 @@ namespace Avalonia.Controls |
|
|
|
SetCurrentValue(TextProperty, StringBuilderCache.GetStringAndRelease(sb)); |
|
|
|
|
|
|
|
SetCurrentValue(CaretIndexProperty, start); |
|
|
|
|
|
|
|
_presenter.MoveCaretToTextPosition(start, true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|