bd-contributions
bd-contributions copied to clipboard
Missing whitespace when copying codeblock contents
Description
New lines & (some) tabs are not copied to clipboard when a codeblock's content is copied.
This could be fixed multiple ways, but a favorable solution would be to add a "copy code" button on the codeblock.
Reproduction Steps
- Select all of the code in a codeblock
- Ctrl + C to copy it
- Ctrl + V in your favorite editor
- ???
- where are my newlines & (some) tabs?????
- Plugin Name: BetterCodeblocks
- Discord Release: Stable
- Platform: Windows 11
also fitting with this, tabs just vanish, might be related
this is temporarily fixable by editing the source. replace this in line 316:
// comment this out:
// return !min ? content : content.replace(new RegExp(`^ {${min}}`, "gm"), '');
// put this there:
return content
idk whether thatbreaks things elsewhere, but for now its better than the two missing whitespaces
this is temporarily fixable by editing the source. replace this in line 316:
// comment this out: // return !min ? content : content.replace(new RegExp(`^ {${min}}`, "gm"), ''); // put this there: return content ```idk whether thatbreaks things elsewhere, but for now its better than the two missing whitespaces
perhaps you should make a PR?
nah, im just removing functionality cheaply without knowing what else it might break, there has to be a reason why thats there, and im just basically skipping it. until i know why that is there in the first place that would be a bad idea
me running some tests console.log'ing the info. the first CONTENT is the variable as it exists in the parameter CONTENT 2 is after the first regex edit, the MIN is the value of
min
and then END is what it returns
This is an explanation of the first regex:
Second:
However, the line this regex is on also will reduce the content as an array by the regex into a number by using
Math.min()
on the values based on the array. Basically, this will compare each value (which represents the index of the returned regex match in the string) to the length of the array, and return the lower set of the numbers. Starting with Infinity, it will then add these numbers together for the sum, and set the min
variable to it
Then, the last regex, uses the min
variable and makes a regex
Then, on this line it will check first if min is 0, if it is, it returns the content variable as before, if it isn't, then it will replace content based on the regex above with a blank string
''
Essentially, the tl;dr, being the only reason that this (stupid) method exists, is to cut out the first line of indents in a code block. AKA, its basically useless. It is very possible that when making the plugin, there was some much that added extra spacing as to mess up the formatting, but currently there is no such issue and it makes no sense to include this. However, I am not the developer for this plugin so I'll leave that up to the developer.
Also, In my copy of the code I am setting the method to:
dedent(content) {
return content;
}```
As the first regex will remove any tab characters, and that is also pointless.
This is fixed in the latest commit. I've submitted a pullrequest to make the latest commit load shiki correctly which fixes both bugs for me.