BTextView's Caret drawing
|Reported by:||Blub||Owned by:||zooey|
I'm using a BTextView in a small app I write to get to know the BeAPI. I have two suggestions, although the first one could be seen more like a bug-fix instead of an enhancement:
1) Invalidating the caret in GoToLine()
I added keys to move through the text by multiple lines at once and noticed the following (bad) behaviour:
When the caret is visible GoToLine() does not invalidate the old caret BRect, which causes the caret to stay visible: http://rear.endoftheinternet.org/~blub/images/caret.png
The first line there has 3 rendered carets. And since the _DrawCaret() function only does InvertRect() moving to and away from those carets won't remove them, so I manually have to Invalidate(). But Invalidate()ing when ScrollToSelection() didn't actually scroll seems unclean since it then redraws the whole textview. Now the fastest solution would be to have GoToLine() invalidate the old caret position. http://rear.endoftheinternet.org/~blub/patches/haiku_gotoline_hidecaret.diff
Although, when your application uses GoToLine() multiple times to do editing at special positions - most of which can be done without GoToLine() if I'm not mistaken, maybe even all of them - you'd think that it would "undraw" the caret too often, but really _HideCaret does check if the caret is already hidden, since as mentioned above, it only does InvertRect().
2) Showing the caret when moving
I have noticed that when moving the caret it usually disappears, especially Select() calls _HideCaret() but doesn't call _ShowCaret(), which IMHO it should, if start == end (in other words, if you just place the insertion point) http://rear.endoftheinternet.org/~blub/patches/haiku_select_gotoline_showcaret.diff
I also have a .diff for both patches applied, however, please read on:
3) The clash
Above I have started an argument that using GoToLine() repeatedly with the first patch shouldn't cause any trouble since _HideCaret() checks if the caret is already hidden. However, when applying both patches, GoToLine() hides and also shows the caret, which, when shooting the GoToLine() calls outta a machine gun could lead to slow rendering... Personally I don't think GoToLine() is used too often to apply those patches.