Page 1 of 1

Use TRichViewEdit as a simple code editor?

Posted: Sat Aug 24, 2024 7:38 pm
by hsauro
I am writing a FMX application and I need a simple editor component that can show line numbers in a gutter and the ability to change the font color of individual bits of text. At the moment I use TMemo which is very limited. TMS have such a component but it’s based on an underlying JavaScript component which would make life difficult I think during deployment to the Mac and Windows. Synedit would work but it’s just for VCL. I can’t find anything else for FMX that can do this.

My question is could TRichViewEdit be used for the role described above? Obviously I would not use most of the functionality that the control would offer but I don’t care about that. I just want something that can show line numbers in a gutter and the ability to change font colors for individual bits of text.

Re: Use TRichViewEdit as a simple code editor?

Posted: Mon Aug 26, 2024 11:07 am
by Sergey Tkachenko
Text color can be changed, just like any other text attribute.
Line numbers is not a built-in feature but can be implemented using custom drawing events.
I'll provide an example later today.

Re: Use TRichViewEdit as a simple code editor?

Posted: Tue Aug 27, 2024 6:30 pm
by Sergey Tkachenko
Sorry for the delay, an example will be tomorrow.

Re: Use TRichViewEdit as a simple code editor?

Posted: Wed Aug 28, 2024 11:46 am
by Sergey Tkachenko
This code shows how to draw line numbers in FireMonkey version of TRichView:
viewtopic.php?p=45845#p45845

But if you want to implement not only simple text coloring, but syntax highlighting, it is much more complicated task. In TRichViewEdit, you can change colors only by changing font attributes of the specified text fragment.
There is an implementation of syntax highlighting (TSyntaxRichViewEdit can be found here: https://www.trichview.com/resources/), but it is a very basic example.

Re: Use TRichViewEdit as a simple code editor?

Posted: Thu Aug 29, 2024 1:33 am
by hsauro
Thanks for getting back. Are the line number painted in a gutter or in the text area of the control? Although even if painted in the text area i assume they aren’t considered part of the text in the control?

Re: Use TRichViewEdit as a simple code editor?

Posted: Thu Aug 29, 2024 1:35 am
by hsauro
I think I could handle text highlighting, my syntax is relatively simple. I think I’ll try the trial version to see how it goes. If it works out I’ll purchase a copy.

Re: Use TRichViewEdit as a simple code editor?

Posted: Thu Aug 29, 2024 9:35 am
by Sergey Tkachenko
This example draws line numbers on the left margin. Just make sure that value of LeftMargin property is large enough.
It's only a drawing, so these numbers are not considered as a part of a document.