diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/extensions/ModifierExtensions.kt b/src/main/kotlin/com/jetpackduba/gitnuro/extensions/ModifierExtensions.kt index c106383..b8dde1d 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/extensions/ModifierExtensions.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/extensions/ModifierExtensions.kt @@ -1,7 +1,11 @@ package com.jetpackduba.gitnuro.extensions -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable +import androidx.compose.foundation.* +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.interaction.collectIsHoveredAsState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.awt.awtEventOrNull @@ -38,9 +42,11 @@ fun Modifier.handOnHover(): Modifier { // TODO Try to restore hover that was shown with clickable modifier @OptIn(ExperimentalComposeUiApi::class) -fun Modifier.fastClickable(onClick: () -> Unit) = +@Composable +fun Modifier.fastClickable(key: Any = Unit, onClick: () -> Unit) = this.handOnHover() - .pointerInput(Unit) { + .hoverBackground() + .pointerInput(key) { while (true) { val lastMouseEvent = awaitPointerEventScope { awaitFirstDownEvent() } val mouseEvent = lastMouseEvent.awtEventOrNull @@ -51,4 +57,12 @@ fun Modifier.fastClickable(onClick: () -> Unit) = } } } - } \ No newline at end of file + } + +@Composable +private fun Modifier.hoverBackground(): Modifier { + val hoverInteraction = remember { MutableInteractionSource() } + + return this.hoverable(hoverInteraction) + .indication(hoverInteraction, LocalIndication.current) +} diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt index 4e1cdb4..9f0cd3a 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/diff/Diff.kt @@ -861,7 +861,7 @@ fun DiffLineText(line: Line, diffEntryType: DiffEntryType, onActionTriggered: () contentDescription = null, tint = Color.White, modifier = Modifier - .fastClickable { onActionTriggered() } + .fastClickable(line) { onActionTriggered() } .size(14.dp) .clip(RoundedCornerShape(2.dp)) .background(color), diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt index 157f794..f21ee58 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt @@ -619,7 +619,7 @@ fun UncommitedChangesLine( modifier = Modifier .height(40.dp) .fillMaxWidth() - .fastClickable { onUncommitedChangesSelected() } + .handMouseClickable { onUncommitedChangesSelected() } .padding(start = graphWidth) .backgroundIf(isSelected, MaterialTheme.colors.backgroundSelected) .padding(DIVIDER_WIDTH.dp), @@ -742,7 +742,7 @@ fun CommitLine( ) { Box( modifier = Modifier - .fastClickable { onRevCommitSelected() } + .fastClickable(graphNode) { onRevCommitSelected() } .padding(start = graphWidth) .height(LINE_HEIGHT.dp) .backgroundIf(isSelected, MaterialTheme.colors.backgroundSelected)