# HG changeset patch # User Anton Shestakov # Date 2024-05-07 11:15:41 # Node ID 6ec4c745c598708dec5370b91762b221ca2f6268 # Parent 99072b02138f0510d55476bd1728015a31a2f686 chistedit: change action for the correct item We have an experimental config histedit.later-commits-first from c820866c52f9, and when it's true, the order of commits in histedit UI is reversed, both in text mode and in curses mode. But before this patch key presses in curses mode would change histedit actions in the same old order, i.e. trying to edit the latest commit (which would be first now) would put "edit" action on the last commit in the list. This wasn't a cosmetic issue, histedit would actually proceed to edit the first commit in the list. Let's map rules to display items (hopefully now correctly). diff --git a/hgext/histedit.py b/hgext/histedit.py --- a/hgext/histedit.py +++ b/hgext/histedit.py @@ -1581,14 +1581,16 @@ pgup/K: move patch up, pgdn/J: move patc def change_action(self, pos, action): """Change the action state on the given position to the new action""" - assert 0 <= pos < len(self.rules) - self.rules[pos].action = action + rule_pos = self.display_pos_to_rule_pos(pos) + assert 0 <= rule_pos < len(self.rules) + self.rules[rule_pos].action = action def cycle_action(self, pos, next=False): """Changes the action state the next or the previous action from the action list""" - assert 0 <= pos < len(self.rules) - current = self.rules[pos].action + rule_pos = self.display_pos_to_rule_pos(pos) + assert 0 <= rule_pos < len(self.rules) + current = self.rules[rule_pos].action assert current in KEY_LIST @@ -1597,6 +1599,8 @@ pgup/K: move patch up, pgdn/J: move patc index += 1 else: index -= 1 + # using pos instead of rule_pos because change_action() also calls + # display_pos_to_rule_pos() self.change_action(pos, KEY_LIST[index % len(KEY_LIST)]) def change_view(self, delta, unit):