From 7481e5aa139cbad25afa4bd2171698f279cb32a9 Mon Sep 17 00:00:00 2001 From: Timo T Date: Sat, 18 Jun 2022 20:48:59 +0200 Subject: [PATCH] Allow clearing the multiplayer server text field with the "Backspace" key (#7196) --- .../src/com/unciv/ui/options/MultiplayerTab.kt | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/core/src/com/unciv/ui/options/MultiplayerTab.kt b/core/src/com/unciv/ui/options/MultiplayerTab.kt index 4d72af1f59..55acf17b94 100644 --- a/core/src/com/unciv/ui/options/MultiplayerTab.kt +++ b/core/src/com/unciv/ui/options/MultiplayerTab.kt @@ -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("(? '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