diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2017-07-29 16:56:32 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2017-07-30 00:42:37 +0200 |
commit | 1cf43894a55ef7c765a573d393a180120b6efa51 (patch) | |
tree | 505655c19802aa3dfbbbc6eac99d010d3a1fb5fa /wee_slack.py | |
parent | f71af881d287c634941e3bc4b3ce0244479c82bd (diff) | |
download | wee-slack-1cf43894a55ef7c765a573d393a180120b6efa51.tar.gz |
Improve rendering of changes in multiline messages
Previously, if a multiline message was edited or reacted to, all of the
new message would be crammed into the last line of the already printed
message.
This change updates each line separately, so if the number of lines in
the message doesn't change, the message will still be rendered correctly
after edits or reactions.
If the number of lines change, the rendering is still improved, however
I don't know if it is possible to insert or delete lines in a weechat
buffer without re-rendering the whole buffer, so it won't be perfect. If
the number of lines of a message decreases after an edit, the extra
lines will still be present, but they will be blanked. If the number of
lines increases, the first lines will be set as normally, but the last
line will contain all of the rest of the lines.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/wee_slack.py b/wee_slack.py index 7fd6313..ad196e6 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2716,6 +2716,8 @@ def modify_buffer_line(buffer, new_line, timestamp, time_id): # hold the structure of a line and of line data struct_hdata_line = w.hdata_get('line') struct_hdata_line_data = w.hdata_get('line_data') + # keep track of the number of lines with the matching time and id + number_of_matching_lines = 0 while line_pointer: # get a pointer to the data in line_pointer via layout of struct_hdata_line @@ -2726,13 +2728,25 @@ def modify_buffer_line(buffer, new_line, timestamp, time_id): # prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix') if timestamp == int(line_timestamp) and int(time_id) == line_time_id: - # w.prnt("", "found matching time date is {}, time is {} ".format(timestamp, line_timestamp)) - w.hdata_update(struct_hdata_line_data, data, {"message": new_line}) + number_of_matching_lines += 1 + elif number_of_matching_lines > 0: + # since number_of_matching_lines is non-zero, we have + # already reached the message and can stop traversing break - else: - pass # move backwards one line and try again - exit the while if you hit the end line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1) + + # split the message into at most the number of existing lines + lines = new_line.split('\n', number_of_matching_lines - 1) + # pad the list with empty strings until the number of elements equals + # number_of_matching_lines + lines += [''] * (number_of_matching_lines - len(lines)) + + if line_pointer: + for line in lines: + line_pointer = w.hdata_move(struct_hdata_line, line_pointer, 1) + data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data') + w.hdata_update(struct_hdata_line_data, data, {"message": line}) return w.WEECHAT_RC_OK |