Skip to content

TextFieldWidget: clamp firstCharacterIndex when text is changed #1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 10.x-1.19.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public void addText(String text) {
}

public void onChanged(String newText) {
int length = newText.length();
if (this.firstCharacterIndex > length) {
this.firstCharacterIndex = length;
}
if (this.responder != null) {
this.responder.accept(newText);
}
Expand Down Expand Up @@ -409,7 +413,7 @@ public void renderBorder(PoseStack matrices) {
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
if (this.isVisible()) {
this.renderBorder(matrices);

int color = this.editable ? this.editableColor : this.notEditableColor;
int int_4 = this.cursorPos - this.firstCharacterIndex;
int int_5 = this.highlightPos - this.firstCharacterIndex;
Expand Down Expand Up @@ -582,7 +586,7 @@ public void setHighlightPos(int highlightPos) {
if (this.firstCharacterIndex > j) {
this.firstCharacterIndex = j;
}

int width = this.getWidth();
String clippedText = this.font.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), width);
int int_4 = clippedText.length() + this.firstCharacterIndex;
Expand Down