mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Allow clearing the multiplayer server text field with the "Backspace" key (#7196)
This commit is contained in:
parent
378d8da4dd
commit
7481e5aa13
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user