fix: prevent endless loop with buttons

This commit is contained in:
Oleg A 2025-01-05 13:30:13 +03:00
parent 44bd8fe103
commit c3071ac8f8
No known key found for this signature in database
GPG key ID: 7175209A1D749531

View file

@ -179,9 +179,12 @@ class KeyboardBuilder(Generic[ButtonType], ABC):
last_row.extend(head)
# Separate buttons to exclusive rows with max possible row width
while buttons:
row, buttons = buttons[: self.max_width], buttons[self.max_width :]
markup.append(list(row))
if self.max_width > 0:
while buttons:
row, buttons = buttons[: self.max_width], buttons[self.max_width :]
markup.append(list(row))
else:
markup.append(list(buttons))
self._markup = markup
return self