From 2a5fe2c3828a1346719b096ae0122444960fcc85 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Sun, 24 Apr 2016 14:56:22 -0400 Subject: [PATCH] Feature/yanking (#138) * Support yanking * Remove unneeded code from yank spec --- lib/ex.coffee | 5 +++++ spec/ex-commands-spec.coffee | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/ex.coffee b/lib/ex.coffee index 5173495..41aaed6 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -354,6 +354,11 @@ class Ex editor.buffer.setTextInRange(range, '') + yank: ({ range }) -> + range = [[range[0], 0], [range[1] + 1, 0]] + txt = atom.workspace.getActiveTextEditor().getTextInBufferRange(range) + atom.clipboard.write(txt); + set: ({ range, args }) -> args = args.trim() if args == "" diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index f350e1d..2fa05c5 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -590,6 +590,21 @@ describe "the commands", -> submitNormalModeInputText(':%substitute/abc/ghi/ig') expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi') + describe ":yank", -> + beforeEach -> + editor.setText('abc\ndef\nghi\njkl') + editor.setCursorBufferPosition([2, 0]) + + it "yanks the current line", -> + keydown(':') + submitNormalModeInputText('yank') + expect(atom.clipboard.read()).toEqual('ghi\n') + + it "yanks the lines in the given range", -> + keydown(':') + submitNormalModeInputText('1,2yank') + expect(atom.clipboard.read()).toEqual('abc\ndef\n') + describe "illegal delimiters", -> test = (delim) -> keydown(':')