[Cuis-dev] InnerTextMorph & RunNotArray, Was: StyledTextEditor PR & InnerTextMorph

Juan Vuletich juan at cuis.st
Tue Sep 19 05:52:44 PDT 2023


Hi Bernhard,

(inline)
On 9/18/2023 2:07 PM, Bernhard Pieber via Cuis-dev wrote:
> Hi Juan,
>
> I introduced InnerTextMorph>>editor: to fix StyledTextEditorTest>>#testStylesInPaste1 and similar tests, also in StyledTextTest (see senders of editor:).
>
> First I tried to make the test setup more similar to what happens when a StyledTextEditor is opened. Here is what I came up with at first:
>
> testStylesInPaste1
> 	"
> 	StyledTextEditorTest new testStylesInPaste1
> 	"
> 	| heading1 heading1Text simpleText editor composition concatenation initialText model innerMorph |
> 	model :=
​ StyledTextModel new.
> 	heading1 :=
​ model styleSet paragraphStyleNamed: 'Heading 1'.
> 	heading1Text :=
​ Text string: 'This is the heading', String newLineString attribute: (ParagraphStyleReference for: heading1).	"Include a newLine, so our paragraphStyle is applied to resulting paragraph"
> 	simpleText :=
​ 'This is a text without style' asText.
>
> 	initialText :=
​ simpleText copy.
> 	model contents: initialText.
> 	innerMorph 
​:= (PluggableStyledTextMorph withModel: model) innerTextMorph.
> 	editor 
​:= innerMorph editor.
>
> 	editor deselectAndPlaceCursorAt: initialText size+1.
> 	Clipboard storeObject: heading1Text. editor paste.		"Extends heading 1 to beginning, runs must be compacted"
> 	concatenation 
​:= editor text.
> 	self assert: concatenation runs runs size = 1 description: 'Should apply the "Heading 1" paragraph style to the whole text'.
> 	self assert: concatenation runs first size = 1 description: 'Should apply just the "Heading 1" paragraph style to the whole text'.
> 	self assert: concatenation runs first first style == heading1 description: 'Should apply the "Heading 1" paragraph style to the whole text'
>
> This is nicer also because the test setup would become much simpler.

Yes, that's much better.

> However, then I ran into a MNU: RunNotArray>>runs in the first assertion. So RunNotArray is not polymorphic to RunArray for this use case. I could not figure out how to fix the assertions without changing their semantics for RunNotArray, and I was not sure if the use of RunNotArray was even intentional. So I chose the easy way to fix these by setting the editor manually.
>
> How should the assertions be rewritten for a RunNotArray?

Just use Text protocol:

     self assert: (concatenation runLengthFor: 1) = concatenation size 
description: 'Should apply the "Heading 1" paragraph style to the whole 
text'.
     self assert: (concatenation attributesAt: 1) size = 1 description: 
'Should apply just the "Heading 1" paragraph style to the whole text'.
     self assert: (concatenation attributesAt: 1) first style == 
heading1 description: 'Should apply the "Heading 1" paragraph style to 
the whole text'.

If you can remove all senders to #editor: and #textComposition:, I think 
the tests will be cleaner and more robust against system changes.

> Cheers,
> Bernhard
>

Thanks,

-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich



More information about the Cuis-dev mailing list