@@ -103,12 +103,15 @@ public Point getCursorPos(List<String> lines, int x, int y) {
103103 y -= getStartY (measuredLines .size ());
104104 int index = (int ) (y / (getFontHeight ()));
105105 if (index < 0 ) return new Point ();
106- if (index >= measuredLines .size ())
107- return new Point (measuredLines .get (measuredLines .size () - 1 ).getText ().length (), measuredLines .size () - 1 );
106+ if (index >= measuredLines .size ()) {
107+ return new Point (getRealLength (measuredLines .get (measuredLines .size () - 1 ).getText ()), measuredLines .size () - 1 );
108+ }
108109 Line line = measuredLines .get (index );
109110 x -= getStartX (line .getWidth ());
110111 if (line .getWidth () <= 0 ) return new Point (0 , index );
111- if (line .getWidth () < x ) return new Point (line .getText ().length (), index );
112+ if (line .getWidth () < x ) {
113+ return new Point (getRealLength (line .getText ()), index );
114+ }
112115 float currentX = 0 ;
113116 int ignoredChars = 0 ;
114117 for (int i = 0 ; i < line .getText ().length (); i ++) {
@@ -129,10 +132,14 @@ public Point getCursorPos(List<String> lines, int x, int y) {
129132 * Whether the given character should be ignored for cursor positioning purposes
130133 */
131134 @ ApiStatus .Experimental
132- protected boolean isIgnoredChar (char c ) {
135+ protected boolean isIgnoredChar (int c ) {
133136 return false ;
134137 }
135138
139+ private int getRealLength (String text ) {
140+ return text .length () - (int ) text .chars ().filter (this ::isIgnoredChar ).count ();
141+ }
142+
136143 public Point2D .Float getPosOf (List <Line > measuredLines , Point cursorPos ) {
137144 if (measuredLines .isEmpty ()) {
138145 return new Point2D .Float (getStartX (0 ), getStartYOfLines (1 ));
0 commit comments