Fix search inputs accepting formatted text (#6501)

* Fix Global and extension search input accepts formatted text #6495

* Code change as requested because of performance issue

* code changes as requested

* minor code changes
This commit is contained in:
Rajat 2022-01-26 23:37:26 -05:00 committed by GitHub
parent dea585e69b
commit 77a3acf5cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,12 +2,16 @@ package eu.kanade.tachiyomi.ui.base.controller
import android.app.Activity import android.app.Activity
import android.os.Bundle import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.text.style.StyleSpan
import android.view.Menu import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -52,6 +56,21 @@ abstract class SearchableNucleusController<VB : ViewBinding, P : BasePresenter<*
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() }) searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
searchView.maxWidth = Int.MAX_VALUE searchView.maxWidth = Int.MAX_VALUE
// Remove formatting from pasted text
val searchAutoComplete: SearchView.SearchAutoComplete = searchView.findViewById(
R.id.search_src_text
)
searchAutoComplete.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
override fun afterTextChanged(editable: Editable) {
editable.getSpans(0, editable.length, StyleSpan::class.java)
.forEach { editable.removeSpan(it) }
}
})
searchView.queryTextEvents() searchView.queryTextEvents()
.onEach { .onEach {
val newText = it.queryText.toString() val newText = it.queryText.toString()