Page 1 of 1

Texteditor.SetColor

Posted: Wed Apr 29, 2026 2:32 pm
by ilbarbax
How to disable setcolor in a texteditor string?
I casually found that moai.DoMethod(id$, "SetColor", start, end, 0) does it but I'm not sure it is the right way. I'm not sure that all the escape characters are removed and I get a plain text.
Can someone give some light on this matter?

thanks

Re: Texteditor.SetColor

Posted: Thu Apr 30, 2026 10:38 am
by ilbarbax
Sorry I selected the wrong thread lt needed to be under rapagui
May the administrator move this post? Thanks

Re: Texteditor.SetColor

Posted: Thu Apr 30, 2026 8:15 pm
by plouf
you dont need at all coloring?
maybe seting Texteditor.Styled to false which disables it?

Re: Texteditor.SetColor

Posted: Sat May 02, 2026 8:08 pm
by ilbarbax
I think that styled would apply to the whole document of the texteditor, while instead I need to reset the color in just few specific words of the document leaving the rest untouched (with colors)

Re: Texteditor.SetColor

Posted: Sat May 02, 2026 9:37 pm
by airsoftsoftwair
ilbarbax wrote: Sat May 02, 2026 8:08 pm I think that styled would apply to the whole document of the texteditor, while instead I need to reset the color in just few specific words of the document leaving the rest untouched (with colors)
Hmm, if you only need to reset the color in a few specific words why not use Texteditor.SetColor?

Re: Texteditor.SetColor

Posted: Sun May 03, 2026 9:44 am
by ilbarbax
Yes I did that as described in my first message but I'm not sure I found the correct way

Re: Texteditor.SetColor

Posted: Sun May 03, 2026 11:02 pm
by airsoftsoftwair
I think it's the only way. Maybe in the future a method for resetting style information for a part of the text can be added.

Re: Texteditor.SetColor

Posted: Mon May 04, 2026 2:35 pm
by ilbarbax
I approached the problem in a more pragmatic way with the following function

Code: Select all

Function p_te_uncolor(id$,l_n,txt$)
		Local line_pos=moai.DoMethod(id$, "GetPosition", "0", ToString(l_n-1))
		Local line_len=moai.DoMethod(id$, "GetLineLength", ToString(l_n-1))
		Local t$ = moai.DoMethod(id$, "GetText", line_pos, line_pos+line_len)
		Local pz=FindStr(t$,txt$)
		If pz>=0 
			ntxt$=MidStr(t$,pz-10,StrLen(txt$)+20); my text including evenctual color escape chr
			If StartsWith(ntxt$,Chr(27).."P[")
				t$=UnmidStr(t$, pz+StrLen(txt$), 10)
				t$=UnmidStr(t$, pz-10, 10)
				moai.Set(id$,"CursorPos",line_pos)
				moai.DoMethod(id$, "Mark", line_pos, line_pos+line_len)
				DebugPrint(line_pos, line_pos+line_len, moai.DoMethod(id$, "GetSelection"))

				moai.DoMethod(id$, "Cut")
				moai.Set(id$,"CursorPos",line_pos)
				moai.DoMethod(id$, "Insert", t$, "Cursor")
			EndIf
		EndIf
EndFunction 
It works but I have a problem with the Cut command. It seems not work. In fact I get the line repeated with the color and without the color.
The mark command seems working because the debug print shows coherent figures.
Atm I'm stuck with this problem that is another problem respect the first one.

Re: Texteditor.SetColor

Posted: Mon May 04, 2026 3:50 pm
by ilbarbax
found the problem!.
The texteditor was readonly but at this point why only cut is effected by the readonly and not set color?

Re: Texteditor.SetColor

Posted: Sun May 10, 2026 6:38 pm
by airsoftsoftwair
ilbarbax wrote: Mon May 04, 2026 3:50 pm The texteditor was readonly but at this point why only cut is effected by the readonly and not set color?
Read-only only means that the user won't be able to edit the text. Changing the text programmatically is still possible even in read-only mode.