From 72ab0fd52eaa195163bb5cf244ce127e847d7a13 Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:14:01 -0800 Subject: [PATCH 1/3] [features- input-] leave cell unmodified when sysedit does --- visidata/_input.py | 4 ++-- visidata/features/sysedit.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/visidata/_input.py b/visidata/_input.py index d365856eb..8a6031a5e 100644 --- a/visidata/_input.py +++ b/visidata/_input.py @@ -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 diff --git a/visidata/features/sysedit.py b/visidata/features/sysedit.py index 90da2b04c..c3de57f35 100644 --- a/visidata/features/sysedit.py +++ b/visidata/features/sysedit.py @@ -40,5 +40,5 @@ def syseditCells_async(sheet, cols, rows, filetype=None): 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') +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') From 483fbe7990aad8d2416b440b412a0f9ba2aa688a Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Sat, 28 Dec 2024 13:19:59 -0800 Subject: [PATCH 2/3] [features-] sysedit-selected: only modify cells that editor changed --- visidata/features/sysedit.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/visidata/features/sysedit.py b/visidata/features/sysedit.py index c3de57f35..245ac365a 100644 --- a/visidata/features/sysedit.py +++ b/visidata/features/sysedit.py @@ -37,7 +37,16 @@ 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]) + # 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') From 7988e020cc3c1dfd370df1beee1f50d4c63140ff Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Sat, 11 Jan 2025 17:28:09 -0800 Subject: [PATCH 3/3] Use saved variable instead of cursorDisplay May as well just use the local that was created. --- visidata/features/sysedit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/visidata/features/sysedit.py b/visidata/features/sysedit.py index 245ac365a..89a434871 100644 --- a/visidata/features/sysedit.py +++ b/visidata/features/sysedit.py @@ -49,5 +49,5 @@ def syseditCells_async(sheet, cols, rows, filetype=None): 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') +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')