Text search in Webview Control

For questions about Gambas web tools.
Post Reply
User avatar
Quincunxian
Posts: 132
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Text search in Webview Control

Post by Quincunxian » Monday 17th May 2021 4:48am

I have a webview that I load with text that I wish to search.
There are two issues.

Search Text List
Apple
Banana
Pineapple

If the web view text is:
Apple
Pineapple
Pineapple
Apple
Banana

In this example, the the word Pineapple is never found.
The issue is that the search seems to go through the webview from start to end but you cannot tell it go back to the start to search again.
So once it finds the second instance of the word 'Apple', it does not go back and search at the beginning for for any other words.
In the WebView.FindText(SearchWord,Backward,CaseSensitive,Wrap), If you set the parameter 'warp' to true, it goes into an unending loop.

The second, issue is that there is no way to search for a 'whole word'.
If 'vacant' is part of the searched text and you search for 'can' , it counts as one, the instance inside the other word.
You can search for 'can ' with the added space but in a replace function, it will replace the space as well.

I'm using a webview instead of a TextEditor, as I can't get it to highlight multiple instances in different colours which is the requirement.

Any ideas ?
Cheers - Quin.
I code therefore I am

User avatar
stevedee
Posts: 456
Joined: Monday 20th March 2017 6:06pm

Re: Text search in Webview Control

Post by stevedee » Monday 17th May 2021 6:49am

Quincunxian wrote:
Monday 17th May 2021 4:48am
...The issue is that the search seems to go through the webview from start to end but you cannot tell it go back to the start to search again...
My only idea is that you try to reload the page before a search to force it to start at the beginning
...The second, issue is that there is no way to search for a 'whole word'...
Try putting the word in double quotes, so "back" will not find the word background

User avatar
BruceSteers
Posts: 654
Joined: Thursday 23rd July 2020 5:20pm

Re: Text search in Webview Control

Post by BruceSteers » Monday 17th May 2021 8:22am

Quincunxian wrote:
Monday 17th May 2021 4:48am
I have a webview that I load with text that I wish to search.
There are two issues.

Search Text List
Apple
Banana
Pineapple

If the web view text is:
Apple
Pineapple
Pineapple
Apple
Banana

In this example, the the word Pineapple is never found.
The issue is that the search seems to go through the webview from start to end but you cannot tell it go back to the start to search again.
So once it finds the second instance of the word 'Apple', it does not go back and search at the beginning for for any other words.
In the WebView.FindText(SearchWord,Backward,CaseSensitive,Wrap), If you set the parameter 'warp' to true, it goes into an unending loop.

The second, issue is that there is no way to search for a 'whole word'.
If 'vacant' is part of the searched text and you search for 'can' , it counts as one, the instance inside the other word.
You can search for 'can ' with the added space but in a replace function, it will replace the space as well.

I'm using a webview instead of a TextEditor, as I can't get it to highlight multiple instances in different colours which is the requirement.

Any ideas ?
I know not of webview but...
TextEditor will highlight search result. using HighlightString() command
Public Sub HighlightString(Text As String, Optional IgnoreCase As Boolean, Optional WordOnly As Boolean)

color can be set setting TextEditor1.Styles[Highlight.Highlight].Color
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
Quincunxian
Posts: 132
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Text search in Webview Control

Post by Quincunxian » Monday 17th May 2021 10:02pm

Thanks Bruce,
I did try the text editor earlier on but the requirement was to highlight multiple words in different colours.
I'm a (would be) author writing fantasy and I've created a program in Gambas to help me do that.

I wanted to scan a chapter of text, around 5000 words, and be able to hi-light a number of words by their type.
Each type has a colour. There are around 10 types.

The problem I had with the text editor is that I could do one colour but not preserve that and do another.
The Code editor in gambas is obviously capable of doing that but cannot find an example. No surprises there.
I played around with it for a number of days then gave up and got the limited success with the web view.

Thanks SteveDee:
I tried the "word" process but the search identifies it as a word with quotes.
So word is not found, but "word" is found.
I've tried WebView.Refresh and that didn't work and a reload of the page means that I have to save the existing hi-light then do the next word then save...
One process that looks for sets of words, as 2800+ in the database so this may not be workable on a process time basis.

Thanks Guys.
I'll go back and try out the text editor again to see I've missed something.
Cheers - Quin.
I code therefore I am

Post Reply