How to implement text selection?

My question is not language based or OS based. I assume that every system offers some kind of TextOut (text, x, y) method. I am looking for some recommendations or articles on how I should implement the selection of the displayed text. Could not find information about this.

The only thing that comes to my mind is this:

When a user clicks on a point on a text canvas, I know the coordinates of that point. I need to calculate exactly where it will be in my text buffer. Therefore, I go from the beginning of the buffer, and I apply a style (if any) to each character (or block of text). After that, I know that after this style the letter gave a size. I add its width and height to the previously calculated X, Y coordinates. Thus, I move the buffer until the calculated position reaches the point that the user clicked on. After I reached a point within a certain offset, I have a starting point for selection.

This is the main idea. I do not know if this is good, I would like to know how this is done for real, for example, in Firefox. I know that I can browse the sources, and if I have no choice, I will do it. But first I try to find an article about this ...

+3
source share
2 answers

The choice of text is inherently specific to the control that contains it, and means that it saves that text.

( ) - , , , . , . , , , "-" .

- ( , ), , , , , . ( , ), , .

, . . , , , Rope Gap Buffers, , . , , , - /, , . , , .

, TextOut . , , (, ) , . , TextOut, , , . TextOut , , , .

+1

, ( , , , ). ( ) GUI selectionRange, , , .

.

Javascript . : , textarea JavaScript

0

Source: https://habr.com/ru/post/1782782/


All Articles