fix msg lines counting

This commit is contained in:
Alexander Zveruk 2020-05-20 21:45:08 +03:00
parent 5476d3be30
commit ea5d77c0b6

View file

@ -305,11 +305,22 @@ class MsgView:
# count wide character utf-8 symbols that take > 1 bytes to
# print it causes invalid offset
wide_char_len = sum(map(len, emoji_pattern.findall(msg)))
elements = (f" {dt} ", user_id, " " + msg)
total_len = sum(len(e) for e in elements) + wide_char_len
label_elements = [f" {dt} ", user_id]
msg_label_len = sum(len(e) for e in label_elements)
elements = *label_elements, f" {msg}"
needed_lines = 0
for i, msg_line in enumerate(msg.split("\n")):
emojies_count = sum(
map(len, emoji_pattern.findall(msg_line))
)
line_len = len(msg_line) + emojies_count
# first line cotains msg lable, e.g user name, date
if i == 0:
line_len += msg_label_len
needed_lines += (line_len // self.w) + 1
needed_lines = (total_len // self.w) + 1 + int(is_reply)
line_num -= needed_lines
if line_num <= 0:
break