mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
widget: ensure editor does not trim trailing whitespace
This commit makes the editor widget suppress the trimming of trailing whitespace so that the spaces can be selected intuitively. Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user