Results after an empty search move the split editor to the first row

Aperta
#23,784 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile, testing

Direzione di ricerca

Start with the regression test shown in the issue, AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserEmptySearchPaneTest.kt, and trace how paneRow is updated when search results become empty and later repopulate. Run the focused Robolectric test and confirm that the edited note stays selected without showing a save prompt after the searches. The issue was discovered during PR review, so check that no work has already begun before picking it up.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

code-scan

Assisted-by: Claude Opus 5.5

[EXISTING] Results after an empty search move the split editor to the first row
Subject: [EXISTING] Results after an empty search move the split editor to the first row

After a search with no results, the next results open the first row instead of the edited note, asking to save unsaved edits.

⚠️ This issue existed before the PR and should likely be split off into a separate issue.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserEmptySearchPaneTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserEmptySearchPaneTest.kt
new file mode 100644
index 0000000000..be3b80bd95
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/CardBrowserEmptySearchPaneTest.kt
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki
+
+import androidx.appcompat.app.AlertDialog
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.ichi2.testutils.withSplitPaneUi
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.equalTo
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.shadows.ShadowDialog
+
+@RunWith(AndroidJUnit4::class)
+class CardBrowserEmptySearchPaneTest : RobolectricTest() {
+    @Test
+    fun `results after an empty search keep the edited note in the pane`() =
+        withSplitPaneUi {
+            setCardBrowserFragmented(true)
+            val browser = getBrowserWithNotes(2)
+            browser.viewModel.setQuery("deck:Default", forceRefresh = true)
+            browser.waitForSearchResults()
+            advanceRobolectricLooper()
+            browser.clickRowAtPosition(1)
+            advanceRobolectricLooperUntil { browser.viewModel.paneRow == browser.viewModel.cards[1] }
+            advanceRobolectricLooper()
+            val editedRow = requireNotNull(browser.viewModel.paneRow)
+            requireNotNull(browser.fragment).editFieldAt(1)!!.setText("edited")
+
+            browser.viewModel.setQuery("nid:1", forceRefresh = true)
+            browser.waitForSearchResults()
+            advanceRobolectricLooper()
+            browser.viewModel.setQuery("deck:Default", forceRefresh = true)
+            browser.waitForSearchResults()
+            advanceRobolectricLooper()
+
+            assertThat("no save changes prompt", (ShadowDialog.getLatestDialog() as? AlertDialog)?.isShowing == true, equalTo(false))
+            assertThat("the edited note stays highlighted", browser.viewModel.paneRow, equalTo(editedRow))
+        }
+}

Found while handling https://github.com/ankidroid/Anki-Android/pull/22885#pullrequestreview-6064211858

Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
2g 1h
PR unite (30g)
311

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ankidroid/Anki-Android

Tutte le issue di ankidroid/Anki-Android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.