widget: fix moveLines residual x offset calculation

Commit c22138f5f broke it, this change fixes it.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-02-16 19:40:55 +01:00
parent 845d35dd50
commit 2df3db361f
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -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)
}
+8
View File
@@ -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) {