When calculating post length, count all urls as being of the reserved character count, even if they're shorter. (#2404)
Addresses #2399
This commit is contained in:
parent
2017d0b13b
commit
bbd818084d
|
@ -716,7 +716,9 @@ class ComposeActivity :
|
||||||
val urlSpans = binding.composeEditField.urls
|
val urlSpans = binding.composeEditField.urls
|
||||||
if (urlSpans != null) {
|
if (urlSpans != null) {
|
||||||
for (span in urlSpans) {
|
for (span in urlSpans) {
|
||||||
offset += max(0, span.url.length - charactersReservedPerUrl)
|
// it's expected that this will be negative
|
||||||
|
// when the url length is less than the reserved character count
|
||||||
|
offset += (span.url.length - charactersReservedPerUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var length = binding.composeEditField.length() - offset
|
var length = binding.composeEditField.length() - offset
|
||||||
|
|
|
@ -242,12 +242,12 @@ class ComposeActivityTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun whenTextContainsMultipleUrls_onlyEllipsizedURLIsCounted() {
|
fun whenTextContainsShortUrls_allUrlsGetEllipsized() {
|
||||||
val shortUrl = "https://tusky.app"
|
val shortUrl = "https://tusky.app"
|
||||||
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
||||||
val additionalContent = " Check out this @image #search result: "
|
val additionalContent = " Check out this @image #search result: "
|
||||||
insertSomeTextInContent(shortUrl + additionalContent + url)
|
insertSomeTextInContent(shortUrl + additionalContent + url)
|
||||||
assertEquals(activity.calculateTextLength(), additionalContent.length + shortUrl.length + DEFAULT_MAXIMUM_URL_LENGTH)
|
assertEquals(activity.calculateTextLength(), additionalContent.length + (DEFAULT_MAXIMUM_URL_LENGTH * 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -271,7 +271,7 @@ class ComposeActivityTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun whenTextContainsMultipleUrls_onlyEllipsizedURLIsCounted_withCustomConfiguration() {
|
fun whenTextContainsShortUrls_allUrlsGetEllipsized_withCustomConfiguration() {
|
||||||
val shortUrl = "https://tusky.app"
|
val shortUrl = "https://tusky.app"
|
||||||
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
||||||
val additionalContent = " Check out this @image #search result: "
|
val additionalContent = " Check out this @image #search result: "
|
||||||
|
@ -280,7 +280,7 @@ class ComposeActivityTest {
|
||||||
setupActivity()
|
setupActivity()
|
||||||
shadowOf(getMainLooper()).idle()
|
shadowOf(getMainLooper()).idle()
|
||||||
insertSomeTextInContent(shortUrl + additionalContent + url)
|
insertSomeTextInContent(shortUrl + additionalContent + url)
|
||||||
assertEquals(activity.calculateTextLength(), additionalContent.length + shortUrl.length + customUrlLength)
|
assertEquals(activity.calculateTextLength(), additionalContent.length + (customUrlLength * 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue