MangaPresenter: Fix incorrect range selection (#7709)

(cherry picked from commit f7b11f2ce92627cbea713c200ed23ec596499d4f)
This commit is contained in:
Ivan Iskandar 2022-08-09 20:11:12 +07:00 committed by Jobobby04
parent 2ca853a302
commit f99635bb3a

View File

@ -1236,13 +1236,13 @@ class MangaPresenter(
fromLongPress: Boolean = false, fromLongPress: Boolean = false,
) { ) {
updateSuccessState { successState -> updateSuccessState { successState ->
val modifiedIndex = successState.chapters.indexOfFirst { it.chapter.id == item.chapter.id } val newChapters = successState.processedChapters.toMutableList().apply {
if (modifiedIndex < 0) return@updateSuccessState successState val modifiedIndex = successState.processedChapters.indexOfFirst { it == item }
if (modifiedIndex < 0) return@apply
val oldItem = successState.chapters[modifiedIndex] val oldItem = get(modifiedIndex)
if ((oldItem.selected && selected) || (!oldItem.selected && !selected)) return@updateSuccessState successState if ((oldItem.selected && selected) || (!oldItem.selected && !selected)) return@apply
val newChapters = successState.chapters.toMutableList().apply {
val firstSelection = none { it.selected } val firstSelection = none { it.selected }
var newItem = removeAt(modifiedIndex) var newItem = removeAt(modifiedIndex)
add(modifiedIndex, newItem.copy(selected = selected)) add(modifiedIndex, newItem.copy(selected = selected))