Skip to content

Commit bbf5c94

Browse files
committed
more minor fixes for input/text area value and selection handling + many more detailed tests
1 parent b4e9b4c commit bbf5c94

6 files changed

Lines changed: 618 additions & 16 deletions

File tree

src/changes/changes.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@
88

99
<body>
1010
<release version="5.4.0" date="August xx, 2026" description="Firefox 153, Bugfixes">
11+
<action type="fix" dev="rbri">
12+
Fixed HtmlTextArea.reset(): the text entry cursor/selection is now only moved to the end of the restored
13+
value when that value actually differs from the current one, instead of always being forced to the end.
14+
</action>
15+
<action type="fix" dev="rbri">
16+
Fixed HtmlInput/HtmlSelectableTextInput: setting the value to the value it already holds no longer moves
17+
the text entry cursor/selection to the end, mirroring the same fix applied to HtmlTextArea.
18+
</action>
19+
<action type="fix" dev="rbri">
20+
Fixed HtmlSelectableTextInput.reset(): removed a leftover selection reset that left selectionStart and
21+
selectionEnd in an inconsistent state after a form reset.
22+
</action>
1123
<action type="update" dev="rbri">
12-
Major refactoring of the value handling for textarea - setting the value no longer manipulates the DOM,
24+
Major refactoring of the value handling for textarea; setting the value no longer manipulates the DOM,
1325
instead a separate value and dirty flag are maintained (this is now in sync with the spec and the input element).
1426
</action>
1527
<action type="remove" dev="rbri">

src/main/java/org/htmlunit/html/HtmlInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public abstract class HtmlInput extends HtmlElement implements DisabledElement,
6868

6969
/**
7070
* The element's raw value (spec term), decoupled from the DOM child nodes
71-
* once {@link #valueDirty_} is {@code true}. Mirrors {@code HtmlInput}'s
71+
* once {@link #isValueDirty_} is {@code true}. Mirrors {@code HtmlInput}'s
7272
* dirty-value-flag model rather than reading/writing child text nodes directly.
7373
*/
7474
private String rawValue_;

src/main/java/org/htmlunit/html/HtmlSelectableTextInput.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public abstract class HtmlSelectableTextInput extends HtmlInput implements Selec
4848
*/
4949
@Override
5050
public void setValue(final String newValue) {
51+
final String oldValue = getValue();
5152
super.setValue(newValue);
5253

5354
final SgmlPage page = getPage();
54-
if (page != null && page.isHtmlPage()) {
55+
if (page != null && page.isHtmlPage() && !newValue.equals(oldValue)) {
5556
final int pos = newValue.length();
5657
setSelectionStart(pos);
5758
setSelectionEnd(pos);
@@ -149,16 +150,6 @@ public void setSelectionEnd(final int selectionEnd) {
149150
selectionDelegate_.setSelectionEnd(selectionEnd);
150151
}
151152

152-
/**
153-
* {@inheritDoc}
154-
* @see HtmlInput#reset()
155-
*/
156-
@Override
157-
public void reset() {
158-
super.reset();
159-
setSelectionEnd(0);
160-
}
161-
162153
/**
163154
* {@inheritDoc}
164155
*/

src/main/java/org/htmlunit/html/HtmlTextArea.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,16 @@ public NameValuePair[] getSubmitNameValuePairs() {
208208
*/
209209
@Override
210210
public void reset() {
211+
final String oldValue = getText();
212+
211213
isValueDirty_ = false;
212214

213-
final int pos = computeValueFromChildText().length();
214-
setSelectionStart(pos);
215-
setSelectionEnd(pos);
215+
final String newValue = computeValueFromChildText();
216+
if (!newValue.equals(oldValue)) {
217+
final int pos = newValue.length();
218+
setSelectionStart(pos);
219+
setSelectionEnd(pos);
220+
}
216221
}
217222

218223
/**

0 commit comments

Comments
 (0)