mirror of
https://github.com/paul-nameless/tg
synced 2025-02-16 18:48:24 +00:00
fix msg lines counting
This commit is contained in:
parent
5476d3be30
commit
ea5d77c0b6
1 changed files with 15 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue