ViewRaw: Fix ugly copy icon & context menu position

This commit is contained in:
V 2023-09-05 21:20:13 +02:00
parent 860d6edc7b
commit 7d954f9ade
No known key found for this signature in database
GPG key ID: A1DC0CFB5615D905

View file

@ -26,9 +26,11 @@ import { Margins } from "@utils/margins";
import { copyWithToast } from "@utils/misc"; import { copyWithToast } from "@utils/misc";
import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { closeModal, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { Button, ChannelStore, Forms, Menu, Parser, Text } from "@webpack/common"; import { Button, ChannelStore, Forms, Menu, Parser, Text } from "@webpack/common";
import { Message } from "discord-types/general"; import { Message } from "discord-types/general";
const CodeContainerClasses = findByPropsLazy("markup", "codeContainer");
const CopyIcon = () => { const CopyIcon = () => {
return <svg viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" width="22" height="22"> return <svg viewBox="0 0 20 20" fill="currentColor" aria-hidden="true" width="22" height="22">
@ -61,8 +63,7 @@ function cleanMessage(msg: Message) {
function CodeBlock(props: { content: string, lang: string; }) { function CodeBlock(props: { content: string, lang: string; }) {
return ( return (
// make text selectable <div className={CodeContainerClasses.markup}>
<div style={{ userSelect: "text" }}>
{Parser.defaultRules.codeBlock.react(props, null, {})} {Parser.defaultRules.codeBlock.react(props, null, {})}
</div> </div>
); );
@ -127,7 +128,15 @@ const settings = definePluginSettings({
function MakeContextCallback(name: string) { function MakeContextCallback(name: string) {
const callback: NavContextMenuPatchCallback = (children, props) => () => { const callback: NavContextMenuPatchCallback = (children, props) => () => {
children.push( const lastChild = children.at(-1);
if (lastChild?.key === "developer-actions") {
const p = lastChild.props;
if (!Array.isArray(p.children))
p.children = [p.children];
({ children } = p);
}
children.splice(-1, 0,
<Menu.MenuItem <Menu.MenuItem
id={`vc-view-${name.toLowerCase()}-raw`} id={`vc-view-${name.toLowerCase()}-raw`}
label="View Raw" label="View Raw"