For #25812 - Set the cursor at the end for search terms when switching to toolbar editMode.
This commit is contained in:
parent
9565b48b70
commit
d88d930b83
|
@ -12,6 +12,7 @@ import androidx.appcompat.content.res.AppCompatResources
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import mozilla.components.browser.state.search.SearchEngine
|
import mozilla.components.browser.state.search.SearchEngine
|
||||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||||
|
import mozilla.components.concept.toolbar.Toolbar
|
||||||
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
||||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||||
import mozilla.components.support.ktx.android.view.hideKeyboard
|
import mozilla.components.support.ktx.android.view.hideKeyboard
|
||||||
|
@ -135,7 +136,12 @@ class ToolbarView(
|
||||||
// we have the most up to date text
|
// we have the most up to date text
|
||||||
interactor.onTextChanged(view.url.toString())
|
interactor.onTextChanged(view.url.toString())
|
||||||
|
|
||||||
|
// If search terms are displayed, move the cursor to the end instead of selecting all text.
|
||||||
|
if (settings.showUnifiedSearchFeature && searchState.searchTerms.isNotBlank()) {
|
||||||
|
view.editMode(cursorPlacement = Toolbar.CursorPlacement.END)
|
||||||
|
} else {
|
||||||
view.editMode()
|
view.editMode()
|
||||||
|
}
|
||||||
isInitialized = true
|
isInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,14 @@ import io.mockk.MockKAnnotations
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.impl.annotations.MockK
|
import io.mockk.impl.annotations.MockK
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
|
import io.mockk.mockkObject
|
||||||
import io.mockk.spyk
|
import io.mockk.spyk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
import mozilla.components.browser.state.search.SearchEngine
|
import mozilla.components.browser.state.search.SearchEngine
|
||||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||||
import mozilla.components.browser.toolbar.edit.EditToolbar
|
import mozilla.components.browser.toolbar.edit.EditToolbar
|
||||||
import mozilla.components.concept.engine.Engine
|
import mozilla.components.concept.engine.Engine
|
||||||
|
import mozilla.components.concept.toolbar.Toolbar
|
||||||
import mozilla.components.support.test.robolectric.testContext
|
import mozilla.components.support.test.robolectric.testContext
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertFalse
|
import org.junit.Assert.assertFalse
|
||||||
|
@ -24,12 +26,13 @@ import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
import org.mozilla.fenix.FeatureFlags
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.components.metrics.MetricsUtils
|
import org.mozilla.fenix.components.metrics.MetricsUtils
|
||||||
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||||
import org.mozilla.fenix.search.SearchEngineSource
|
import org.mozilla.fenix.search.SearchEngineSource
|
||||||
import org.mozilla.fenix.search.SearchFragmentState
|
import org.mozilla.fenix.search.SearchFragmentState
|
||||||
import org.mozilla.fenix.utils.Settings
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
@RunWith(FenixRobolectricTestRunner::class)
|
@RunWith(FenixRobolectricTestRunner::class)
|
||||||
|
@ -71,6 +74,7 @@ class ToolbarViewTest {
|
||||||
fun setup() {
|
fun setup() {
|
||||||
MockKAnnotations.init(this)
|
MockKAnnotations.init(this)
|
||||||
context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
context = ContextThemeWrapper(testContext, R.style.NormalTheme)
|
||||||
|
every { context.settings() } returns mockk(relaxed = true)
|
||||||
toolbar = spyk(BrowserToolbar(context))
|
toolbar = spyk(BrowserToolbar(context))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +119,31 @@ class ToolbarViewTest {
|
||||||
verify(exactly = 2) { interactor.onTextChanged(any()) }
|
verify(exactly = 2) { interactor.onTextChanged(any()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `GIVEN search term is set WHEN switching to edit mode THEN the cursor is set at the end of the search term`() {
|
||||||
|
every { context.settings().showUnifiedSearchFeature } returns true
|
||||||
|
val view = buildToolbarView(false)
|
||||||
|
mockkObject(FeatureFlags)
|
||||||
|
|
||||||
|
view.update(defaultState.copy(searchTerms = "search terms"))
|
||||||
|
|
||||||
|
// editMode gets called when the view is initialized.
|
||||||
|
verify(exactly = 1) { toolbar.editMode(Toolbar.CursorPlacement.ALL) }
|
||||||
|
verify(exactly = 1) { toolbar.editMode(Toolbar.CursorPlacement.END) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `GIVEN no search term is set WHEN switching to edit mode THEN the cursor is set at the end of the search term`() {
|
||||||
|
every { context.settings().showUnifiedSearchFeature } returns true
|
||||||
|
val view = buildToolbarView(false)
|
||||||
|
mockkObject(FeatureFlags)
|
||||||
|
|
||||||
|
view.update(defaultState)
|
||||||
|
|
||||||
|
// editMode gets called when the view is initialized.
|
||||||
|
verify(exactly = 2) { toolbar.editMode(Toolbar.CursorPlacement.ALL) }
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `URL gets set to the states query`() {
|
fun `URL gets set to the states query`() {
|
||||||
val toolbarView = buildToolbarView(false)
|
val toolbarView = buildToolbarView(false)
|
||||||
|
@ -223,7 +252,7 @@ class ToolbarViewTest {
|
||||||
|
|
||||||
private fun buildToolbarView(isPrivate: Boolean) = ToolbarView(
|
private fun buildToolbarView(isPrivate: Boolean) = ToolbarView(
|
||||||
context,
|
context,
|
||||||
Settings(context),
|
context.settings(),
|
||||||
interactor,
|
interactor,
|
||||||
isPrivate = isPrivate,
|
isPrivate = isPrivate,
|
||||||
view = toolbar,
|
view = toolbar,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user