improve nativ find in page handling
This commit is contained in:
+10
-1
@@ -2,6 +2,7 @@ package eu.lensai.flutter_mozilla_components.api
|
|||||||
|
|
||||||
import eu.lensai.flutter_mozilla_components.GlobalComponents
|
import eu.lensai.flutter_mozilla_components.GlobalComponents
|
||||||
import eu.lensai.flutter_mozilla_components.pigeons.GeckoFindApi
|
import eu.lensai.flutter_mozilla_components.pigeons.GeckoFindApi
|
||||||
|
import mozilla.components.browser.state.action.ContentAction
|
||||||
import mozilla.components.browser.state.selector.findTabOrCustomTab
|
import mozilla.components.browser.state.selector.findTabOrCustomTab
|
||||||
import mozilla.components.browser.state.state.BrowserState
|
import mozilla.components.browser.state.state.BrowserState
|
||||||
import mozilla.components.concept.engine.EngineSession
|
import mozilla.components.concept.engine.EngineSession
|
||||||
@@ -34,7 +35,15 @@ class GeckoFindApiImpl : GeckoFindApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun clearMatches(tabId: String?) {
|
override fun clearMatches(tabId: String?) {
|
||||||
val engineSession = sessionByTabId(tabId)
|
val loadSessionId = tabId
|
||||||
|
?: components.core.store.state.selectedTabId
|
||||||
|
|
||||||
|
if (loadSessionId == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val engineSession = sessionByTabId(loadSessionId)
|
||||||
engineSession?.clearFindMatches()
|
engineSession?.clearFindMatches()
|
||||||
|
components.core.store.dispatch(ContentAction.ClearFindResultsAction(loadSessionId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-20
@@ -169,25 +169,5 @@ class Events(
|
|||||||
) { _ -> }
|
) { _ -> }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stateFlow.flowScoped { flow ->
|
|
||||||
flow.mapNotNull { state -> state.tabs }
|
|
||||||
.filterChanged {
|
|
||||||
it.content.findResults
|
|
||||||
}
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.collect { tab ->
|
|
||||||
tab.content.findResults
|
|
||||||
flutterEvents.onFindResults(
|
|
||||||
System.currentTimeMillis(),
|
|
||||||
tab.id,
|
|
||||||
tab.content.findResults.map { result -> FindResultState(
|
|
||||||
activeMatchOrdinal = result.activeMatchOrdinal.toLong(),
|
|
||||||
numberOfMatches = result.numberOfMatches.toLong(),
|
|
||||||
isDoneCounting = result.isDoneCounting,
|
|
||||||
) }
|
|
||||||
) { _ -> }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+25
@@ -10,6 +10,7 @@ import eu.lensai.flutter_mozilla_components.ext.resize
|
|||||||
import eu.lensai.flutter_mozilla_components.ext.toWebPBytes
|
import eu.lensai.flutter_mozilla_components.ext.toWebPBytes
|
||||||
import eu.lensai.flutter_mozilla_components.pigeons.AudioHitResult
|
import eu.lensai.flutter_mozilla_components.pigeons.AudioHitResult
|
||||||
import eu.lensai.flutter_mozilla_components.pigeons.EmailHitResult
|
import eu.lensai.flutter_mozilla_components.pigeons.EmailHitResult
|
||||||
|
import eu.lensai.flutter_mozilla_components.pigeons.FindResultState
|
||||||
import eu.lensai.flutter_mozilla_components.pigeons.GeckoStateEvents
|
import eu.lensai.flutter_mozilla_components.pigeons.GeckoStateEvents
|
||||||
import eu.lensai.flutter_mozilla_components.pigeons.GeoHitResult
|
import eu.lensai.flutter_mozilla_components.pigeons.GeoHitResult
|
||||||
import eu.lensai.flutter_mozilla_components.pigeons.ImageHitResult
|
import eu.lensai.flutter_mozilla_components.pigeons.ImageHitResult
|
||||||
@@ -108,6 +109,30 @@ class FlutterEventMiddleware(private val flutterEvents: GeckoStateEvents) : Midd
|
|||||||
) { _ -> }
|
) { _ -> }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
is ContentAction.AddFindResultAction -> {
|
||||||
|
runOnUiThread {
|
||||||
|
flutterEvents.onFindResults(
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
action.sessionId,
|
||||||
|
listOf(
|
||||||
|
FindResultState(
|
||||||
|
activeMatchOrdinal = action.findResult.activeMatchOrdinal.toLong(),
|
||||||
|
numberOfMatches = action.findResult.numberOfMatches.toLong(),
|
||||||
|
isDoneCounting = action.findResult.isDoneCounting,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) { _ -> }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is ContentAction.ClearFindResultsAction -> {
|
||||||
|
runOnUiThread {
|
||||||
|
flutterEvents.onFindResults(
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
action.sessionId,
|
||||||
|
listOf()
|
||||||
|
) { _ -> }
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> {
|
else -> {
|
||||||
//logger.debug("Event fired: " + action.javaClass.name)
|
//logger.debug("Event fired: " + action.javaClass.name)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user