litehtml icon indicating copy to clipboard operation
litehtml copied to clipboard

How to impement a displaying of a text selecting?

Open NikitaFeodonit opened this issue 7 years ago • 14 comments

I would like to implement the selection of text by mouse or via Ctrl-A. Can the litehtml display a text selection at the click position?

NikitaFeodonit avatar Aug 01 '17 21:08 NikitaFeodonit

Or display of a selecting of the whole text by pressing a hotkey?

And how to get the selected text?

NikitaFeodonit avatar Aug 01 '17 21:08 NikitaFeodonit

Sorry litehtml doesn't support selection. You have to write your own code for this. Selection should be implemented via :selection selector. See the implementation of litehtml::html_tag::on_mouse_over and litehtml::html_tag::on_mouse_leave as example. These functions set/remove hover pseudo class for element. The same can be used for selection.

tordex avatar Aug 10 '17 14:08 tordex

Hi,

Litehtml is a really cool library, thanks for your awesome work. I am interested in using litehtml for an email client I am building.

I will be looking to implement text selection in the container. I was just wondering - are you aware of any good code bases where I could find such an implementation for Pango? The only ones that I'm aware are webkit and GTK which are way too complex and flexible.

Thanks so much Andrei

matzipan avatar Oct 12 '19 14:10 matzipan

Have you looked at freetype?

mmanyen avatar Oct 12 '19 19:10 mmanyen

I'm trying something out with pango atm. Any pointers about free type?

Sent from my iPhone

On 12 Oct 2019, at 21:53, Mark Manyen [email protected] wrote:

 Have you looked at freetype?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

matzipan avatar Oct 12 '19 20:10 matzipan

Ok, using pango I managed to mark the start position. Next I'm gonna work for the simple case where the end position is in the same el_text node.

How would the :selection work? Should I introduce a virtual element for the selection, and then render that using the :selection pseudo class? This begs the question, what do I do in the case where the selection spans multiple lines? Do I create one of these virtual elements for each line?

Or should it be entirely in the rendering, ie. pango markup for the text, and :selection styling for the elements?

I will push a merge request when I have something more substantial to show.

matzipan avatar Oct 13 '19 01:10 matzipan

Also very important question: what is the algorithm for selecting text over multiple elements? How does the layout come into play? I can get some intuition by playing a bit with some browsers, but I couldn't find any RFCs or anything describing this in more detail

matzipan avatar Oct 13 '19 01:10 matzipan

Some interesting documentation:

  • https://go.tiny.cloud/blog/a-quick-guide-to-browser-selection-models/
  • https://docs.google.com/document/d/19sakBLZnnU0GPCQS3-EuaohvR56A4TopVrI2MfxK-RI/edit#heading=h.ar8dxx954ldu
  • https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html

matzipan avatar Oct 13 '19 01:10 matzipan

I pushed https://github.com/litehtml/litehtml/pull/111. It's currently in early stages, but any input is welcome. I will also push demo code which is not meant to be merged.

matzipan avatar Oct 13 '19 13:10 matzipan

Qt Creator 4.11 comes with a Litehtml Help plugin, which has selection implemented.

Bare in mind that Qt Creator is GPL licensed.

You can download a snapshot from here: https://download.qt.io/snapshots/qtcreator/4.11/

cristianadam avatar Oct 13 '19 15:10 cristianadam

Seeing as litehtml is BSD licensed, I'm not sure how to navigate the licensing issues that this brings up, so I won't delve in it too deep, but it seems I went along a similar track. Thanks for the pointer!

matzipan avatar Oct 13 '19 15:10 matzipan

@matzipan You also might want to look at Claws Mail mail client, there's a relatively new plugin for using Litehtml to display HTML email there.

deacomm avatar Oct 25 '19 08:10 deacomm

@matzipan You also might want to look at Claws Mail mail client, there's a relatively new plugin for using Litehtml to display HTML email there.

Interesting. It seems really nice, thanks.

However, on the text selection front, I'm not seeing any code.

matzipan avatar Oct 25 '19 09:10 matzipan

No, I guess I mentioned it mostly because it also uses Pango for fonts.

deacomm avatar Oct 25 '19 09:10 deacomm