changeset 1978:5662a997c180 default tip

fix click location
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 26 Jun 2025 16:22:06 -0600
parents f827708b1805
children
files src/luan/modules/swing/TextAreaLuan.java
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r f827708b1805 -r 5662a997c180 src/luan/modules/swing/TextAreaLuan.java
--- a/src/luan/modules/swing/TextAreaLuan.java	Wed Jun 25 18:31:08 2025 -0600
+++ b/src/luan/modules/swing/TextAreaLuan.java	Thu Jun 26 16:22:06 2025 -0600
@@ -6,6 +6,7 @@
 import java.awt.Graphics;
 import java.awt.Color;
 import java.awt.Shape;
+import java.awt.Point;
 import java.awt.event.FocusListener;
 import java.awt.event.FocusEvent;
 import java.awt.event.ActionListener;
@@ -197,6 +198,23 @@
 				return new CustomWrappedPlainView( elem, getWrapStyleWord() );
 			return super.create(elem);
 		}
+
+		@Override public int viewToModel(JTextComponent tc, Point pt, Position.Bias[] biasReturn) {
+			try {
+				int pos = super.viewToModel(tc,pt,biasReturn);
+				Rectangle rect = modelToView(tc,pos);
+				//logger.info("viewToModel "+pos+" "+pt+" "+rect);
+				if( pos > 0 && pt.y >= rect.y && pt.y < rect.y + rect.height && pt.x < rect.x  ) {
+					Rectangle rectPrev = modelToView(tc,pos-1);
+					//logger.info("rectPrev "+rectPrev);
+					if( rect.y == rectPrev.y && pt.x < (rectPrev.x + rect.x) / 2 )
+						pos = pos - 1;
+				}
+				return pos;
+			} catch(BadLocationException e) {
+				throw new RuntimeException(e);
+			}
+		}
 	}