mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-27 17:49:16 +03:00
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:
parent
dea585e69b
commit
77a3acf5cc
1 changed files with 19 additions and 0 deletions
|
@ -2,12 +2,16 @@ package eu.kanade.tachiyomi.ui.base.controller
|
|||
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.text.style.StyleSpan
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
@ -52,6 +56,21 @@ abstract class SearchableNucleusController<VB : ViewBinding, P : BasePresenter<*
|
|||
searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() })
|
||||
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()
|
||||
.onEach {
|
||||
val newText = it.queryText.toString()
|
||||
|
|
Loading…
Reference in a new issue