vscode-markdown-shortcuts icon indicating copy to clipboard operation
vscode-markdown-shortcuts copied to clipboard

Toggle Code Block adds an unnecessary line break

Open robertmarkbram opened this issue 5 years ago • 6 comments

What is the problem?

Any time I use the Toggle Code Block, it adds an extra blank line at the end of my code.

  • Whether I select every line of code (including or excluding the last line break) or just leave the cursor in the current single line of code.
  • Whether I use the keyboard shortcut or invoke the function via the Command Palette.

How can I reproduce it?

Invoke the function.

robertmarkbram avatar Mar 23 '19 06:03 robertmarkbram

Just to clarify, if you select the following text:

Some code with
an empty line

and use Toggle Code Block, then you would expect the result to be (with backticks instead of apostrophes):

'''
Some code with
an empty line
'''

correct?

mdickin avatar Mar 25 '19 15:03 mdickin

I think the behaviour should be

  • do not modify the selected text (so don't remove any trailing or leading new lines if the user wants them there for whatever reason)
  • end with the entire code block plus the lines with surrounding bacticks selected so that the user can indent the whole lot if needed.

So if have my cursor in the middle of a single line when I run the code block function:

some code

I should end up with the following (all selected):

```
some code
```

And if I have these three lines when I run the function:

some code
with an empty line

I should end up with the following (all selected):

```
some code
with an empty line

```

robertmarkbram avatar Mar 25 '19 19:03 robertmarkbram

I'm not sure how this is different from current behavior

Before: image After: image

Before: image After: image

If this doesn't match what you're seeing, can you tell me what OS you're using and the version of VSCode?

mdickin avatar Mar 26 '19 12:03 mdickin

Going back and re-reading your last comment, is this about line breaks or is it about text selection? With the text selection, I agree, it doesn't currently select the entire text inside the code block.

mdickin avatar Mar 26 '19 12:03 mdickin

Hi @mdickin , try putting some extra lines at the end of of your file, then you might see the behaviour..

Before: 2019-03-27 16_10_41-VS Code MD

After: 2019-03-27 15_51_02-VS Code MD

Before: 2019-03-27 15_54_00-VS Code MD

After: 2019-03-27 15_54_21-VS Code MD

My core issue is about the empty lines being added, but as I was typing my reply I thought I would try to sneak a feature request into a bug report... or something like that :)

Rob :)

robertmarkbram avatar Mar 27 '19 05:03 robertmarkbram

Ok, I see now. Thank you for being patient with me!

That's a weird one, I'll dig into it.

mdickin avatar Mar 27 '19 12:03 mdickin