1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-08 08:56:22 +00:00

QuickReply: Prevent caret from moving when selecting message (#3104)

This commit is contained in:
Sqaaakoi 2024-12-30 15:22:10 +13:00 committed by GitHub
parent cca5d7dc09
commit 79e2cb15f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,7 +20,7 @@ import { definePluginSettings, Settings } from "@api/Settings";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { ChannelStore, FluxDispatcher as Dispatcher, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { ChannelStore, ComponentDispatch, FluxDispatcher as Dispatcher, MessageStore, PermissionsBits, PermissionStore, SelectedChannelStore, UserStore } from "@webpack/common";
import { Message } from "discord-types/general";
const Kangaroo = findByPropsLazy("jumpToMessage");
@ -60,24 +60,24 @@ export default definePlugin({
settings,
start() {
Dispatcher.subscribe("DELETE_PENDING_REPLY", onDeletePendingReply);
Dispatcher.subscribe("MESSAGE_END_EDIT", onEndEdit);
Dispatcher.subscribe("MESSAGE_START_EDIT", onStartEdit);
Dispatcher.subscribe("CREATE_PENDING_REPLY", onCreatePendingReply);
document.addEventListener("keydown", onKeydown);
},
stop() {
Dispatcher.unsubscribe("DELETE_PENDING_REPLY", onDeletePendingReply);
Dispatcher.unsubscribe("MESSAGE_END_EDIT", onEndEdit);
Dispatcher.unsubscribe("MESSAGE_START_EDIT", onStartEdit);
Dispatcher.unsubscribe("CREATE_PENDING_REPLY", onCreatePendingReply);
document.removeEventListener("keydown", onKeydown);
},
});
const onDeletePendingReply = () => replyIdx = -1;
const onEndEdit = () => editIdx = -1;
flux: {
DELETE_PENDING_REPLY() {
replyIdx = -1;
},
MESSAGE_END_EDIT() {
editIdx = -1;
},
MESSAGE_START_EDIT: onStartEdit,
CREATE_PENDING_REPLY: onCreatePendingReply
}
});
function calculateIdx(messages: Message[], id: string) {
const idx = messages.findIndex(m => m.id === id);
@ -109,6 +109,8 @@ function onKeydown(e: KeyboardEvent) {
if (!isUp && e.key !== "ArrowDown") return;
if (!isCtrl(e) || isAltOrMeta(e)) return;
e.preventDefault();
if (e.shiftKey)
nextEdit(isUp);
else
@ -194,9 +196,10 @@ function nextReply(isUp: boolean) {
channel,
message,
shouldMention: shouldMention(message),
showMentionToggle: channel.guild_id !== null && message.author.id !== meId,
showMentionToggle: channel.isPrivate() && message.author.id !== meId,
_isQuickReply: true
});
ComponentDispatch.dispatchToLastSubscribed("TEXTAREA_FOCUS");
jumpIfOffScreen(channel.id, message.id);
}