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

[features-] sysedit: modify cell only if editor changes value #2656

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions visidata/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ def handle_key(self, ch:str, scr) -> bool:
v += c
elif ch == '^O':
edit_v = vd.launchExternalEditor(v)
if self.value == '' and edit_v == '':
# if a cell has a value of None, keep it when the editor exits with no change
if self.value == edit_v:
# leave cell unmodified when the editor exits with no change
raise EscapeException(ch)
else:
self.value = edit_v
Expand Down
17 changes: 13 additions & 4 deletions visidata/features/sysedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ def syseditCells_async(sheet, cols, rows, filetype=None):
tempcol = tempvs.colsByName.get(col.name)
if not tempcol: # column not in edited version
continue
col.setValuesTyped(rows, *[tempcol.getTypedValue(r) for r in tempvs.rows])


TableSheet.addCommand('^O', 'sysedit-cell', 'cursorCol.setValues([cursorRow], vd.launchExternalEditor(cursorDisplay))', 'edit current cell in external $EDITOR')
# only assign values that were changed by the editor
edited_rows = []
edited_vals = []
for r, r_edited in zip(rows, tempvs.rows):
v = tempcol.getDisplayValue(r_edited)
if col.getDisplayValue(r) != v:
edited_rows.append(r)
edited_vals.append(v)
if edited_rows:
col.setValuesTyped(edited_rows, *edited_vals)


TableSheet.addCommand('^O', 'sysedit-cell', 'cd = cursorDisplay; e = vd.launchExternalEditor(cursorDisplay); cursorCol.setValues([cursorRow], e) if e != cd else None', 'edit current cell in external $EDITOR')
Sheet.addCommand('g^O', 'sysedit-selected', 'syseditCells(visibleCols, onlySelectedRows)', 'edit rows in $EDITOR')
Loading