Vscode: Ctrl-k (kill to end of line) does not delete empty line.

Created on 30 Jun 2016  路  17Comments  路  Source: microsoft/vscode

VSCode Version:
Version 1.3.0-insider (1.3.0-insider)
a21c123
2016-06-30T05:01:53.185Z

OS Version:
OSX 10.11.5 (15F34)

Steps to Reproduce:

  1. In a new document, type 'a' and then return for a newline.
  2. Place the editor caret in front of 'a'.
  3. Press ctrl-k twice.

In any standard OSX text area, this results in the text 'a' being killed, then the second kill deletes the empty line.
In VS Code, the 'a' gets killed, but the second kill has no effect.

As a user habituated to the standard text commands, this is very annoying, because it prevents me from quickly deleting multiple lines of text; instead, I have to alternate between ctrl-k and ctrl-d.

bug editor mac verified

Most helpful comment

I would go for changing the implementation of DeleteAllRight. I am pretty sure the only reason we added it was for mac's ctrl+k.

All 17 comments

fyi @joaomoreno

@gwk We bind ctrl+k on the mac to deleteAllRight.

https://github.com/Microsoft/vscode/blob/master/src/vs/editor/common/config/config.ts#L295

registerCoreCommand(H.DeleteAllRight, {
    primary: null,
    mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_K, secondary: [KeyMod.CtrlCmd | KeyCode.Delete] }
});

That was my understanding of ctrl+k from https://support.apple.com/en-gb/HT201236

image

Should ctrl+k bind by default to editor.action.deleteLines or should it handle differently the empty line case in its implementation?

@alexandrudima the support article you mention does not describe the 'empty line' case, but it is real, and I hope vscode will support it. Should editor.action.deleteLines handle this case, or do we need a new action?

I tried to find more reference material but it is not very interesting. The system default cocoa keybinding is found in /System/Library/Frameworks/AppKit.framework/Resources/StandardKeyBinding.dict:

"^k": "deleteToEndOfParagraph:"

This name refers to the NSResponder method documented here:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSResponder_Class/index.html#//apple_ref/occ/instm/NSResponder/deleteToEndOfParagraph:

The actual implementation is by NSTextView, NSTextField and whoever else, and I don't see a specification of implemented behavior.

After testing it in three other apps (Sublime, TextEdit, Notes), this is the behaviour I distilled:

  • If the cursor is not at the end of a line, delete everything from that position until the end of the line. This is what we currently have.
  • Otherwise, delete the new line character right after the cursor, effectively joining the current line with the next line.

@alexandrudima Should we implement a context for it (cursorAtEndOfLine) or should we just create a new command SpecialDeleteAllRight?

Agree with @joaomoreno, the behavior is dependent on cursor position, not line contents as I implied earlier! For what it's worth, I think the determination should be made based on the behavior of (default) cocoa text fields, and not Sublime Text, which is a completely custom implementation.

I would go for changing the implementation of DeleteAllRight. I am pretty sure the only reason we added it was for mac's ctrl+k.

I stumbled across this today. I miss this behavior of ctrl-k since it works almost everywhere in Mac.

This is the normal emacs (not only Mac) keybinding that also work in the terminal and any linux DE with emacs keybinding.

Would love to see this fixed/changed - I have so much muscle memory around Ctrl-K working as described by @joaomoreno above.

I can take this, @alexandrudima. 馃憤

@joaomoreno I've just moved the code to a better place, outside the editor core (lineOperations.ts)

馃挴

Did that land in 1.8.1 yet?

Nope.

Can this be done for DeleteAllLeft as well?

What's the keybinding for that?

@joaomoreno it's cmd+backspace on mac (I imagine cmd+del on Windows)

Yeah, wanna file an issue for it? You can ping me there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisdias picture chrisdias  路  3Comments

mrkiley picture mrkiley  路  3Comments

biij5698 picture biij5698  路  3Comments

villiv picture villiv  路  3Comments

VitorLuizC picture VitorLuizC  路  3Comments