#FEATURE by cg
class: EditTextView
added:
#trimLastCR
#trimLastCR:
changed: #contents
--- a/EditTextView.st Sun May 27 11:39:43 2018 +0200
+++ b/EditTextView.st Mon May 28 12:27:38 2018 +0200
@@ -1328,6 +1328,24 @@
if nil, the setting follows the current userPref setting."
trimBlankLines := aBooleanOrNil.
+!
+
+trimLastCR
+ "If true, the last line is returned without a trailing CR character;
+ The default is false; this is only used by very specialized editors."
+
+ ^ (self objectAttributeAt:#trimLastCR) ? false
+
+ "Created: / 28-05-2018 / 12:05:34 / Claus Gittinger"
+!
+
+trimLastCR:aBooleanOrNil
+ "If true, the last line is returned without a trailing CR character;
+ The default is false; this is only used by very specialized editors."
+
+ self objectAttributeAt:#trimLastCR put:aBooleanOrNil.
+
+ "Created: / 28-05-2018 / 12:05:02 / Claus Gittinger"
! !
!EditTextView methodsFor:'accessing-contents'!
@@ -1382,7 +1400,7 @@
contents
"return the contents as a String or Text (i.e. with emphasis)"
- |numLines|
+ |numLines contents|
list isNil ifTrue:[^ ''].
self trimBlankLines ifTrue:[
@@ -1401,9 +1419,18 @@
].
].
].
- ^ super contents.
+ contents := super contents.
+ (self trimLastCR) ifTrue:[
+ contents isString ifTrue:[
+ (contents endsWith:Character cr) ifTrue:[
+ ^ contents copyButLast
+ ].
+ ].
+ ].
+ ^ contents
"Modified: / 04-07-2006 / 19:22:32 / fm"
+ "Modified: / 28-05-2018 / 12:25:31 / Claus Gittinger"
!
contents:aStringOrStringCollectionOrNil