<commit_before>import vx

from collections import defaultdict

_changes = defaultdict(list)

def register_change(s):
    r, c = vx.window.focused.cursor
    change_list = _changes[vx.window.focused]
    change_list.append({'string': s, 'row': r, 'col': c, 'type': 'addition'})

def register_removal(s, r=None, c=None, hold=False):
    if r is None or c is None:
        r, c = vx.window.focused.cursor
    change_list = _changes[vx.window.focused]
    change_list.append({'string': s, 'row': r, 'col': c, 'type': 'removal', 'hold': hold})

@vx.expose
def _undo():
    change_list = _changes[vx.window.focused]
    if len(change_list) > 0:
        change = change_list.pop()
        vx.window.focused.cursor = (change['row'], change['col'])
        if change['type'] == 'removal' and change['hold']:
            r, c = vx.window.focused.cursor
        if change['type'] == 'addition':
            vx.backspace(track=False)
        elif change['type'] == 'removal':
            vx.add_string(change['string'], track=False)<commit_msg>Fix bug in undo<commit_after>import vx

from collections import defaultdict

_changes = defaultdict(list)

def register_change(s):
    r, c = vx.window.focused.cursor
    change_list = _changes[vx.window.focused]
    change_list.append({'string': s, 'row': r, 'col': c, 'type': 'addition'})

def register_removal(s, r=None, c=None, hold=False):
    if r is None or c is None:
        r, c = vx.window.focused.cursor
    change_list = _changes[vx.window.focused]
    change_list.append({'string': s, 'row': r, 'col': c, 'type': 'removal', 'hold': hold})

@vx.expose
def _undo():
    change_list = _changes[vx.window.focused]
    if len(change_list) > 0:
        change = change_list.pop()
        vx.window.focused.cursor = (change['row'], change['col'])
        if change['type'] == 'removal' and change['hold']:
            r, c = vx.window.focused.cursor
        if change['type'] == 'addition':
            for _ in range(len(change['string'])):
                vx.backspace(track=False)
        elif change['type'] == 'removal':
            vx.add_string(change['string'], track=False)
{'fraction_non_alphanumeric': 0.1636020744931636, 'fraction_numerical': 0.000942951438000943, 'mean_word_length': 3.244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7667681', 'n_tokens_mistral': 740, 'n_tokens_neox': 702, 'n_words': 167}