Skip to content

Commit

Permalink
fixed redo-locking bug in switch mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pier-bezuhoff committed Jan 24, 2024
1 parent 397853c commit 5ce044d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions composeApp/src/commonMain/kotlin/ui/EditClusterViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class EditClusterViewModel(
circles.clear()
circles.addAll(previousState.circles)
parts.addAll(previousState.parts)
switchSelectionMode(previousState.selectionMode)
switchSelectionMode(previousState.selectionMode, noAlteringShortcuts = true)
selection.addAll(previousState.selection)
redoCommands.addFirst(previousCommand)
redoHistory.addFirst(previousState)
Expand All @@ -118,7 +118,7 @@ class EditClusterViewModel(
circles.clear()
circles.addAll(nextState.circles)
parts.addAll(nextState.parts)
switchSelectionMode(nextState.selectionMode)
switchSelectionMode(nextState.selectionMode, noAlteringShortcuts = true)
selection.addAll(nextState.selection)
commands.addLast(nextCommand)
history.addLast(nextState)
Expand Down Expand Up @@ -210,21 +210,23 @@ class EditClusterViewModel(
}
}

fun switchSelectionMode(newMode: SelectionMode) {
fun switchSelectionMode(newMode: SelectionMode, noAlteringShortcuts: Boolean = false) {
if (selection.size > 1 && newMode == SelectionMode.Drag)
selection.clear()
if (selectionMode.value == SelectionMode.Multiselect && newMode == SelectionMode.Multiselect) {
if (selection.isEmpty())
selection.addAll(circles.indices)
else
selection.clear()
} else if (selectionMode.value == SelectionMode.SelectRegion && newMode == SelectionMode.SelectRegion) {
} else if (selectionMode.value == SelectionMode.SelectRegion && newMode == SelectionMode.SelectRegion &&
!noAlteringShortcuts
) {
if (parts.isEmpty()) {
// recordCommand(Command.SELECT_PART)
recordCommand(Command.SELECT_PART)
// select interlacing, todo: proper 2^n -> even # of 1's -> {0101001} -> parts
parts.add(Cluster.Part(emptySet(), circles.indices.toSet()))
} else {
// recordCommand(Command.SELECT_PART)
recordCommand(Command.SELECT_PART)
parts.clear()
}
}
Expand Down

0 comments on commit 5ce044d

Please sign in to comment.