Browse Source

TextField: Include caret spacing in visible editor rect to avoid text shifting when the caret is at the start/end of the line.

pull/235/head
weisj 4 years ago
parent
commit
8b3c2705c1
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 6
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java
  2. 2
      core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

6
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextFieldUI.java

@ -148,6 +148,12 @@ public class DarkTextFieldUI extends DarkTextFieldUIBridge implements PropertyCh
rect.y = ins.top + FontUtil.getCenteredFontPosition(height, fm);
rect.height = fm.getHeight();
}
if (rect != null) {
// Provide spacing for caret to avoid jumping text if the caret moves to the start or end of the
// line.
// This space is already included in DarkTextUI#getPreferredSize.
rect.width += getCaretWidth(editor);
}
adjustTextRect(getComponent(), rect);
return rect;
}

2
core/src/main/java/com/github/weisj/darklaf/ui/text/DarkTextUI.java

@ -235,6 +235,8 @@ public abstract class DarkTextUI extends BasicTextUI implements OpacityBufferedU
}
}
if (c.getSize().width < dim.width) {
// Provide spacing for caret to avoid jumping text if the caret moves to the start or end of the
// line.
dim.width += getCaretWidth(editor);
}
return dim;

Loading…
Cancel
Save