Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextEditor.selection is not respected in clipboard operations #6994

Closed
alefragnani opened this issue May 28, 2016 · 5 comments
Closed

TextEditor.selection is not respected in clipboard operations #6994

alefragnani opened this issue May 28, 2016 · 5 comments
Assignees

Comments

@alefragnani
Copy link

  • VSCode Version: ^1.1.0
  • OS Version: Windows

Steps to Reproduce:

  1. Update TextEditor.selection
  2. Execute editor.action.clipboardCopyAction or editor.action.clipboardCutAction commands
  3. Instead of copying to clipboard the new selected word, it copies the entire line (default Code behavior when nothing is selected)

The code is basically this one:

  const cursorWordRange = doc.getWordRangeAtPosition(selection.active);
  var newSe = new vscode.Selection(cursorWordRange.start.line, cursorWordRange.start.character, cursorWordRange.end.line, cursorWordRange.end.character);
  editor.selection = newSe;
  vscode.commands.executeCommand("editor.action.clipboardCopyAction");

The issue already appeared in version 0.10.11 and was fixed in March release (#4393), but returned 1.1.0.

Thanks in advance

@jrieken
Copy link
Member

jrieken commented May 30, 2016

@alefragnani It's not really an API command - the behaviour isn't spec'd. For now I'd recommend to use a node_module to copy stuff to clipboard

@alefragnani
Copy link
Author

@jrieken I understand that. I just reported the issue because in #4393 it was considered a bug, and was fixed by this commit.

I will move to https://github.com/xavi-/node-copy-paste, as you suggested in some other issues, like #4972 and #217.

Thanks

@jrieken
Copy link
Member

jrieken commented May 31, 2016

@alexandrudima Can you comment?

@alexdima
Copy link
Member

alexdima commented Aug 9, 2016

Sorry for not noticing this comment, I tried the following and it works for me:

commands.registerCommand('test', () => {
        let editor = window.activeTextEditor;
        let doc = editor.document;
        let selection = editor.selection;

        const cursorWordRange = doc.getWordRangeAtPosition(selection.active);
        var newSe = new Selection(cursorWordRange.start.line, cursorWordRange.start.character, cursorWordRange.end.line, cursorWordRange.end.character);
        editor.selection = newSe;
        commands.executeCommand("editor.action.clipboardCutAction");
    });

@alefragnani
Copy link
Author

No problem @alexandrudima 👍

I followed @jrieken suggestion and since then, I'm using https://github.com/xavi-/node-copy-paste, instead of the clipboard commands.

Thanks

SebastianZaha added a commit to SebastianZaha/vscode-emacs-friendly that referenced this issue Jan 14, 2017
Addressing hiro-sun#4 and hiro-sun#38

Removed the kill ring implementation (which was not on parity with emacs anyway). The cut/paste/copy commands now only deal with the system clipboard, no separate kill ring.

Using the copy-paste module for handling the clipboard, as recommended in multiple issues on vscode repo (microsoft/vscode#6994 and various others).
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants