Skip to content

Commit

Permalink
Make range selections created with the mouse non-sticky
Browse files Browse the repository at this point in the history
I prefer this because I almost never use sticky range selections. Also, this
fixes the issue that just clicking a line in a diff (without dragging) already
creates a range selection. It still does, technically, but it's no longer a
problem because a non-sticky one-line range selection behaves the same as a
non-range selection.
  • Loading branch information
stefanhaller committed Jan 24, 2024
1 parent 9cd69e4 commit e72c759
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/gui/controllers/patch_explorer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (self *PatchExplorerController) HandleMouseDown() error {
}

func (self *PatchExplorerController) HandleMouseDrag() error {
self.context.GetState().SelectLine(self.context.GetViewTrait().SelectedLineIdx())
self.context.GetState().DragSelectLine(self.context.GetViewTrait().SelectedLineIdx())

return nil
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/gui/patch_exploring/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ func NewState(diff string, selectedLineIdx int, oldState *State, log *logrus.Ent
}

selectMode := LINE
rangeIsSticky := false
// if we have clicked from the outside to focus the main view we'll pass in a non-negative line index so that we can instantly select that line
if selectedLineIdx >= 0 {
selectMode = RANGE
rangeStartLineIdx = selectedLineIdx
rangeIsSticky = true
} else if oldState != nil {
// if we previously had a selectMode of RANGE, we want that to now be line again
if oldState.selectMode == HUNK {
Expand All @@ -70,7 +68,7 @@ func NewState(diff string, selectedLineIdx int, oldState *State, log *logrus.Ent
selectedLineIdx: selectedLineIdx,
selectMode: selectMode,
rangeStartLineIdx: rangeStartLineIdx,
rangeIsSticky: rangeIsSticky,
rangeIsSticky: false,
diff: diff,
}
}
Expand Down Expand Up @@ -150,7 +148,12 @@ func (s *State) SelectNewLineForRange(newSelectedLineIdx int) {
s.rangeStartLineIdx = newSelectedLineIdx

s.selectMode = RANGE
s.rangeIsSticky = true

s.selectLineWithoutRangeCheck(newSelectedLineIdx)
}

func (s *State) DragSelectLine(newSelectedLineIdx int) {
s.selectMode = RANGE

s.selectLineWithoutRangeCheck(newSelectedLineIdx)
}
Expand Down

0 comments on commit e72c759

Please sign in to comment.