Expand description
MG.18d: putting the cursor back on the user’s work after a rebuild.
Every magit mutation ends in a refresh that replaces the whole buffer, so the row the cursor was on means nothing afterwards — files move between sections, counts change, the staged hunk is gone. At file granularity losing your place was tolerable. At hunk granularity it defeats the feature: staging four of a file’s six hunks means finding your place four times.
So the cursor is restored by identity, not by row: the entry (or file header) the work belonged to, plus the ordinal of the hunk within it. Staging hunk k removes it, so ordinal k now names the next remaining hunk — the restore rule and magit’s behaviour fall out of the same arithmetic. Clamping to the last hunk covers staging the final one.
Pure functions over the rebuilt text, resolved BEFORE it is applied: the refresh already holds the string it is about to write, so no second read of the buffer is needed and there is no window in which the text could change under the lookup.
Structs§
- Cursor
Request - A resolved cursor placement, on its way back to the editor thread.
- Hunk
Restore - The work a mutation interrupted: which file, and which hunk of it.
- Hunk
Site - The same fact in view-independent terms, as the shared staging path can state it: which file, which side of the index, which hunk.
Enums§
- Restore
Anchor - Where the work lived, in whichever buffer shape the view uses.
Type Aliases§
- Cursor
BusHandle - Service alias — register and look up through this exact type
(
feedback_servicesregistry_arc_typeid).