Fix inserting text when markdown preview is off
This commit is contained in:
parent
8be6c6e3ce
commit
8dd70f5d1a
5 changed files with 19 additions and 12 deletions
|
@ -17,9 +17,9 @@
|
|||
*/
|
||||
|
||||
import { Devs } from "@utils/constants";
|
||||
import { insertTextIntoChatInputBox } from "@utils/discord";
|
||||
import definePlugin from "@utils/types";
|
||||
import { filters, mapMangledModuleLazy } from "@webpack";
|
||||
import { ComponentDispatch } from "@webpack/common";
|
||||
|
||||
const ExpressionPickerState = mapMangledModuleLazy('name:"expression-picker-last-active-view"', {
|
||||
close: filters.byCode("activeView:null", "setState")
|
||||
|
@ -40,7 +40,7 @@ export default definePlugin({
|
|||
|
||||
handleSelect(gif?: { url: string; }) {
|
||||
if (gif) {
|
||||
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { rawText: gif.url + " " });
|
||||
insertTextIntoChatInputBox(gif.url + " ");
|
||||
ExpressionPickerState.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { insertTextIntoChatInputBox } from "@utils/discord";
|
||||
import {
|
||||
ModalContent,
|
||||
ModalFooter,
|
||||
|
@ -24,7 +25,7 @@ import {
|
|||
ModalRoot,
|
||||
openModal,
|
||||
} 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";
|
||||
|
||||
|
@ -84,9 +85,7 @@ function EncModal(props: ModalProps) {
|
|||
const toSend = noCover ? encrypted.replaceAll("d", "") : encrypted;
|
||||
if (!toSend) return;
|
||||
|
||||
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", {
|
||||
rawText: `${toSend}`
|
||||
});
|
||||
insertTextIntoChatInputBox(toSend);
|
||||
|
||||
props.onClose();
|
||||
}}
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
import { addButton, removeButton } from "@api/MessagePopover";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { insertTextIntoChatInputBox } from "@utils/discord";
|
||||
import definePlugin from "@utils/types";
|
||||
import { ChannelStore, ComponentDispatch } from "@webpack/common";
|
||||
import { ChannelStore } from "@webpack/common";
|
||||
|
||||
export default definePlugin({
|
||||
name: "QuickMention",
|
||||
|
@ -34,7 +35,7 @@ export default definePlugin({
|
|||
icon: this.Icon,
|
||||
message: msg,
|
||||
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 { classNameFactory } from "@api/Styles";
|
||||
import { Devs } from "@utils/constants";
|
||||
import { getTheme, Theme } from "@utils/discord";
|
||||
import { getTheme, insertTextIntoChatInputBox, Theme } from "@utils/discord";
|
||||
import { Margins } from "@utils/margins";
|
||||
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, openModal } from "@utils/modal";
|
||||
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) {
|
||||
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>
|
||||
<Button
|
||||
onClick={() => {
|
||||
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", { rawText: formatted });
|
||||
insertTextIntoChatInputBox(formatted + " ");
|
||||
close();
|
||||
}}
|
||||
>Insert</Button>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
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";
|
||||
|
||||
const PreloadedUserSettings = findLazy(m => m.ProtoClass?.typeName.endsWith("PreloadedUserSettings"));
|
||||
|
@ -42,3 +42,10 @@ export const enum Theme {
|
|||
export function getTheme(): Theme {
|
||||
return PreloadedUserSettings.getCurrentValue()?.appearance?.theme;
|
||||
}
|
||||
|
||||
export function insertTextIntoChatInputBox(text: string) {
|
||||
ComponentDispatch.dispatchToLastSubscribed("INSERT_TEXT", {
|
||||
rawText: text,
|
||||
plainText: text
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue