mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
feat: Implement display for text selection and caret (#35830)
This PR introduces an initial, straightforward implementation for displaying text selection and the caret. This is achieved by passing the selection range and insertion point index down to `TextFragment`, along with the starting offset of each `TextFragment` to determine the proper range for displaying the caret and text selection. Additionally, the `selected_style` was passed into `TextFragment` to specify the background color. During the final build phase, although whitespace is typically ignored when constructing glyphs, we still need to retrieve it to render both the caret and text selection at the correct location. This ensures that whitespace is not overlooked when the `TextFragment` contains an insertion point or selection range. There are several improvements yet to be made, including: - The caret is static and does not flash. - The caret is not rendered when the input field is empty. (I suppose there should be an easy fix somewhere but I haven't found it yet) **Working Examples** macOS https://github.com/user-attachments/assets/f3622cbe-9fa6-40c0-b2d8-b3a8f9842c28 Windows https://github.com/user-attachments/assets/9b008a0d-0011-4c76-a2e2-0e35869a216c Linux [Screencast from 03-07-2025 11_05_41 AM.webm](https://github.com/user-attachments/assets/09a311ad-f975-4450-a66c-b20be525a5ed) --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix part of #33237 (But the cursor isn't blinking yet) - [x] These changes do not require tests because there's no behavior change Signed-off-by: DK Liao <dklassic@gmail.com>
This commit is contained in:
parent
e6595619e1
commit
e62aecb103
9 changed files with 172 additions and 11 deletions
|
@ -212,7 +212,7 @@ pub trait ThreadSafeLayoutNode<'dom>: Clone + Copy + Debug + NodeInfo + PartialE
|
|||
|
||||
fn node_text_content(self) -> Cow<'dom, str>;
|
||||
|
||||
/// If the insertion point is within this node, returns it. Otherwise, returns `None`.
|
||||
/// If selection intersects this node, return it. Otherwise, returns `None`.
|
||||
fn selection(&self) -> Option<Range<ByteIndex>>;
|
||||
|
||||
/// If this is an image element, returns its URL. If this is not an image element, fails.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue