- Migrates NIP-17 DM new message model to its own model and disable some of the generic behavior from new posts.

- Fixes a bug on edits showing a previous edit.
- Refactors user suggestions and lastword procedures
- Adds a DM inline reply from other parts of the app, like on notification.
- Hides Retweet button from DMs on Notifications
- Fixes colors for drafts in chats.
- Adds a nav function that computes the destination only after the user clicks on it and on a coroutine.
This commit is contained in:
Vitor Pamplona
2025-03-04 17:57:47 -05:00
parent 1a001e7bb3
commit 0580aef4a2
54 changed files with 1858 additions and 698 deletions

View File

@@ -22,6 +22,8 @@ package com.vitorpamplona.amethyst.commons.compose
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import kotlin.math.max
import kotlin.math.min
fun TextFieldValue.insertUrlAtCursor(url: String): TextFieldValue {
var toInsert = url.trim()
@@ -41,3 +43,54 @@ fun TextFieldValue.insertUrlAtCursor(url: String): TextFieldValue {
TextRange(endOfUrlIndex, endOfUrlIndex),
)
}
fun TextFieldValue.replaceCurrentWord(wordToInsert: String): TextFieldValue {
val lastWordStart = currentWordStartIdx()
val lastWordEnd = currentWordEndIdx()
val cursor = lastWordStart + wordToInsert.length
return TextFieldValue(
text.replaceRange(lastWordStart, lastWordEnd, wordToInsert),
TextRange(cursor, cursor),
)
}
fun TextFieldValue.currentWordStartIdx(): Int {
val previousNewLine = text.lastIndexOf('\n', selection.start - 1)
val previousSpace = text.lastIndexOf(' ', selection.start - 1)
return max(
previousNewLine,
previousSpace,
) + 1
}
fun TextFieldValue.currentWordEndIdx(): Int {
val nextNewLine = text.indexOf('\n', selection.end)
val nextSpace = text.indexOf(' ', selection.end)
if (nextSpace < 0 && nextNewLine < 0) return selection.end
if (nextSpace > 0 && nextNewLine > 0) {
return min(
nextNewLine,
nextSpace,
)
}
if (nextSpace > 0) {
return nextSpace
}
return nextNewLine
}
fun TextFieldValue.currentWord(): String {
if (selection.end != selection.start) return ""
val start = currentWordStartIdx()
val end = currentWordEndIdx()
return if (start < end) {
val word = text.substring(start, end)
word
} else {
""
}
}