From 5c56bc7015ec635245d6270287508851276a040f Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 16 Mar 2024 17:09:58 +0100 Subject: [PATCH] Set mode to none when calling SetSelectionRangeAndMode with empty non-sticky range So far, the only situation where we called SetSelectionRangeAndMode was one where the range could only get larger (in startInteractiveRebaseWithEdit, in which case update-ref todos can be inserted by the rebase). However, in the last commit we introduced a new call site where the range can get smaller, including being reduced to a single item. Since this is indistinguishable from a single selection, set the mode to none in this case; without this, hitting escape would seemingly do nothing because it collapses the empty range selection. --- pkg/gui/context/traits/list_cursor.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/gui/context/traits/list_cursor.go b/pkg/gui/context/traits/list_cursor.go index 3b4ab1c3d..31f3de7a4 100644 --- a/pkg/gui/context/traits/list_cursor.go +++ b/pkg/gui/context/traits/list_cursor.go @@ -65,7 +65,11 @@ func (self *ListCursor) SetSelection(value int) { func (self *ListCursor) SetSelectionRangeAndMode(selectedIdx, rangeStartIdx int, mode RangeSelectMode) { self.selectedIdx = self.clampValue(selectedIdx) self.rangeStartIdx = self.clampValue(rangeStartIdx) - self.rangeSelectMode = mode + if mode == RangeSelectModeNonSticky && selectedIdx == rangeStartIdx { + self.rangeSelectMode = RangeSelectModeNone + } else { + self.rangeSelectMode = mode + } } // Returns the selectedIdx, the rangeStartIdx, and the mode of the current selection.