Ctrl-k (kill to end of line) does not delete empty line. #8575

Closed
gwk opened this Issue Jun 30, 2016 · 17 comments

Projects

None yet

9 participants

@gwk
gwk commented Jun 30, 2016

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.

@alexandrudima
Member

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 alexandrudima added this to the Backlog milestone Jul 12, 2016
@alexandrudima alexandrudima added the mac label Jul 12, 2016
@gwk
gwk commented Jul 12, 2016

@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.

@joaomoreno
Member
joaomoreno commented Jul 12, 2016 edited

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?

@gwk
gwk commented Jul 12, 2016

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.

@alexandrudima
Member

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.

@jjinux
jjinux commented Oct 6, 2016

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

@francisl
francisl commented Dec 1, 2016

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

@scolestock

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

@joaomoreno
Member

I can take this, @alexandrudima. 👍

@joaomoreno joaomoreno modified the milestone: January 2017, Backlog Dec 12, 2016
@alexandrudima
Member

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

@jjinux
jjinux commented Dec 12, 2016

💯

@nox
nox commented Jan 2, 2017

Did that land in 1.8.1 yet?

@joaomoreno
Member

Nope.

@bighitbiker3

Can this be done for DeleteAllLeft as well?

@joaomoreno
Member

What's the keybinding for that?

@bighitbiker3

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

@joaomoreno
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment