diff --git a/tests/golden/issue1377.tsv b/tests/golden/issue1377.tsv new file mode 100644 index 000000000..3f3d19240 --- /dev/null +++ b/tests/golden/issue1377.tsv @@ -0,0 +1,4 @@ +A customer name sales rep sku category quantity unit price ext price date +680916 Mueller and Sons Loring Predovic GP-14407 Belt 19 88.49 1681.31 2015-11-17 05:58:34 +680916 Mueller and Sons Loring Predovic FI-01804 Shirt 3 78.07 234.21 2016-02-13 04:04:11 +530925 Purdy and Sons Teagan O'Keefe EO-54210 Shirt 19 30.21 573.99 2015-08-11 12:44:38 diff --git a/tests/golden/issue1377b.tsv b/tests/golden/issue1377b.tsv new file mode 100644 index 000000000..e5ca835e3 --- /dev/null +++ b/tests/golden/issue1377b.tsv @@ -0,0 +1,7 @@ +A customer name sales rep sku category quantity unit price ext price date +680916 Mueller and Sons Loring Predovic GP-14407 Belt 19 88.49 1681.31 2015-11-17 05:58:34 +680916 Mueller and Sons Loring Predovic GP-14407 Belt 19 88.49 1681.31 2015-11-17 05:58:34 +680916 Mueller and Sons Loring Predovic FI-01804 Shirt 3 78.07 234.21 2016-02-13 04:04:11 +530925 Purdy and Sons Teagan O'Keefe EO-54210 Shirt 19 30.21 573.99 2015-08-11 12:44:38 +680916 Mueller and Sons Loring Predovic FI-01804 Shirt 3 78.07 234.21 2016-02-13 04:04:11 +530925 Purdy and Sons Teagan O'Keefe EO-54210 Shirt 19 30.21 573.99 2015-08-11 12:44:38 diff --git a/tests/issue1377.vdj b/tests/issue1377.vdj new file mode 100644 index 000000000..d167a7542 --- /dev/null +++ b/tests/issue1377.vdj @@ -0,0 +1,9 @@ +#!vd -p +{"sheet": null, "col": null, "row": null, "longname": "open-file", "input": "sample_data/sample-sales-reps.xlsx", "keystrokes": "o", "comment": null} +{"sheet": "sample-sales-reps", "col": "", "row": "\u30adsample-salesv4", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open current row with sheet-specific dive"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "0", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "1", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "2", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "", "longname": "copy-selected", "input": "", "keystrokes": "gy", "comment": "yank (copy) selected rows to clipboard"} +{"col": "", "row": "", "longname": "open-new", "input": "", "keystrokes": "Shift+A", "comment": "Open new empty sheet"} +{"col": "", "row": "", "longname": "paste-after", "input": "", "keystrokes": "p", "comment": "paste clipboard rows after current row"} diff --git a/tests/issue1377b.vdj b/tests/issue1377b.vdj new file mode 100644 index 000000000..4e00bfecf --- /dev/null +++ b/tests/issue1377b.vdj @@ -0,0 +1,10 @@ +#!vd -p +{"sheet": null, "col": null, "row": null, "longname": "open-file", "input": "sample_data/sample-sales-reps.xlsx", "keystrokes": "o", "comment": null} +{"sheet": "sample-sales-reps", "col": "", "row": "\u30adsample-salesv4", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open current row with sheet-specific dive"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "0", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "1", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "2", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"} +{"sheet": "sample-sales-reps_sample-salesv4", "col": "", "row": "", "longname": "copy-selected", "input": "", "keystrokes": "gy", "comment": "yank (copy) selected rows to clipboard"} +{"col": "", "row": "", "longname": "open-new", "input": "", "keystrokes": "Shift+A", "comment": "Open new empty sheet"} +{"col": "", "row": "", "longname": "paste-after", "input": "", "keystrokes": "p", "comment": "paste clipboard rows after current row"} +{"col": "", "row": "1", "longname": "paste-before", "input": "", "keystrokes": "Shift+P", "comment": "paste clipboard rows before current row"} diff --git a/visidata/clipboard.py b/visidata/clipboard.py index 649eb0c9d..1cad22896 100644 --- a/visidata/clipboard.py +++ b/visidata/clipboard.py @@ -7,8 +7,8 @@ import functools import os -from visidata import VisiData, vd, asyncthread -from visidata import Sheet, Path +from visidata import VisiData, vd, asyncthread, SettableColumn +from visidata import Sheet, Path, Column if sys.platform == 'win32': syscopy_cmd_default = 'clip.exe' @@ -129,14 +129,33 @@ def delete_row(sheet, rowidx): sheet.setModified() return oldrow + @Sheet.api +@asyncthread def paste_after(sheet, rowidx): + 'Paste rows from *vd.cliprows* at *rowidx*.' if not vd.memory.cliprows: #1793 vd.warning('nothing to paste') return - to_paste = list(deepcopy(r) for r in reversed(vd.memory.cliprows)) - sheet.addRows(to_paste, index=rowidx) + for col in vd.memory.clipcols[sheet.nVisibleCols:]: + newcol = SettableColumn() + newcol.__setstate__(col.__getstate__()) + sheet.addColumn(newcol) + + addedRows = [] + + for extrow in vd.memory.cliprows: + if isinstance(extrow, Column): + newrow = copy(extrow) + else: + newrow = sheet.newRow() + for col, extcol in zip(sheet.visibleCols, vd.memory.clipcols): + col.setValue(newrow, extcol.getTypedValue(extrow)) + + addedRows.append(newrow) + + sheet.addRows(addedRows, index=rowidx) Sheet.addCommand('y', 'copy-row', 'copyRows([cursorRow])', 'yank (copy) current row to clipboard') diff --git a/visidata/modify.py b/visidata/modify.py index e58d87316..d1024b5ce 100644 --- a/visidata/modify.py +++ b/visidata/modify.py @@ -91,9 +91,9 @@ def addRows(sheet, rows, index=None, undo=True): 'Add *rows* after row at *index*.' addedRows = {} if index is None: index=len(sheet.rows) - for row in Progress(rows, gerund='adding'): + for i, row in enumerate(Progress(rows, gerund='adding')): addedRows[sheet.rowid(row)] = row - sheet.addRow(row, index=index+1) + sheet.addRow(row, index=index+i+1) if sheet.defer: sheet.rowAdded(row)