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

[sheets-] recreate sort columns for copied sheet #2192

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions visidata/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,21 @@ def __copy__(self):
ret.rows = UNLOADED

ret.columns = []
for c in self.keyCols:
ret.addColumn(copy(c))

ret.setKeys(ret.columns)

col_mapping = {}
for c in self.columns:
if c not in self.keyCols:
ret.addColumn(copy(c))
new_col = copy(c)
col_mapping[c] = new_col
ret.addColumn(new_col)

ret.setKeys([col_mapping[c] for c in self.columns if c.keycol])

ret._ordering = []
for sortcol,reverse in self._ordering:
if isinstance(sortcol, str):
ret._ordering.append((sortcol,reverse))
else:
ret._ordering.append((col_mapping[sortcol],reverse))

ret.topRowIndex = ret.cursorRowIndex = 0
return ret
Expand Down Expand Up @@ -1098,7 +1105,7 @@ def _async_deepcopy(newlist, oldlist):

BaseSheet.init('pane', lambda: 1)

Sheet.init('_ordering', list, copy=True) # (col:Column, reverse:bool)
Sheet.init('_ordering', list, copy=False) # (col:Column, reverse:bool)


BaseSheet.addCommand('^R', 'reload-sheet', 'preloadHook(); reload()', 'Reload current sheet')
Expand Down
Loading