fix regex, add * and empty text matchers

This commit is contained in:
janderedev 2021-08-12 23:17:52 +02:00
parent 82d3dd3c7b
commit dfed9515d1
No known key found for this signature in database
GPG key ID: 5D5E18ACB990F57A

View file

@ -107,7 +107,7 @@ const Action = styled.div`
`; `;
// For sed replacement // For sed replacement
const SED_REGEX = new RegExp("^s/([^])+/([^])+$"); const SED_REGEX = new RegExp("^s/([^])*/([^])*$");
// ! FIXME: add to app config and load from app config // ! FIXME: add to app config and load from app config
export const CAN_UPLOAD_AT_ONCE = 4; export const CAN_UPLOAD_AT_ONCE = 4;
@ -214,22 +214,34 @@ export default observer(({ channel }: Props) => {
renderer.messages.reverse(); renderer.messages.reverse();
if (msg) { if (msg) {
const [_, toReplace, newText, flags] = // eslint-disable-next-line prefer-const
content.split(/(?<!\\)\//); let [_, toReplace, newText, flags] = content.split(/(?<!\\)\//);
const newContent = msg.content
.toString() if (toReplace == "*") toReplace = msg.content.toString();
.replace(new RegExp(toReplace, flags), newText);
const newContent =
toReplace == ""
? msg.content.toString() + newText
: msg.content
.toString()
.replace(new RegExp(toReplace, flags), newText);
if (newContent != msg.content) { if (newContent != msg.content) {
msg.edit({ if (newContent.length == 0) {
content: newContent.substr(0, 2000), msg.delete().catch(console.error);
}) } else {
.then(() => msg.edit({
defer(() => content: newContent.substr(0, 2000),
renderer.jumpToBottom(SMOOTH_SCROLL_ON_RECEIVE), })
), .then(() =>
) defer(() =>
.catch(console.warn); renderer.jumpToBottom(
SMOOTH_SCROLL_ON_RECEIVE,
),
),
)
.catch(console.error);
}
} }
} }
} else { } else {