Sublime Forum

Block copy when nothing is selected

#1

Not sure if this is a bug but sure it feels like a bug to me:

CTRL-C with no text selected copies empty string!
Why is that bad?

It happens that I press CTRL-C to copy selected text and then place the cursor somewhere else and press again CTRL-C instead CTRL-V.

As a result, my clipboard is replaced with an empty string and I have to repeat the steps.

What is the logic of copying empty text when nothing is selected?

0 Likes

#2
	// If true, the copy and cut commands will operate on the current line
	// when the selection is empty, rather than doing nothing.
	"copy_with_empty_selection": true,

This setting, which defaults to true, controls this. You would end up with either the current line or, if the current line is empty, an empty string, on the clipboard if you use the copy command when there is no selection. Setting it to false sounds like what you want.

0 Likes

#3

Thanks.
I also use this way of copying a line without selecting it.
So I wouldn’t want to deactivate it.
Instead, I would expect that nothing is copied if the line is empty.

0 Likes

#4

In that case you would need something like a customized key binding that disables the key binding if the current line (the text before and after the cursor) is only optional whitespace and nothing else, or a plugin with a customized version of copy that checks the content of the line at each cursor.

This seems like something that has been asked before, but at the moment I’m unable to find where it was that I would have created a plugin for that.

1 Like

#5

I was hoping to see this change done in the core…
I’m not going to write a customization just for that.
Besides: I regard this as a bug.

0 Likes

#6

Copying an empty line doesn’t copy nothing, it copies an empty line. This is perhaps more obvious when cutting, where the empty line is removed.

1 Like

#7

FWIW I think the default behaviour is exactly as I expect it. As @bschaaf states, an empty line isn’t nothing, it’s an empty line (BOL, EOL, and CR/LF).

So if I copy an empty line and then paste, I get a new empty line, and my row-count goes up by one. This makes perfect sense.

1 Like

#8

I get your point.
I guess this is one of those things that make sense from a logical point of view but is just annoying in the practical use.

0 Likes

#9

Depends on personal expections. If you hit wrong key bindings, you just can’t expect right things to happen. A program can’t yet read your mind to know about your real intents.

0 Likes

#10

Now, you misinterpret me:
I’m not expecting to get “Paste” when I hit “Copy”.
That’s my fault.
I’m just not expecting to copy the empty line with nothing selected on an empty line.
I was expecting that nothing happens and my clipboard is still as it was before.
Again, I get the point of this behavior as it is right now.

0 Likes