dotnet / dotnet/wpf

WPF multiline TextBox CaretIndex resets to beginningof line when navigating vertically

Open
#3,757 1 comment 0 reactions 0 assignees View on GitHub
.NET Framework Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity2.visualstudio.com/t/WPF-multiline-TextBox-CaretIndex-resets-/798123)._

---

When navigating vertically using the up and down arrow keys, the cursor position is set to the beginning of the line instead of being immediately above/below the previous position (if possible).

Image:101295-textbox-caret-index.gif

This behavior is consistently reproducible on a TextBox without previous user interaction such as clicking, selecting text, moving the caret with arrow keys.

Conditions:
  1. TextBox.AcceptsReturn is true, TextBox.Text is multiline text
  2. TextBox has not had any user interaction yet
  3. TextBox caret position set programmatically using either TextBox.CaretIndex or TextBox.Select(int, 0)
  4. TextBox focused programmatically

Workaround:

Call internal static method TextEditorSelection._ClearSuggestedX after setting caret index programmatically.

TextEditorSelection._ClearSuggestedX is not called in

  • TextEditorSelection. OnMoveUpByLine
  • TextEditorSelection.OnMoveDownByLine

because the selection is empty when changing the caret index using

  • TextBox. CaretIndex or
  • TextBox.Select(int, 0)

Environment information:

  • Windows 10 Enterprise Build 17763, Intel(R) Core(TM) i9-8950HK
  • Windows 10 Enterprise Build 15063, Intel64 Family 6 Model 94 Stepping 3 GenuineIntel

Project information:

  • Application (.exe)
  • Solution with multiple dependent projects
  • Visual Studio 2017
  • Target Framework .NET 4.6
Code sample with different scenarios, including the workaround:

wpftextboxnavigation.zip

---
### Original Comments

#### Feedback Bot on 10/30/2019, 11:22 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

#### Feedback Bot on 12/5/2019, 05:12 PM:

I have detected that for the last 35 days, this issue didn't have much product team activity and a very small amount of new votes or comments. Based on this, its severity, and affected area, it’s my experience that this issue is very unlikely to be fixed.

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.