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

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

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

Post 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.
Last edited by seany on Wednesday 19th October 2022 7:17pm, edited 1 time in total.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

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

Post 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
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

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

Post 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.
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

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

Post 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
If at first you don't succeed , try doing something differently.
BruceS
seany
Posts: 32
Joined: Friday 6th December 2019 3:09pm

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

Post 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.
Post Reply