Files
ladybird/Tests/LibWeb/Text/input/input-scroll-cursor-into-view.html
Jelle Raaijmakers 2d4728d353 LibWeb: Keep cursor in view for text controls
When editing or changing the selection inside an <input> or <textarea>,
we should scroll the container so the cursor is always visible. Note
that currently the cursor might still become invisible at the end of the
container since we do not reserve enough space for it to be made
visible.
2026-02-11 11:04:53 +01:00

34 lines
927 B
HTML

<!DOCTYPE html>
<style>
input {
font-size: 16px;
width: 100px;
padding: 2px;
border: 1px solid;
}
</style>
<input value="foobarbazloremipsum foobarbazloremipsum" />
<script src="include.js"></script>
<script>
test(() => {
const input = document.querySelector("input");
input.offsetWidth;
input.focus();
// Click near the left edge before scrolling.
const rect = input.getBoundingClientRect();
const x = rect.left + 5;
const y = rect.top + rect.height / 2;
internals.click(x, y);
println(`before: ${input.selectionStart}`);
// Move cursor to the end, which should scroll the input.
input.setSelectionRange(39, 39);
input.offsetWidth;
// Click in the same spot after scrolling.
internals.click(x, y);
println(`after: ${input.selectionStart}`);
});
</script>