Skip to content

Commit

Permalink
[features-] sysedit: modify cell only if editor changes value (#2656)
Browse files Browse the repository at this point in the history
* [features- input-] leave cell unmodified when sysedit does

* [features-] sysedit-selected: only modify cells that editor changed
---------

Co-authored-by: Saul Pwanson <[email protected]>
  • Loading branch information
midichef and saulpw authored Jan 13, 2025
1 parent f5a4a18 commit 533fd2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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(cd); 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')

0 comments on commit 533fd2d

Please sign in to comment.