widget: fix build on Go 1.17

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-02-09 21:04:18 +01:00
parent b162ed56d7
commit 912ddb95f8
+8 -2
View File
@@ -742,9 +742,15 @@ func (e *Editor) PaintCaret(gtx layout.Context) {
} }
} }
// TODO: copied from package math. Remove when Go 1.18 is minimum.
const (
intSize = 32 << (^uint(0) >> 63) // 32 or 64
maxInt = 1<<(intSize-1) - 1
)
// Len is the length of the editor contents, in runes. // Len is the length of the editor contents, in runes.
func (e *Editor) Len() int { func (e *Editor) Len() int {
end := e.closestPosition(combinedPos{runes: math.MaxInt}) end := e.closestPosition(combinedPos{runes: maxInt})
return end.runes return end.runes
} }
@@ -1051,7 +1057,7 @@ func (e *Editor) moveStart(selAct selectionAction) {
func (e *Editor) moveEnd(selAct selectionAction) { func (e *Editor) moveEnd(selAct selectionAction) {
caret := e.closestPosition(combinedPos{runes: e.caret.start}) caret := e.closestPosition(combinedPos{runes: e.caret.start})
caret = e.closestPosition(combinedPos{lineCol: screenPos{X: math.MaxInt, Y: caret.lineCol.Y}}) caret = e.closestPosition(combinedPos{lineCol: screenPos{X: maxInt, Y: caret.lineCol.Y}})
e.caret.start = caret.runes e.caret.start = caret.runes
l := e.lines[caret.lineCol.Y] l := e.lines[caret.lineCol.Y]
a := align(e.Alignment, l.Width, e.viewSize.X) a := align(e.Alignment, l.Width, e.viewSize.X)