[squeak-dev] Re: Text Style Code in TextMorph

marcel.taeumel Marcel.Taeumel at hpi.de
Wed Jul 20 17:18:29 UTC 2016

Patrick R. wrote
> Hi everyone,
> I have just started investigating a bug with the PluggableTextMorphPlus
> where a TextStyle affecting a complete Text remained valid after setting a
> String instead. During debugging I have encountered the following code in
> TextMorph>>#newContents:
> (text notNil and: [ (textSize := text size) > 0] and: [ (text
> runLengthFor: 1) = textSize ])
>     ifTrue: [ | attribs |
> attribs := text attributesAt: 1 forStyle: textStyle.
> Text string: stringOrText copy attributes: attribs.]
>     ifFalse: [ Text fromString: stringOrText copy ]
> What it does is that if the previous style applied to all of the Text,
> then the new Text also gets this style applied. Why is that? That seems
> pretty weird to me to only handle this one special case. Does anyone know
> the rational behind that?
> Thanks and bests
> Patrick

Hi Patrick,

this seems to be an unexpected side-effect of #newContents:. Please remove

Note that the TextStyle is only needed for TextFontChange text attributes.
What it actually does here is that it copies the current text attributes
from the first character and applies it to the new contents. Do not confuse
"text style" with "text attribute". :-)

IMO: If some application wants to set the text programmatically and keep the
current formatting, that application should be responsible for retrieving
the current formatting and applying it to the new contents. We have Text >>
#attributesAt: and Text >> #addAttribute: for that.


View this message in context: http://forum.world.st/Text-Style-Code-in-TextMorph-tp4907261p4907273.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.

More information about the Squeak-dev mailing list