Allow clearing the multiplayer server text field with the "Backspace" key (#7196)

This commit is contained in:
Timo T 2022-06-18 20:48:59 +02:00 committed by GitHub
parent 378d8da4dd
commit 7481e5aa13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,29 +238,15 @@ private fun fixTextFieldUrlOnType(TextField: TextField) {
var text: String = TextField.text
var cursor: Int = minOf(TextField.cursorPosition, text.length)
// if text is 'http:' or 'https:' auto append '//'
if (Regex("^https?:$").containsMatchIn(text)) {
TextField.appendText("//")
return
}
val textBeforeCursor: String = text.substring(0, cursor)
// replace multiple slash with a single one
val multipleSlashes = Regex("/{2,}")
// replace multiple slash with a single one, except when it's a ://
val multipleSlashes = Regex("(?<!:)/{2,}")
text = multipleSlashes.replace(text, "/")
// calculate updated cursor
cursor = multipleSlashes.replace(textBeforeCursor, "/").length
// operations above makes 'https://' -> 'https:/'
// fix that if available and update cursor
val i: Int = text.indexOf(":/")
if (i > -1) {
text = text.replaceRange(i..i + 1, "://")
if (cursor > i + 1) ++cursor
}
// update TextField
if (text != TextField.text) {
TextField.text = text