Merge pull request #204 from tomsmeding/reply-quotes

Allow quotes in replied-to messages
This commit is contained in:
Denis Kasak 2020-06-03 11:31:31 +00:00 committed by GitHub
commit 126c55b3ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View file

@ -1360,7 +1360,7 @@ def matrix_reply_command_cb(data, buffer, args):
# necessary purpose
event_id, reply = parse_redact_args(args)
if not event_id:
if not event_id or not reply:
message = (
"{prefix}matrix: Invalid command "
"arguments (see /help reply)"

View file

@ -137,13 +137,16 @@ def matrix_message_completion_cb(data, completion_item, buffer, completion):
if not event_id:
continue
message = line.message
# Make sure we'll be able to reliably detect the end of the
# quoted snippet
message_fmt = line.message.replace("\\", "\\\\") \
.replace('"', '\\"')
if len(message) > REDACTION_COMP_LEN + 2:
message = message[:REDACTION_COMP_LEN] + ".."
if len(message_fmt) > REDACTION_COMP_LEN + 2:
message_fmt = message_fmt[:REDACTION_COMP_LEN] + ".."
item = ('{event_id}|"{message}"').format(
event_id=event_id, message=message
event_id=event_id, message=message_fmt
)
W.hook_completion_list_add(

View file

@ -182,10 +182,18 @@ def parse_redact_args(args):
event_id, rest = (args, "")
if had_example_text:
try:
_, _, reason = rest.split("\"", 2)
except ValueError:
reason = None
rest = rest.lstrip()
reason = None # until it has been correctly determined
if rest[0] == '"':
escaped = False
for i in range(1, len(rest)):
if escaped:
escaped = False
elif rest[i] == "\\":
escaped = True
elif rest[i] == '"':
reason = rest[i+1:]
break
else:
reason = rest