From 59344b6a9aeddd249923a1c07abd18d6f4db92d6 Mon Sep 17 00:00:00 2001 From: midichef <67946319+midichef@users.noreply.github.com> Date: Sat, 9 Nov 2024 04:02:32 -0800 Subject: [PATCH] [aggr-] allow undo for aggregate-col/cols --- visidata/aggregators.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/visidata/aggregators.py b/visidata/aggregators.py index a468d93e0..3b424a5ae 100644 --- a/visidata/aggregators.py +++ b/visidata/aggregators.py @@ -3,6 +3,7 @@ import functools import collections import statistics +from copy import copy from visidata import Progress, Sheet, Column, ColumnsSheet, VisiData from visidata import vd, anytype, vlen, asyncthread, wrapply, AttrDict, date, INPROGRESS @@ -205,10 +206,9 @@ def addAggregators(sheet, cols, aggrnames): for aggrname in aggrnames: aggrs = vd.aggregators.get(aggrname) aggrs = aggrs if isinstance(aggrs, list) else [aggrs] - for aggr in aggrs: - for c in cols: - if not hasattr(c, 'aggregators'): - c.aggregators = [] + for c in cols: + vd.addUndo(setattr, c, 'aggregators', copy(c.aggregators)) + for aggr in aggrs: if aggr and aggr not in c.aggregators: c.aggregators += [aggr]