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

Bernhard Pieber bernhard at pieber.com
Mon Sep 18 10:07:42 PDT 2023


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. 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?

Cheers,
Bernhard



------- Original Message -------
Juan Vuletich <juan at cuis.st> schrieb am Montag, 18. September 2023 um 01:31:


> 
> 
> Hi Bernhard,
> 
> On 9/17/2023 10:57 AM, Bernhard Pieber via Cuis-dev wrote:
> 
> > Hi Juan,
> > 
> > I updated the PR for StyledTextEditor to fix SUnit tests. I fixed 18 errors and am now down to just 1 failure and 7 errors out of 56 tests. :-)
> > 
> > For the tests to work I needed an additional accessor in InnerTextMorph to explicitly set its editor. I could have done it as an extension in StyledTextEditor but thought it fits better in the base image. See attachment.
> > 
> > The method is currently only needed in setup code in StyledTextEditor SUnit tests. I need to set the editor explicitly because InnerTextMorph>>#hasUnacceptedEdits: now calls convertAndStyleIfNeeded which assumes InnerTextMorph has an editor.
> > 
> > Some design questions arose:
> > Should convertAndStyle be used for a StyledTextEditor? As it should be able to contain Smalltalk code I would say it should. What do you think?
> 
> 
> I think so. I guess we'd need to find a way for the code styler to ask
> for the current ParagraphStyle... Mhhh. I see #doesShout. It seems the
> has already been tasken care of right? I haven't worked on this code in
> a very long time. I'm sorry.
> 
> > Should InnerTextMorph always have an editor, or are there use cases where it does not need& should not have one?
> 
> 
> The current design is that it usually has one.
> 
> > Right now InnerTextMorph is responsible for setting up its own editor in InnerTextMorph<<#installEditorAndTextComposition. Is it ok to set it from the outside, e.g. for test setup, or should we try to avoid that?
> 
> 
> Please try to avoid that. Asking #editor to the InnerTextMorph should
> set the editor and the textComposition. Instead of adding #editor: I'd
> prefer also removing #textComposition: . Let's let InnerTextMorph take
> care of its own business.
> 
> Thanks,
> 
> > Cheers,
> > Bernhard


More information about the Cuis-dev mailing list