mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 16:35:36 +00:00
widget: fix Editor panic
If you created an Editor and immediately SetCaret, it panicked because e.lines was nil and it looked at e.lines[0]. - Add e.makeValid at the top of SetCaret. - Add a test case for this situation. Signed-off-by: Larry Clapp <larry@theclapp.org>
This commit is contained in:
@@ -1186,6 +1186,7 @@ func (e *Editor) Selection() (start, end int) {
|
||||
// and end are in bytes, and represent offsets into the editor text. start and
|
||||
// end must be at a rune boundary.
|
||||
func (e *Editor) SetCaret(start, end int) {
|
||||
e.makeValid()
|
||||
// Constrain start and end to [0, e.Len()].
|
||||
l := e.Len()
|
||||
start = max(min(start, l), 0)
|
||||
|
||||
Reference in New Issue
Block a user