Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #254 - SelectableLazyColumn multi selection bug #255

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions foundation/api/foundation.api
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public class org/jetbrains/jewel/foundation/lazy/tree/DefaultSelectableLazyColum
public fun <init> ()V
public fun handlePointerEventPress (Landroidx/compose/ui/input/pointer/PointerEvent;Lorg/jetbrains/jewel/foundation/lazy/SelectableColumnKeybindings;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Ljava/util/List;Ljava/lang/Object;)V
public fun onExtendSelectionToKey (Ljava/lang/Object;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;)V
public fun toggleKeySelection (Ljava/lang/Object;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;)V
public fun toggleKeySelection (Ljava/lang/Object;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;)V
}

public class org/jetbrains/jewel/foundation/lazy/tree/DefaultSelectableLazyColumnKeyActions : org/jetbrains/jewel/foundation/lazy/tree/KeyActions {
Expand Down Expand Up @@ -470,7 +470,7 @@ public final class org/jetbrains/jewel/foundation/lazy/tree/KeyActionsKt {
public abstract interface class org/jetbrains/jewel/foundation/lazy/tree/PointerEventActions {
public abstract fun handlePointerEventPress (Landroidx/compose/ui/input/pointer/PointerEvent;Lorg/jetbrains/jewel/foundation/lazy/SelectableColumnKeybindings;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;Ljava/util/List;Ljava/lang/Object;)V
public abstract fun onExtendSelectionToKey (Ljava/lang/Object;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;)V
public abstract fun toggleKeySelection (Ljava/lang/Object;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;)V
public abstract fun toggleKeySelection (Ljava/lang/Object;Ljava/util/List;Lorg/jetbrains/jewel/foundation/lazy/SelectableLazyListState;Lorg/jetbrains/jewel/foundation/lazy/SelectionMode;)V
}

public final class org/jetbrains/jewel/foundation/lazy/tree/Tree {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public interface PointerEventActions {
key: Any,
allKeys: List<SelectableLazyListKey>,
selectableLazyListState: SelectableLazyListState,
selectionMode: SelectionMode,
)

public fun onExtendSelectionToKey(
Expand Down Expand Up @@ -78,7 +79,7 @@ public open class DefaultSelectableLazyColumnEventAction : PointerEventActions {
}

pointerEvent.keyboardModifiers.isMultiSelectionKeyPressed -> {
toggleKeySelection(key, allKeys, selectableLazyListState)
toggleKeySelection(key, allKeys, selectableLazyListState, selectionMode)
}

else -> {
Expand All @@ -93,11 +94,18 @@ public open class DefaultSelectableLazyColumnEventAction : PointerEventActions {
key: Any,
allKeys: List<SelectableLazyListKey>,
selectableLazyListState: SelectableLazyListState,
selectionMode: SelectionMode,
) {
selectableLazyListState.selectedKeys = if (selectableLazyListState.selectedKeys.contains(key)) {
selectableLazyListState.selectedKeys - key
} else {
selectableLazyListState.selectedKeys + key
when (selectionMode) {
SelectionMode.None -> return
SelectionMode.Single -> selectableLazyListState.selectedKeys = setOf(key)
SelectionMode.Multiple -> {
if (key in selectableLazyListState.selectedKeys) {
selectableLazyListState.selectedKeys -= key
} else {
selectableLazyListState.selectedKeys += key
}
}
}
selectableLazyListState.lastActiveItemIndex = allKeys.indexOfFirst { it == key }
}
Expand Down Expand Up @@ -161,8 +169,9 @@ public class DefaultTreeViewPointerEventAction(

pointerEvent.keyboardModifiers.isMultiSelectionKeyPressed -> {
selectableLazyListState.lastKeyEventUsedMouse = false
super.toggleKeySelection(key, allKeys, selectableLazyListState)
super.toggleKeySelection(key, allKeys, selectableLazyListState, selectionMode)
}

else -> {
selectableLazyListState.selectedKeys = setOf(key)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn
import org.jetbrains.jewel.foundation.lazy.SelectionMode
import org.jetbrains.jewel.foundation.lazy.rememberSelectableLazyListState
import org.jetbrains.jewel.foundation.lazy.tree.buildTree
import org.jetbrains.jewel.foundation.theme.JewelTheme
Expand Down Expand Up @@ -70,6 +71,7 @@ fun SelectableLazyColumnSample() {
modifier = Modifier.size(200.dp, 200.dp),
) {
SelectableLazyColumn(
selectionMode = SelectionMode.Multiple,
modifier = Modifier.focusable(interactionSource = interactionSource),
state = state,
content = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ private fun LinkImpl(
.clickable(
onClick = {
linkState = linkState.copy(visited = true)
println("clicked Link")
onClick()
},
enabled = enabled,
Expand Down
Loading