-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sed expression editing #1542
base: master
Are you sure you want to change the base?
Sed expression editing #1542
Conversation
2acfe89
to
9d5d813
Compare
if (UserSettings::instance()->sedEditing() && room->edit().isEmpty()) [[unlikely]] { | ||
// The bulk of this logic was shamelessly stolen from Neochat. Thanks to Carl Schwan for | ||
// letting us have this :) | ||
static const QRegularExpression sed("^s/([^/]*)/([^/]*)(/g)?$"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means there is no way to escape a / in the regex. Probably fine, but not great. Also I really like that Vim allows you to use any non-alphanumeric character as the separator. So maybe actually go with the /s/ command :)
if (flags == "/g") | ||
other.replace(regex, replacement); | ||
else | ||
other.replace(other.indexOf(regex), regex.size(), replacement); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That way the first one will do \1 group replacement, the other one won't.
The proper solution is probably to extract the first match and only do a replace on that, then stitch it back together. The regex.size() also is wrong, since it will behave incorrectly with /s/.*// imo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I understand what you are saying here. Could you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If you do a replacement with
s/.*//
, I think your code will just delete 2 characters at the start of the message. - If you do a replacement like
s/[abc]*/__\1__/
the first one will replaceaaacbbbaaa
with__aaacbbbaaa__
, the second one will replace it with the literal text__\1__
, I think.
This reuses the Neochat code to edit your most recent message by sed expressions, but if you reply to one of your messages, it will try to edit that message instead.
This reuses the Neochat code to edit your most recent message by sed expressions, but if you reply to one of your messages, it will try to edit that message instead. Also, nheko is smarter and won't blindly apply a sed expression to a message that it won't change.