Skip to content

Commit

Permalink
Only update size when values are valid
Browse files Browse the repository at this point in the history
In some environments the ioctl call for window size will return 0x0,
for instance in serial console setups. This causes the input to be
truncated making it hard for users to see what they are typing. This
performs a check to see if either width or height has a non-zero value
before updating the size.
  • Loading branch information
andrewsun2898 authored and knz committed Jul 17, 2023
1 parent e176cdf commit 20f487f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions editline/editline.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,12 @@ func (m *Model) Debug() string {
}

// SetSize changes the size of the editor.
// NB: if one of the dimensions is zero, the call is a no-op.
// NB: it only takes effect at the first next event processed.
func (m *Model) SetSize(width, height int) {
if width == 0 || height == 0 {
return
}
m.hasNewSize = true
m.newWidth = width
m.newHeight = height
Expand Down
10 changes: 10 additions & 0 deletions editline/testdata/bad_resize
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
run
reset
resize 40 25
resize 0 0
----
TEA WINDOW SIZE: {40 25}
TEA WINDOW SIZE: {0 0}
-- view:
>   ␤
M-? toggle key help • C-d erase/stop🛇

0 comments on commit 20f487f

Please sign in to comment.