[PATCH] histedit: make actions toggleables

Yu Feng rainwoodman at gmail.com
Fri May 10 13:15:31 EDT 2019


# HG changeset patch
# User feyu at google.com
# Date 1557508115 25200
#      Fri May 10 10:08:35 2019 -0700
# Node ID 23bc04dc2d149829133db571f6a922e95843c9f9
# Parent  458dc948aff9f1217718b7679f890fea510d54f7
histedit: make actions toggleables.

If the same action is applied twice, revert to pick.

For example, the current state
#0  pick   104:xxxxxxxxx   Collect progress

pressing e once
#0  edit   104:xxxxxxxxx   Collect progress

pressing e again toggles it back to pick.
Instead of keeping at e (behavior before this patch)
#0  pick   104:xxxxxxxxx   Collect progress

The rationale is that giving a response when a key is pressed
makes happy users. Toggling seems to be a reasonable response in
this scenario.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1111,7 +1111,10 @@ def changeaction(state, pos, action):
     """Change the action state on the given position to the new action"""
     rules = state['rules']
     assert 0 <= pos < len(rules)
-    rules[pos].action = action
+    if rules[pos].action != action:
+        rules[pos].action = action
+    else: # applying the same action twice reverts to the default
+        rules[pos].action = KEY_LIST[0]
 
 def cycleaction(state, pos, next=False):
     """Changes the action state the next or the previous action from


More information about the Mercurial-devel mailing list