Added ctrl+enter to commit in commit's msg field

This commit is contained in:
Abdelilah El Aissaoui 2021-12-04 06:46:22 +01:00
parent c5372e074a
commit 7436eb80cf

View File

@ -18,6 +18,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.isCtrlPressed
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.input.pointer.pointerMoveFilter
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@ -35,7 +39,7 @@ import org.eclipse.jgit.diff.DiffEntry
import app.theme.headerBackground import app.theme.headerBackground
import app.theme.headerText import app.theme.headerText
@OptIn(ExperimentalAnimationApi::class) @OptIn(ExperimentalAnimationApi::class, androidx.compose.ui.ExperimentalComposeUiApi::class)
@Composable @Composable
fun UncommitedChanges( fun UncommitedChanges(
gitManager: GitManager, gitManager: GitManager,
@ -125,12 +129,21 @@ fun UncommitedChanges(
TextField( TextField(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.weight(weight = 1f, fill = true), .weight(weight = 1f, fill = true)
.onPreviewKeyEvent {
if (it.isCtrlPressed && it.key == Key.Enter) {
gitManager.commit(commitMessage)
true
}
else
false
},
value = commitMessage, value = commitMessage,
onValueChange = { commitMessage = it }, onValueChange = { commitMessage = it },
label = { Text("Write your commit message here", fontSize = 14.sp) }, label = { Text("Write your commit message here", fontSize = 14.sp) },
colors = TextFieldDefaults.textFieldColors(backgroundColor = MaterialTheme.colors.background), colors = TextFieldDefaults.textFieldColors(backgroundColor = MaterialTheme.colors.background),
textStyle = TextStyle.Default.copy(fontSize = 14.sp) textStyle = TextStyle.Default.copy(fontSize = 14.sp),
) )
Button( Button(