Skip to content

script: Add support for setting the edit point with the mouse in <input> and <textarea> - #41906

Merged
mrobinson merged 1 commit into
servo:mainfrom
mrobinson:glyph-index
Jan 14, 2026
Merged

mrobinson merged 1 commit into
servo:mainfrom
mrobinson:glyph-index

Conversation

@mrobinson

@mrobinson mrobinson commented Jan 14, 2026 •

Copy link
Copy Markdown
Member

This change updates and implements the old query_text_index layout
query to properly look for the glyph index of a point within a node's
Fragments. This should work properly with the shadow DOM of both
<input> and <textarea> elements. In particular, multiple lines are
supported.

Caveats:

  • <input> and <textarea> that are transformed are currently not
    supported. This will happen in a followup.
  • For multi-line inputs, we should be finding the text offset of the
    nearest line that is within the block range of the click. This will
    happen in a followup.

Testing: This change adds two Servo-specific WPT-style tests. These are
Servo-specific because the behavior of clicking in text fields isn't
fully specified.

Fixes: #35432
Fixes: #10083

@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 14, 2026
@mrobinson
mrobinson force-pushed the glyph-index branch 2 times, most recently from 926a7cb to cf24978 Compare January 14, 2026 11:10
@codecov-commenter

codecov-commenter commented Jan 14, 2026 •

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
861 1 860 0
View the top 1 failed test(s) by shortest run time
libservo::webview::test_show_and_hide_ime
Stack Traces | 0.227s run time
thread 'test_show_and_hide_ime' (43091) panicked at .../servo/tests/webview.rs:630:9:
assertion `left == right` failed
  left: Some(5)
 right: Some(0)
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: core::ops::function::FnOnce::call_once
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

ifc.possibly_flush_deferred_forced_line_break();

// Advance the glyph offset of the current inline container. Note that this must
// be done before handling preserved newlines, as they count as glpyhs for the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// be done before handling preserved newlines, as they count as glpyhs for the
// be done before handling preserved newlines, as they count as glyphs for the

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +382 to +385
current_offset += glyph.advance();
if current_offset - (glyph.advance().scale_by(0.5)) >= point.x {
return current_glyph;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can avoid calling glyph.advance() twice, and I think it looks better by increasing afterwards instead of subtracting in the condition

Suggested change
current_offset += glyph.advance();
if current_offset - (glyph.advance().scale_by(0.5)) >= point.x {
return current_glyph;
}
let advance = glyph.advance();
if current_offset + advance.scale_by(0.5) >= point.x {
return current_glyph;
}
current_offset += advance;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Jan 14, 2026
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 14, 2026
…put>` and `<textarea>`

This change updates and implements the old `query_text_index` layout
query to properly look for the glyph index of a point within a node's
`Fragment`s. This should work properly with the shadow DOM of both
`<input>` and `<textarea>` elements. In particular, multiple lines are
supported.

Caveats:
 - `<input>` and `<textarea>` that are transformed are currently not
   supported. This will happen in a followup.
 - For multi-line inputs, we should be finding the text offset of the
   nearest line that is within the block range of the click. This will
   happen in a followup.

Co-authored-by: Josh Matthews <[email protected]>
Co-authored-by: Oriol Brufau <[email protected]>
Signed-off-by: Martin Robinson <[email protected]>
@mrobinson
mrobinson enabled auto-merge January 14, 2026 13:14
@mrobinson
mrobinson added this pull request to the merge queue Jan 14, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 14, 2026
Merged via the queue into servo:main with commit d5dcdd6 Jan 14, 2026
@mrobinson
mrobinson deleted the glyph-index branch January 14, 2026 15:07
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

layout: implement process_text_index_request input / textarea - mouse interaction doesn't work

4 participants