Fix inserting text when markdown preview is off

This commit is contained in:
Vendicated 2023-04-18 23:12:58 +02:00
parent 8be6c6e3ce
commit 8dd70f5d1a
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905
5 changed files with 19 additions and 12 deletions

@ -17,9 +17,9 @@
*/ */
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { insertTextIntoChatInputBox } from "@utils/discord";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { filters, mapMangledModuleLazy } from "@webpack"; import { filters, mapMangledModuleLazy } from "@webpack";
import { ComponentDispatch } from "@webpack/common";
const ExpressionPickerState = mapMangledModuleLazy('name:"expression-picker-last-active-view"', { const ExpressionPickerState = mapMangledModuleLazy('name:"expression-picker-last-active-view"', {
close: filters.byCode("activeView:null", "setState") close: filters.byCode("activeView:null", "setState")
@ -40,7 +40,7 @@ export default definePlugin({
handleSelect(gif?: { url: string; }) { handleSelect(gif?: { url: string; }) {
if (gif) { if (gif) {
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { rawText: gif.url + " " }); insertTextIntoChatInputBox(gif.url + " ");
ExpressionPickerState.close(); ExpressionPickerState.close();
} }
} }

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { insertTextIntoChatInputBox } from "@utils/discord";
import { import {
ModalContent, ModalContent,
ModalFooter, ModalFooter,
@ -24,7 +25,7 @@ import {
ModalRoot, ModalRoot,
openModal, openModal,
} from "@utils/modal"; } from "@utils/modal";
import { Button, ComponentDispatch, Forms, React, Switch, TextInput } from "@webpack/common"; import { Button, Forms, React, Switch, TextInput } from "@webpack/common";
import { encrypt } from "../index"; import { encrypt } from "../index";
@ -84,9 +85,7 @@ function EncModal(props: ModalProps) {
const toSend = noCover ? encrypted.replaceAll("d", "") : encrypted; const toSend = noCover ? encrypted.replaceAll("d", "") : encrypted;
if (!toSend) return; if (!toSend) return;
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { insertTextIntoChatInputBox(toSend);
rawText: `${toSend}`
});
props.onClose(); props.onClose();
}} }}

@ -18,8 +18,9 @@
import { addButton, removeButton } from "@api/MessagePopover"; import { addButton, removeButton } from "@api/MessagePopover";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { insertTextIntoChatInputBox } from "@utils/discord";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { ChannelStore, ComponentDispatch } from "@webpack/common"; import { ChannelStore } from "@webpack/common";
export default definePlugin({ export default definePlugin({
name: "QuickMention", name: "QuickMention",
@ -34,7 +35,7 @@ export default definePlugin({
icon: this.Icon, icon: this.Icon,
message: msg, message: msg,
channel: ChannelStore.getChannel(msg.channel_id), channel: ChannelStore.getChannel(msg.channel_id),
onClick: () => ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { rawText: `<@${msg.author.id}> ` }) onClick: () => insertTextIntoChatInputBox(`<@${msg.author.id}> `)
}; };
}); });
}, },

@ -21,11 +21,11 @@ import "./styles.css";
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents"; import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
import { classNameFactory } from "@api/Styles"; import { classNameFactory } from "@api/Styles";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { getTheme, Theme } from "@utils/discord"; import { getTheme, insertTextIntoChatInputBox, Theme } from "@utils/discord";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal"; import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
import definePlugin from "@utils/types"; import definePlugin from "@utils/types";
import { Button, ButtonLooks, ButtonWrapperClasses, ComponentDispatch, Forms, Parser, Select, Tooltip, useMemo, useState } from "@webpack/common"; import { Button, ButtonLooks, ButtonWrapperClasses, Forms, Parser, Select, Tooltip, useMemo, useState } from "@webpack/common";
function parseTime(time: string) { function parseTime(time: string) {
const cleanTime = time.slice(1, -1).replace(/(\d)(AM|PM)$/i, "$1 $2"); const cleanTime = time.slice(1, -1).replace(/(\d)(AM|PM)$/i, "$1 $2");
@ -104,7 +104,7 @@ function PickerModal({ rootProps, close }: { rootProps: ModalProps, close(): voi
<ModalFooter> <ModalFooter>
<Button <Button
onClick={() => { onClick={() => {
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { rawText: formatted }); insertTextIntoChatInputBox(formatted + " ");
close(); close();
}} }}
>Insert</Button> >Insert</Button>

@ -17,7 +17,7 @@
*/ */
import { findLazy } from "@webpack"; import { findLazy } from "@webpack";
import { ChannelStore, GuildStore, PrivateChannelsStore, SelectedChannelStore } from "@webpack/common"; import { ChannelStore, ComponentDispatch, GuildStore, PrivateChannelsStore, SelectedChannelStore } from "@webpack/common";
import { Guild } from "discord-types/general"; import { Guild } from "discord-types/general";
const PreloadedUserSettings = findLazy(m => m.ProtoClass?.typeName.endsWith("PreloadedUserSettings")); const PreloadedUserSettings = findLazy(m => m.ProtoClass?.typeName.endsWith("PreloadedUserSettings"));
@ -42,3 +42,10 @@ export const enum Theme {
export function getTheme(): Theme { export function getTheme(): Theme {
return PreloadedUserSettings.getCurrentValue()?.appearance?.theme; return PreloadedUserSettings.getCurrentValue()?.appearance?.theme;
} }
export function insertTextIntoChatInputBox(text: string) {
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", {
rawText: text,
plainText: text
});
}