How to Find or Highlight text in version 39.0.0

573 views
Skip to first unread message

dirk_...@gmx.de

unread,
Feb 19, 2015, 1:17:22 PM2/19/15
to cefs...@googlegroups.com

I am trying to implement a search/highlight function in my series of CefSharp
samples and I am having trouble figuring it out. I guess, partly because some
parameters are ignored and partly because I do not know how to use it properly.

I am using a text changed event ...

<TextBox Text="{Binding Find.Text2Find,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"
         
behav:TextChangedBehavior.TextChangedCommand="{Binding Find.FindTextChangedCommand}"
         
MinWidth="200"
         
Grid.Column="2" />

...to fire a method in a viewmodel:
 
https://github.com/Dirkster99/KB/blob/master/00_HelloWorld/KnowledgeBase%20-%20Sample%207%20LocalZipSchemeHandler/KnowledgeBase/ViewModels/FindTextViewModel.cs 
 

private void ExtendFindString(string findText)
{
 
// Don't search the same string twice
 
if (string.Compare(this.Text2Find, findText, this.mMatchCase) == 0)
   
return;



 
this.Text2Find = findText;

 
// stop searching if we have no text to find
 
if (string.IsNullOrEmpty(this.mText2Find) == true)
 
{
   
this.StopSearch();
   
return;
 
}

 
if (this.mBrowser != null)
 
{
   
// Console.WriteLine("Finding Text: '{0}'", Text2Find);
   
this.mBrowser.WebBrowser.StopFinding(false);
   
this.mBrowser.WebBrowser.Find(0, this.mText2Find, false, this.mMatchCase, true);
 
}
}

I find that this code works but it behaves odd. This can be verified when you type the word 'CefBrowser' in the find textbox.
The application starts to highlight the last occurrence of the string and scrolls backward towards the top as I type each letter(?).

Changing the parameters in the Find(...) method does not seem to change the over all behavior.
What I'd like to have is a way of highlighting the first occurrence and keeping the view at its present location if the next typed letters
occur in the currently highlighted word (just as in Google chrome).

And I would also like to use the '<', '>' buttons to scroll through the sequence of occurrences in a document?

How do I do this? Here is a sequence of screenshots that you can get if you verify the workflow stated above:



Alex Maitland

unread,
Feb 20, 2015, 1:19:13 AM2/20/15
to cefs...@googlegroups.com
The `WinForms Example` in the main github repository has a basic find implementation. Take a look at that and see how you go.

https://github.com/cefsharp/CefSharp/blob/master/CefSharp.WinForms.Example/BrowserTabUserControl.cs#L207

dirk_...@gmx.de

unread,
Feb 24, 2015, 12:54:24 PM2/24/15
to cefs...@googlegroups.com
Thanks for the hint. I adopted the WinForms calling conventions into the WPF sample and it works just great.
I guess we have a pretty nice WPF sample now. I might even do a Metro style version soon just because I can :-)

https://github.com/Dirkster99/KB/tree/master/00_HelloWorld/KnowledgeBase%20-%20Sample%207%20LocalZipSchemeHandler

Alex Maitland

unread,
Feb 25, 2015, 7:48:11 PM2/25/15
to cefs...@googlegroups.com
If your interested I'd be happy to see some of these examples implemented in the main `CefSharp` project, possible under their own repository such as `CefSharp.Tutorials`.

Interested?

Code style would need to be changed slightly to bring it inline with the main project, nothing major there though.

dirk_...@gmx.de

unread,
Feb 26, 2015, 5:08:20 AM2/26/15
to cefs...@googlegroups.com
Yeah, I'd be happy to contribute. I could also write some articles on CefSharp at codeplex.

Here is a list of things I've done so far.

The coding style is no issue. Just let me know what I should adjust and how to proceed and we'll get to it :-)

Jørn Hansen

unread,
Feb 27, 2015, 12:22:14 AM2/27/15
to cefs...@googlegroups.com
Adding and alternative - and up to date - version of http://www.codeproject.com/Tips/648678/Embedding-Chrome-in-a-WPF-VB-NET-Application-using would be cool. It should of course use CefSharp 3, be NuGet based so the manual copying can be skipped and mention that there is both x86 and x64 now. Maybe it should point to the FAQ too?

What do you think about that?

dirk_...@gmx.de

unread,
Feb 27, 2015, 1:19:32 PM2/27/15
to cefs...@googlegroups.com
You mean to say we need something like this?
http://www.codeproject.com/Articles/881315/Display-HTML-in-WPF-and-CefSharp-Tutorial-Step-of

Please review and let me know if this is OK - Is it OK to also have the reference to MyGet.org or should this rather be dropped?

dirk_...@gmx.de

unread,
Feb 27, 2015, 1:27:01 PM2/27/15
to cefs...@googlegroups.com
Hi Alex, I saw you already created a repository at: https://github.com/cefsharp/CefSharp.Tutorial

Did you want me to commit samples in this place? What about the coding style you are after?

What do you think about this?
http://www.codeproject.com/Articles/881315/Display-HTML-in-WPF-and-CefSharp-Tutorial-Step-of

Next Step 2 of n could be this:
https://github.com/Dirkster99/KB/tree/master/00_HelloWorld/KnowledgeBase%20-%20Sample%202%20ResourceHandler

yes?

Alex Maitland

unread,
Feb 28, 2015, 6:40:19 AM2/28/15
to cefs...@googlegroups.com
If you create a PR against the tutorial repository I'll comment inline.

ResourceHandler is a common question, so I'm sure many out there would benefit from a tutorial. Thanks!

I think linking to https://github.com/cefsharp/CefSharp#nuget-packages somewhere in the article is probably a good idea.

In one of the articles I think we should mention Cef.Initialize() and some of the options available.

Greatly appreciate the effort your going to! Thanks!

dirk_...@gmx.de

unread,
Mar 2, 2015, 6:21:57 AM3/2/15
to cefs...@googlegroups.com
I added the Nuget link in the Step 1 article.

for the source code of step 1 and then continue on with step 2 etc...

I am not 100% clear about the Cef.Initialize() call. Should I add this to step 1 or not.
When precisely do I need it? I am just asking because step 1 seems to work fine without it
but I re-call that it stops working at some point. Is it possible to describe that point?

Do you have an account on CodeProject? If yes,  I could set you as co-author and you could
review/improve before everyone else sees it.

I don't mind the extra work. Its really fun and I use it myself once in a while to remember how
what worked for me ... :-)

Alex Maitland

unread,
Mar 2, 2015, 7:42:09 AM3/2/15
to cefs...@googlegroups.com
`Cef.Initialize()` is a bit of a complicated subject, with the release of version `39` I hope to simplify this. Should you wish to specify some settings, e.g. `settings.UserAgent` then you need to call Initialize before you create a browser instance.
I'll have a think about how to best explain the subject and get back to you with some words.

I currently don't have a codeproject account, I can create one though. Let me get back to you on that.

Let me know if you need help with the pull request.

dirk_...@gmx.de

unread,
Mar 2, 2015, 7:45:11 PM3/2/15
to cefs...@googlegroups.com
I created a pull request here:
https://github.com/cefsharp/CefSharp.Tutorial/pull/1

Hope this is all good its the first PR I've ever done :-)

dirk_...@gmx.de

unread,
Mar 4, 2015, 1:01:15 PM3/4/15
to cefs...@googlegroups.com

 
I guess, the pull request worked well done :-)

Am going for 2nd Part of the article series - do you have a codeproject account?

I don't know much more about ResourceHandler then what is written here:

Which is really not much. Is this correct? A ResourceHandler defines the HTML content for a fixed URL? Or are there other ways in which a ResourceHandler could be used?

Alex Maitland

unread,
Mar 4, 2015, 6:14:01 PM3/4/15
to cefs...@googlegroups.com
PR was merged without a problem, thanks!

Haven't gotten around to creating a codeproject account yet.

I'll have a quick look at `ResourceHandler` later, just so your up to date there's a PR in the pipeline that will contain some breaking changes see https://github.com/cefsharp/CefSharp/pull/857

I see you have a number of other examples in your KB project, did you wish to merge those into the Tutorial repository as well?

When I get a spare sec I'll see about adding you as a contributor to the `CefSharp.Tutorial` repository. Then you can merge yourself.

Alex Maitland

unread,
Mar 12, 2015, 6:07:03 AM3/12/15
to cefs...@googlegroups.com
I've created a codeproject account finally, sorry it took so long! Username is maitlandalex.

PR #847 has been merged, so we can progress with the `ResourceHandler example if your up for it? Just start using a `CI` build until `39` is out.

dirk_...@gmx.de

unread,
Mar 16, 2015, 4:37:06 AM3/16/15
to cefs...@googlegroups.com
Hi Alex, I am up for it - will try to produce a draft at the start of this week - it should not be too difficult since we already have a working code example.

What do you mean by CI build? Does this refer to the build available via Myget?

Thanks Dirk

Alex Maitland

unread,
Mar 16, 2015, 5:36:22 AM3/16/15
to cefs...@googlegroups.com
Hey,

Yep, builds published to `MyGet`. So everytime there's a commit to `master`, our `AppVeyor` account will build a set of nuget packages and push them to `MyGet` (assuming the build was successful).

`CI` = Continuous Integration.

Alex

dirk_...@gmx.de

unread,
Mar 16, 2015, 6:16:53 PM3/16/15
to cefs...@googlegroups.com
OK'ey Dokey

I have drafted the next article. You should be able to see it here:

and the sample code is also stored where you might expect it:

Updating the article should be easy. Just click on the Update Article button on the top right corner. Use the article
submission Wizard to do your edits and use the Save button controls at the bottom to save your edits. Feel free to
publish it if you are happy with the content.

Let me know what you think about it and feel free to change things around if there is something that's plain wrong
or something vital is missing... I added a MarkDown viewer sample because I felt its a much more interesting sample
application than the usual HelloWorld stuff.

What do you think about it? The sample also tries to load a markdown.css file via the ResourceHandler mechanism
but it does not seem to work :-(. Is this possible or should I use the SchemeHandler for loading css content?

Can you see what I am doing wrong?

Alex Maitland

unread,
Mar 17, 2015, 8:53:17 AM3/17/15
to cefs...@googlegroups.com
Nice! I'll check out the new code sometime tomorrow, hopefully the css thing is an easy fix.
Reply all
Reply to author
Forward
0 new messages