mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
Make moving todo commits more robust
This commit is contained in:
@ -92,3 +92,24 @@ func MuiltiGroupBy[T any, K comparable](slice []T, f func(T) []K) map[K][]T {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Returns a new slice with the element at index 'from' moved to index 'to'.
|
||||
// Does not mutate original slice.
|
||||
func MoveElement[T any](slice []T, from int, to int) []T {
|
||||
newSlice := make([]T, len(slice))
|
||||
copy(newSlice, slice)
|
||||
|
||||
if from == to {
|
||||
return newSlice
|
||||
}
|
||||
|
||||
if from < to {
|
||||
copy(newSlice[from:to+1], newSlice[from+1:to+1])
|
||||
} else {
|
||||
copy(newSlice[to+1:from+1], newSlice[to:from])
|
||||
}
|
||||
|
||||
newSlice[to] = slice[from]
|
||||
|
||||
return newSlice
|
||||
}
|
||||
|
Reference in New Issue
Block a user