Opened 5 years ago

Closed 5 years ago

#11132 closed bug (duplicate)

BTextView::GetText is broken

Reported by: waddlesplash Owned by: axeld
Priority: normal Milestone: R1
Component: Kits/Interface Kit Version: R1/Development
Keywords: Cc:
Blocked By: #8447 Blocking:
Has a Patch: no Platform: All


Calling Text(); works as expected -- you get a char* with all the text in the view. But calling GetText(buffer, BTextView::TextLength()); produces the same output only if the text was not modified since SetText was called. If it was modified, buffer will not contain the text the view shows, but rather the text as if the user had written it while in overwrite mode meaning the GetText() buffer will be filled only up to the size of whatever was passed to SetText as well as being erroneous.

A few OpenGrok searches show that nothing internal uses this, but it appears that at least some apps on HaikuArchives does...

Change History (5)

comment:1 Changed 5 years ago by waddlesplash

Tried some more and found some internal stuff using it:

comment:2 Changed 5 years ago by waddlesplash

OK, first dissection:

BTextView::GetText calls the second prototype of TextGapBuffer::GetString1 which does some simple math to figure out where to memcpy to/from. Meanwhile, the first prototype of TextGapBuffer::GetString also takes fGapCount and fGapIndex into account, and while I wasn't dealing with styled text here I don't think that's the case, the logic differences between the two don't feel right.

1: Why do we have two prototypes of TextGapBuffer::GetString? Due to the differences listed here I think some effort should be made to combine the two.

Last edited 5 years ago by waddlesplash (previous) (diff)

comment:3 Changed 5 years ago by waddlesplash

Some insight from Jessicah:

<jessicah> mm, RealText() seems to reset the gap buffer, whereas GetString()
           avoids resetting the gap buffer
<jessicah> looks like the other GetString is some internal magic utility function
           used by other interface kit internals

comment:4 Changed 5 years ago by waddlesplash

Oh, and BTextView::Text() works because it bypasses that logic and uses TextGapBuffer::RealText() which doesn't deal with ranges and concatenates the whole buffer.

Last edited 5 years ago by waddlesplash (previous) (diff)

comment:5 Changed 5 years ago by waddlesplash

Blocked By: 8447 added
Resolution: duplicate
Status: newclosed

Duplicate of #8447.

Note: See TracTickets for help on using tickets.