BetterDiscordAddons icon indicating copy to clipboard operation
BetterDiscordAddons copied to clipboard

[Bug] BetterFormatting not doing anything

Open Esterze opened this issue 2 years ago • 17 comments

Which plugin/theme is this about? BetterFormattingRedux

Describe the Bug I type something in the chat, then try to format the message and nothing happens.

To Reproduce Type something in the chat, click on the formatting button and select any formatting.

Expected Behavior The plugin should format the message as expected.

Discord Version Fluent Discord 1.1.3 Stable 122087 (5c6d04c) BetterDiscord 1.5.2 Host 1.0.9004 Windows 10 64-Bit (10.0.19043)

Esterze avatar Apr 02 '22 13:04 Esterze

I've tried turning off the theme. That changed nothing. Then I thought I could reinstall the plugin, also nothing.

Esterze avatar Apr 02 '22 13:04 Esterze

Toolbar buttons ain't working anymore

Enrico9431 avatar Apr 02 '22 15:04 Enrico9431

the wrappers from the options still work (== for varied text, frex), but the toolbar buttons no longer work.

jathek avatar Apr 03 '22 18:04 jathek

same here

dranelixx avatar Apr 05 '22 19:04 dranelixx

same issue here

naotyu8 avatar Apr 06 '22 11:04 naotyu8

I've tried everything, but nothing ever happens. Nearly embarrassed myself just now while trying to mock someone with varied text 😵

Vicky-Boi avatar Apr 07 '22 09:04 Vicky-Boi

yup same not working

LukysGaming avatar Apr 08 '22 17:04 LukysGaming

The plugin needs an update since Discord has made a lot of changes in the past week

xDeniz avatar Apr 09 '22 16:04 xDeniz

Quick Fix for the buttons not working:

line: 511

Old:

async wrapSelection(leftWrapper, rightWrapper) {
	if (!rightWrapper) rightWrapper = leftWrapper;
	if (leftWrapper.startsWith("```")) leftWrapper = leftWrapper + "\n";
	if (rightWrapper.startsWith("```")) rightWrapper = "\n" + rightWrapper;
	const textarea = document.querySelector(DiscordSelectors.Textarea.textArea);
	if (!textarea) return;
	if (textarea.tagName === "TEXTAREA") return this.oldWrapSelection(textarea, leftWrapper, rightWrapper);
	const slateEditor = Utilities.findInTree(ReactTools.getReactInstance(textarea), e => e && e.wrapText, { walkable: ["return", "stateNode", "editorRef"] });
	if (!slateEditor) return;
	return slateEditor.wrapText(leftWrapper, rightWrapper);
}

New:

async wrapSelection(leftWrapper, rightWrapper) {
	if (!rightWrapper) rightWrapper = leftWrapper;
	if (leftWrapper.startsWith("```")) leftWrapper = leftWrapper + "\n";
	if (rightWrapper.startsWith("```")) rightWrapper = "\n" + rightWrapper;
	const textarea = document.querySelector(DiscordSelectors.Textarea.textArea);
	if (!textarea) return;
	if (textarea.tagName === "TEXTAREA") return this.oldWrapSelection(textarea, leftWrapper, rightWrapper);
	const { Transforms } = BdApi.findModuleByProps('Transforms');
	const slate = ReactTools.getOwnerInstance(textarea).ref.current.getSlateEditor();
	let selection = JSON.parse(JSON.stringify(slate.selection));
	Transforms.insertText(slate,leftWrapper,{at:slate.selection.anchor});
	Transforms.insertText(slate,rightWrapper,{at:slate.selection.focus});
	selection.anchor.offset += 2;
	selection.focus.offset += 2;
	Transforms.select(slate,selection); 
	return 1; // promise mem leak prevention.
}

EDIT: I've updated the snippet to wrap the selection, if nothing is selected it will add the wrappers to the end of the text with the middle focused so you can just start typing after clicking the button.

ghost avatar Apr 11 '22 23:04 ghost

That code snippet update has fixed it! However, it no longer places the symbols around text that I select and puts it on the beginning and the end of the message only. Is there anything that can be done for that?

LoptmannC avatar Apr 14 '22 02:04 LoptmannC

Thank you for fixing the snippet, it works 100% now.

xDeniz avatar Apr 17 '22 07:04 xDeniz

New code seems to work! Much appreciated!

TheEliteGeek avatar May 03 '22 04:05 TheEliteGeek

It sucks, knowing that almost all plugins I'm using got abandoned.

Esterze avatar May 09 '22 13:05 Esterze

Anyway the snippet works just fine, thanks.

Esterze avatar May 09 '22 13:05 Esterze

Quick Fix for the buttons not working:

line: 511

Old:

async wrapSelection(leftWrapper, rightWrapper) {
	if (!rightWrapper) rightWrapper = leftWrapper;
	if (leftWrapper.startsWith("```")) leftWrapper = leftWrapper + "\n";
	if (rightWrapper.startsWith("```")) rightWrapper = "\n" + rightWrapper;
	const textarea = document.querySelector(DiscordSelectors.Textarea.textArea);
	if (!textarea) return;
	if (textarea.tagName === "TEXTAREA") return this.oldWrapSelection(textarea, leftWrapper, rightWrapper);
	const slateEditor = Utilities.findInTree(ReactTools.getReactInstance(textarea), e => e && e.wrapText, { walkable: ["return", "stateNode", "editorRef"] });
	if (!slateEditor) return;
	return slateEditor.wrapText(leftWrapper, rightWrapper);
}

New:

async wrapSelection(leftWrapper, rightWrapper) {
	if (!rightWrapper) rightWrapper = leftWrapper;
	if (leftWrapper.startsWith("```")) leftWrapper = leftWrapper + "\n";
	if (rightWrapper.startsWith("```")) rightWrapper = "\n" + rightWrapper;
	const textarea = document.querySelector(DiscordSelectors.Textarea.textArea);
	if (!textarea) return;
	if (textarea.tagName === "TEXTAREA") return this.oldWrapSelection(textarea, leftWrapper, rightWrapper);
	const { Transforms } = BdApi.findModuleByProps('Transforms');
	const slate = ReactTools.getOwnerInstance(textarea).ref.current.getSlateEditor();
	let selection = JSON.parse(JSON.stringify(slate.selection));
	Transforms.insertText(slate,leftWrapper,{at:slate.selection.anchor});
	Transforms.insertText(slate,rightWrapper,{at:slate.selection.focus});
	selection.anchor.offset += 2;
	selection.focus.offset += 2;
	Transforms.select(slate,selection); 
	return 1; // promise mem leak prevention.
}

EDIT: I've updated the snippet to wrap the selection, if nothing is selected it will add the wrappers to the end of the text with the middle focused so you can just start typing after clicking the button.

I've tried to follow this, it didn't work for me, maybe I was doing it wrong, can someone tell me how to do it that would be very appreciated.

Maybe0sir avatar Jun 10 '22 17:06 Maybe0sir

NVM, it somehow worked after BFDB got updated

Maybe0sir avatar Jun 10 '22 18:06 Maybe0sir

Excellent! I was digging for a fix and this worked perfectly! Thank you

ghost avatar Aug 04 '22 23:08 ghost

Thank you @BadScribbles I used yours as a reference and made some minor improvements on it!

zerebos avatar Aug 30 '22 05:08 zerebos