desktop: edit previous message with Up arrow (#2841)

This commit is contained in:
Stanislav Dmitrenko
2023-08-03 12:32:01 +03:00
committed by GitHub
parent 105a6afb4b
commit 760282cdfd
6 changed files with 23 additions and 2 deletions

View File

@@ -48,6 +48,7 @@ actual fun PlatformTextField(
showDeleteTextButton: MutableState<Boolean>,
userIsObserver: Boolean,
onMessageChange: (String) -> Unit,
onUpArrow: () -> Unit,
onDone: () -> Unit,
) {
val cs = composeState.value

View File

@@ -12,5 +12,6 @@ expect fun PlatformTextField(
showDeleteTextButton: MutableState<Boolean>,
userIsObserver: Boolean,
onMessageChange: (String) -> Unit,
onUpArrow: () -> Unit,
onDone: () -> Unit,
)

View File

@@ -93,6 +93,7 @@ fun TerminalLayout(
sendMessage = { sendCommand() },
sendLiveMessage = null,
updateLiveMessage = null,
editPrevMessage = {},
onMessageChange = ::onMessageChange,
textStyle = textStyle
)

View File

@@ -556,6 +556,14 @@ fun ComposeView(
}
}
fun editPrevMessage() {
if (composeState.value.contextItem != ComposeContextItem.NoContextItem || composeState.value.preview != ComposePreview.NoPreview) return
val lastEditable = chatModel.chatItems.findLast { it.meta.editable }
if (lastEditable != null) {
composeState.value = ComposeState(editingItem = lastEditable, useLinkPreviews = useLinkPreviews)
}
}
@Composable
fun previewView() {
when (val preview = composeState.value.preview) {
@@ -754,6 +762,7 @@ fun ComposeView(
composeState.value = composeState.value.copy(liveMessage = null)
chatModel.removeLiveDummy()
},
editPrevMessage = ::editPrevMessage,
onMessageChange = ::onMessageChange,
textStyle = textStyle
)

View File

@@ -48,6 +48,7 @@ fun SendMsgView(
sendLiveMessage: (suspend () -> Unit)? = null,
updateLiveMessage: (suspend () -> Unit)? = null,
cancelLiveMessage: (() -> Unit)? = null,
editPrevMessage: () -> Unit,
onMessageChange: (String) -> Unit,
textStyle: MutableState<TextStyle>
) {
@@ -67,7 +68,7 @@ fun SendMsgView(
val showVoiceButton = cs.message.isEmpty() && showVoiceRecordIcon && !composeState.value.editing &&
cs.liveMessage == null && (cs.preview is ComposePreview.NoPreview || recState.value is RecordingState.Started)
val showDeleteTextButton = rememberSaveable { mutableStateOf(false) }
PlatformTextField(composeState, textStyle, showDeleteTextButton, userIsObserver, onMessageChange) {
PlatformTextField(composeState, textStyle, showDeleteTextButton, userIsObserver, onMessageChange, editPrevMessage) {
sendMessage(null)
}
// Disable clicks on text field
@@ -593,6 +594,7 @@ fun PreviewSendMsgView() {
allowVoiceToContact = {},
timedMessageAllowed = false,
sendMessage = {},
editPrevMessage = {},
onMessageChange = { _ -> },
textStyle = textStyle
)
@@ -623,6 +625,7 @@ fun PreviewSendMsgViewEditing() {
allowVoiceToContact = {},
timedMessageAllowed = false,
sendMessage = {},
editPrevMessage = {},
onMessageChange = { _ -> },
textStyle = textStyle
)
@@ -653,6 +656,7 @@ fun PreviewSendMsgViewInProgress() {
allowVoiceToContact = {},
timedMessageAllowed = false,
sendMessage = {},
editPrevMessage = {},
onMessageChange = { _ -> },
textStyle = textStyle
)

View File

@@ -37,6 +37,7 @@ actual fun PlatformTextField(
showDeleteTextButton: MutableState<Boolean>,
userIsObserver: Boolean,
onMessageChange: (String) -> Unit,
onUpArrow: () -> Unit,
onDone: () -> Unit,
) {
val cs = composeState.value
@@ -83,7 +84,11 @@ actual fun PlatformTextField(
onDone()
}
true
} else false
} else if (it.key == Key.DirectionUp && it.type == KeyEventType.KeyDown && cs.message.isEmpty()) {
onUpArrow()
true
}
else false
},
cursorBrush = SolidColor(MaterialTheme.colors.secondary),
decorationBox = { innerTextField ->