Page 1 of 1

[Solved for now] Getting the exact amount of text shown in a richtext editor

Posted: Tuesday 12th July 2022 1:01pm
by seany
Hi

I have previously posted about colors and backgrounds of richtext editor content. My goal is to create an IDE for a language I am working on. The IDE will have syntax highlighting in the text edit in the left hand pane, and a autogenerated program flowchart in the right hand side.

Now, I was lookign for efficient syntax highlight algorithms. I found this and this.

I would like to apply syntax highlighting only on the visible part of the text tho. I would like to find out if i can find out the exact amount of the text displayed in a richtextedit. See Image

Image.

I only want to extract the text that starts at eirmod at the beginning of the visible text block, and ends at Lorem at the end (depending on the scroll bar position). Please note, that there are strokes of a p and a g of the previous line only barely visible at the very top, but I dont want the text of that line.

How can I extract only the visible text block? Thank you.

Re: Getting the exact amount of text shown in a richtext editor

Posted: Tuesday 12th July 2022 3:25pm
by cogier
I can't work out why you want to 'Highlight' all that text.

If you are looking for an IDE editor, why not use the same one that Gambas uses: -

Image

Re: Getting the exact amount of text shown in a richtext editor

Posted: Tuesday 12th July 2022 8:12pm
by seany
Because I want to use my own syntax highlighting rules and precedence.

I could not find out how to do all that in the textEdit. So i am going with richtextedit.

Re: Getting the exact amount of text shown in a richtext editor

Posted: Wednesday 13th July 2022 11:39am
by BruceSteers
That's going to be complicated.
You will need the ScrollY position, you will have to calculate from Font.Height, ScrollY position and TextEdit.Height
You will also need to deal with the text wrapping.

You may find it easier to use gb.form.editor

Check out this application...
https://gitlab.com/bsteers4/scripted/-/tree/old-gambas
That is an editor i made for making bash/gambas scripts using the gambas editor.

At the time I made it gambas did not support sh highlighting.
So I imported the gambas gb.form.editor and gb.eval.highlight components into the program. I then made a copy of the c++ highlighter and called it sh and edited it to work on sh files.

In the .src folder are 2 folders gb.form.editor and gb.eval.highlight. These are the imported/edited files with the TextHighlighter_Sh.class.
The work I did there was good enough to get included with gambas and sh highlighting is now available to all.

If you can see what the file https://gitlab.com/bsteers4/scripted/-/ ... r_Sh.class is doing then you may be able to copy it as i did and modify to your needs.

BruceS

Re: Getting the exact amount of text shown in a richtext editor

Posted: Thursday 14th July 2022 4:18pm
by seany
Ok, thank you.

I am trying to figure out how the actual highlighting is working in the control, that is whether it is a greedy algorithm.