Opened 10 years ago

Closed 10 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:
Platform: All

Description

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 by waddlesplash, 10 years ago

Tried some more and found some internal stuff using it: http://grok.bikemonkey.org/source/search?q=&refs=GetText&project=haiku

comment:2 by waddlesplash, 10 years ago

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. Meanwile, 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.

Version 0, edited 10 years ago by waddlesplash (next)

comment:3 by waddlesplash, 10 years ago

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 by waddlesplash, 10 years ago

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 10 years ago by waddlesplash (previous) (diff)

comment:5 by waddlesplash, 10 years ago

Blocked By: 8447 added
Resolution: duplicate
Status: newclosed

Duplicate of #8447.

Note: See TracTickets for help on using tickets.