diff --git a/widget/editor.go b/widget/editor.go index 38783f03..43c283be 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -610,6 +610,7 @@ func (e *Editor) initBuffer() { e.text.SingleLine = e.SingleLine e.text.Mask = e.Mask e.text.WrapPolicy = e.WrapPolicy + e.text.DisableSpaceTrim = true } // Update the state of the editor in response to input events. Update consumes editor diff --git a/widget/text.go b/widget/text.go index 88e9d17f..fd6b3477 100644 --- a/widget/text.go +++ b/widget/text.go @@ -61,6 +61,9 @@ type textView struct { Truncator string // WrapPolicy configures how displayed text will be broken into lines. WrapPolicy text.WrapPolicy + // DisableSpaceTrim configures whether trailing whitespace on a line will have its + // width zeroed. Set to true for editors, but false for non-editable text. + DisableSpaceTrim bool // Mask replaces the visual display of each rune in the contents with the given rune. // Newline characters are not masked. When non-zero, the unmasked contents // are accessed by Len, Text, and SetText. @@ -285,6 +288,10 @@ func (e *textView) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, s e.params.LineHeightScale = e.LineHeightScale e.invalidate() } + if e.DisableSpaceTrim != e.params.DisableSpaceTrim { + e.params.DisableSpaceTrim = e.DisableSpaceTrim + e.invalidate() + } e.makeValid()