changeset 1961:ea659a1ef879

word wrapping
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 05 Jun 2025 18:28:00 -0600
parents ee48b0ed1dd1
children 037e43ceaa69
files src/luan/modules/swing/TextAreaLuan.java
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/swing/TextAreaLuan.java	Thu Jun 05 13:01:59 2025 -0600
+++ b/src/luan/modules/swing/TextAreaLuan.java	Thu Jun 05 18:28:00 2025 -0600
@@ -71,17 +71,17 @@
 				char[] a = segment.array;
 				int start = segment.offset;
 				int i = start + segment.count - 1;
-				if( !SwingLuan.isWordChar(a[i]) )
+				if( isBreakingChar(a[i]) )
 					return candidate;
 				do {
 					if( --i < start )
 						return candidate;
-				} while( SwingLuan.isWordChar(a[i]) );
+				} while( !isBreakingChar(a[i]) );
 				int breakPos = i + 1 - start + p0;
 				do {
 					if( --i < start )
 						return candidate;
-				} while( !SwingLuan.isWordChar(a[i]) );
+				} while( isBreakingChar(a[i]) );
 				return breakPos;
 			} catch (BadLocationException e) {
 				throw new RuntimeException(e);
@@ -89,6 +89,14 @@
 		}
 	}
 
+	public static boolean isBreakingChar(char c) {
+		return Character.isWhitespace(c)
+			|| c == ','
+			|| c == '('
+			|| c == ')'
+		;
+	}
+
 
 	private boolean showWhitespace = false;
 	private List<Range> highlights = Collections.emptyList();
@@ -111,7 +119,7 @@
 		if (UIManager.getLookAndFeel().getName().startsWith("FlatLaf")) {
 			setUI(new com.formdev.flatlaf.ui.FlatTextAreaUI() {
 				@Override public View create(Element elem) {
-					if (getLineWrap() && getWrapStyleWord())
+					if( getLineWrap() && getWrapStyleWord() )
 						return new CustomWrappedPlainView(elem);
 					return super.create(elem);
 				}