Skip to content

Commit

Permalink
[sheets-] record key-col toggle for replay as key-col-on/-off
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Dec 3, 2024
1 parent 37f0a0c commit f12e3f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 9 additions & 0 deletions visidata/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,12 @@ def keystr(sheet, row):
return sheet.rowname(row)

vd.optalias('color_refline', 'color_graph_refline') # color_refline was used in v3.1 by mistake

@deprecated('3.2', '[self.unsetKeys([c]) if c.keycol else self.setKeys([c]) for c in cols]')
@visidata.TableSheet.api
def toggleKeys(self, cols):
for col in cols:
if col.keycol:
self.unsetKeys([col])
else:
self.setKeys([col])
10 changes: 2 additions & 8 deletions visidata/sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,6 @@ def unsetKeys(self, cols):
for col in cols:
col.keycol = 0

def toggleKeys(self, cols):
for col in cols:
if col.keycol:
self.unsetKeys([col])
else:
self.setKeys([col])

def rowkey(self, row):
'Return tuple of the key for *row*.'
return tuple(c.getTypedValue(row) for c in self.keyCols)
Expand Down Expand Up @@ -1192,7 +1185,8 @@ def _async_deepcopy(newlist, oldlist):
BaseSheet.addCommand('^R', 'reload-sheet', 'preloadHook(); reload()', 'Reload current sheet')
Sheet.addCommand('', 'show-cursor', 'status(statusLine)', 'show cursor position and bounds of current sheet on status line')

Sheet.addCommand('!', 'key-col', 'toggleKeys([cursorCol])', 'toggle current column as a key column')
Sheet.addCommand('!', 'key-col', 'exec_longname("key-col-off") if cursorCol.keycol else exec_longname("key-col-on")', 'toggle current column as a key column', replay=False)
Sheet.addCommand('', 'key-col-on', 'setKeys([cursorCol])', 'set current column as a key column')
Sheet.addCommand('z!', 'key-col-off', 'unsetKeys([cursorCol])', 'unset current column as a key column')

Sheet.addCommand('e', 'edit-cell', 'cursorCol.setValues([cursorRow], editCell(cursorVisibleColIndex)) if not (cursorRow is None) else fail("no rows to edit")', 'edit contents of current cell')
Expand Down

0 comments on commit f12e3f1

Please sign in to comment.