diff --git a/widget/editor.go b/widget/editor.go index 748a973f..e44a1083 100644 --- a/widget/editor.go +++ b/widget/editor.go @@ -398,7 +398,7 @@ func (e *Editor) moveLines(distance int, selAct selectionAction) { pos := e.closestPosition(combinedPos{lineCol: screenPos{Y: caretStart.lineCol.Y + distance}}) pos = e.closestPosition(combinedPos{x: x, y: pos.y}) e.caret.start = pos.runes - e.caret.xoff = x - caretStart.x + e.caret.xoff = x - pos.x e.updateSelection(selAct) } diff --git a/widget/editor_test.go b/widget/editor_test.go index 6b5c91c6..de240efa 100644 --- a/widget/editor_test.go +++ b/widget/editor_test.go @@ -120,6 +120,14 @@ func TestEditor(t *testing.T) { } } } + + // Test that moveLine applies x offsets from previous moves. + e.SetText("long line\nshort") + e.SetCaret(0, 0) + e.moveEnd(selectionClear) + e.moveLines(+1, selectionClear) + e.moveLines(-1, selectionClear) + assertCaret(t, e, 0, utf8.RuneCountInString("long line"), len("long line")) } func TestEditorDimensions(t *testing.T) {