• Jonas Bernoulli's avatar
    Support one-section magit-selections · 115041d4
    Jonas Bernoulli authored
    For a long time Magit supported selecting two or more sibling sections
    using the region and then acting on that selection instead of only on
    the current section.  Single-section selections were not supported and
    a region that did not span multiple siblings was not visualized as a
    selection, instead the underlying region was visualized as it is in
    non-magit buffers.
    
    The change users will notice first is that when they press C-SPC to
    set the beginning of the region/magit-selection on a section heading,
    then the magit-selection is visualized.  Previously not even the
    region was shown after just pressing C-SPC, because the mark and the
    point were identical, so there was no non-empty region to visualize.
    
    For the time being most commands continue to behave exactly as before
    when there is a one-section selection: the act on the current section
    instead.  While a one-section selection is a selection that contains
    nothing but the current section, this difference between the current
    section and a set consisting of only the current section is still
    relevant.  It affects whether and how commands ask for confirmation
    and/or offer the user to act on something else instead.
    
    The reason I decided against supporting one-section selections in the
    past is that it is a bit unfortunate to visualize the selection and
    then the invoked command does not actually use it.  But this is no
    different from a multi-section selection being visualized and then
    invoking a command that isn't magit-selection aware at all.  Or from
    having the region visualized in any Emacs buffer and then invoking any
    command that doesn't behave differently when the region is active.
    
    Beginning with this commit only a handful of commands begin using a
    one-section selection.  Most importantly, and this is what motivated
    this change, it is now possible to use `magit-branch-spinoff' after
    selecting just HEAD to create a new branch rewinding the previously
    current branch by a single commit.  Previously it was only possible
    to rewind it to its upstream or to rewind it by at least two commits.
    
    The other commands that respect one-section selections are:
    - magit-am-apply-patches
    - magit-cherry-apply
    - magit-cherry-pick
    - magit-revert
    - magit-revert-no-commit
    - magit-stash-drop
    - magit-tag-delete
    
    The recently added commands `magit-previous-line' and
    `magit-next-line' now forgo moving on the first shift-selection move
    when point is on a section heading, not just when inside a hunk body.
    
    Closes #2920.
    Closes #3026.
    115041d4
magit-stash.el 19.6 KB