Skip to content

Commit f9dad24

Browse files
committed
feat: carry the active note list search into find in note
1 parent 14a6e24 commit f9dad24

4 files changed

Lines changed: 76 additions & 10 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1414
"Tags" menu adds and removes existing or new tags, including offline. Changes are merged into
1515
the newest server version of the file and never overwrite concurrent desktop changes. Tagging
1616
stays off, with an explanation, when the notes folder has no `notes.sqlite`.
17+
- Opening a note while the note list search is active now opens "Find in note" with the same
18+
text, highlighting the matches and scrolling to the first one without showing the keyboard.
1719

1820
## [0.10.0] - 2026-09-28
1921

‎app/src/androidTest/kotlin/org/qownnotes/mobile/AppLaunchTest.kt‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import androidx.compose.ui.graphics.asAndroidBitmap
1010
import androidx.compose.ui.test.assertIsDisplayed
1111
import androidx.compose.ui.test.assertIsEnabled
1212
import androidx.compose.ui.test.assertIsNotEnabled
13+
import androidx.compose.ui.test.assertIsNotFocused
1314
import androidx.compose.ui.test.assertIsOff
1415
import androidx.compose.ui.test.assertIsOn
1516
import androidx.compose.ui.test.assertIsSelected
17+
import androidx.compose.ui.test.assertTextContains
1618
import androidx.compose.ui.test.assertTextEquals
1719
import androidx.compose.ui.test.captureToImage
1820
import androidx.compose.ui.test.click as touchClick
@@ -2371,6 +2373,39 @@ class AppLaunchTest {
23712373
composeRule.onNodeWithTag("note-find-field").assertDoesNotExist()
23722374
}
23732375

2376+
@Test
2377+
fun noteOpenedFromAnActiveSearchFindsTheSearchTextWithoutTakingFocus() {
2378+
importAccount(
2379+
"alice",
2380+
"Recipe",
2381+
"etag-1",
2382+
10,
2383+
"# Recipe\n\nAdd salt, then more salt.\n"
2384+
)
2385+
composeRule.onNodeWithTag("note-search").performTextInput(" SALT ")
2386+
composeRule.waitForTag("clear-note-search")
2387+
composeRule.onNodeWithText("Recipe").performClick()
2388+
composeRule.waitForTag("markdown-view")
2389+
2390+
composeRule.onNodeWithTag("note-find-field").assertTextContains("SALT")
2391+
composeRule.waitForText("1 of 2")
2392+
// The keyboard must not cover the note merely because it was opened from a search.
2393+
composeRule.onNodeWithTag("note-find-field").assertIsNotFocused()
2394+
composeRule.onNodeWithTag("find-next").performClick()
2395+
composeRule.onNodeWithText("2 of 2").assertIsDisplayed()
2396+
2397+
composeRule.onNodeWithTag("close-find").performClick()
2398+
composeRule.onNodeWithTag("note-find-field").assertDoesNotExist()
2399+
composeRule.onNodeWithTag("back-to-note-list").performClick()
2400+
2401+
// Without a search, a note opens without finding anything.
2402+
composeRule.waitForTag("clear-note-search")
2403+
composeRule.onNodeWithTag("clear-note-search").performClick()
2404+
composeRule.onNodeWithText("Recipe").performClick()
2405+
composeRule.waitForTag("markdown-view")
2406+
composeRule.onNodeWithTag("note-find-field").assertDoesNotExist()
2407+
}
2408+
23742409
/**
23752410
* An editing session that never pauses must still reach storage. Every round of typing
23762411
* restarts the idle save, so it never completes and whatever the database ends up holding was

‎app/src/main/kotlin/org/qownnotes/mobile/MainActivity.kt‎

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ private fun NotesNavigation(
378378
var selectedHeading by rememberSaveable { mutableStateOf<String?>(null) }
379379
var editOnOpenNoteId by rememberSaveable { mutableStateOf<String?>(null) }
380380
var navigationRequest by rememberSaveable { mutableStateOf(0) }
381+
// The note-list search that was active when a note was opened from the list, so the opened
382+
// note starts by finding the same text. Every other way of opening a note clears it.
383+
var findOnOpen by rememberSaveable { mutableStateOf<String?>(null) }
381384
var noteHistory by rememberSaveable { mutableStateOf(emptyList<String>()) }
382385
var managingAccounts by rememberSaveable { mutableStateOf(false) }
383386
var browsingBookmarks by rememberSaveable { mutableStateOf(false) }
@@ -400,6 +403,7 @@ private fun NotesNavigation(
400403
noteHistory = noteHistory.dropLast(1)
401404
selectedHeading = null
402405
editOnOpenNoteId = null
406+
findOnOpen = null
403407
navigationRequest++
404408
}
405409
BackHandler(enabled = managingAccounts && selectedNoteId == null) {
@@ -431,6 +435,7 @@ private fun NotesNavigation(
431435
noteHistory = emptyList()
432436
selectedNoteId = note.localId
433437
selectedHeading = null
438+
findOnOpen = null
434439
navigationRequest++
435440
}
436441
}
@@ -451,6 +456,7 @@ private fun NotesNavigation(
451456
selectedNoteId = request.localId
452457
selectedHeading = null
453458
editOnOpenNoteId = null
459+
findOnOpen = null
454460
navigationRequest++
455461
}
456462
is WidgetRequest.CreateNote -> {
@@ -464,6 +470,7 @@ private fun NotesNavigation(
464470
selectedNoteId = note.localId
465471
selectedHeading = null
466472
editOnOpenNoteId = note.localId
473+
findOnOpen = null
467474
navigationRequest++
468475
}
469476
}
@@ -480,18 +487,21 @@ private fun NotesNavigation(
480487
heading = selectedHeading,
481488
startEditing = editOnOpenNoteId == noteId,
482489
navigationRequest = navigationRequest,
490+
initialFindQuery = findOnOpen,
483491
onInitialEditStarted = { editOnOpenNoteId = null },
484492
onBackToList = {
485493
selectedNoteId = null
486494
selectedHeading = null
487495
editOnOpenNoteId = null
496+
findOnOpen = null
488497
noteHistory = emptyList()
489498
},
490499
onOpen = { destination ->
491500
if (noteId != destination.localId) noteHistory = noteHistory + noteId
492501
selectedNoteId = destination.localId
493502
selectedHeading = destination.heading
494503
editOnOpenNoteId = null
504+
findOnOpen = null
495505
navigationRequest++
496506
}
497507
)
@@ -523,6 +533,7 @@ private fun NotesNavigation(
523533
selectedNoteId = localId
524534
selectedHeading = null
525535
editOnOpenNoteId = null
536+
findOnOpen = null
526537
navigationRequest++
527538
}
528539
)
@@ -551,14 +562,16 @@ private fun NotesNavigation(
551562
selectedNoteId = note.localId
552563
selectedHeading = null
553564
editOnOpenNoteId = note.localId
565+
findOnOpen = null
554566
navigationRequest++
555567
}
556568
},
557-
onOpen = {
569+
onOpen = { localId, searchText ->
558570
noteHistory = emptyList()
559-
selectedNoteId = it
571+
selectedNoteId = localId
560572
selectedHeading = null
561573
editOnOpenNoteId = null
574+
findOnOpen = searchText
562575
navigationRequest++
563576
}
564577
)
@@ -854,7 +867,8 @@ private fun NoteListScreen(
854867
onManageAccounts: () -> Unit,
855868
onOpenBookmarks: () -> Unit,
856869
onCreate: (String, String, String?) -> Unit,
857-
onOpen: (String) -> Unit
870+
/** Opens a note with the active search text, if any, so the note can find it too. */
871+
onOpen: (String, String?) -> Unit
858872
) {
859873
var query by rememberSaveable { mutableStateOf("") }
860874
var searchScope by rememberSaveable { mutableStateOf(NoteSearchScope.TITLE_AND_CONTENT) }
@@ -1483,7 +1497,10 @@ private fun NoteListScreen(
14831497
selectedNoteIds + note.localId
14841498
}
14851499
} else {
1486-
onOpen(note.localId)
1500+
onOpen(
1501+
note.localId,
1502+
query.trim().takeIf(String::isNotEmpty)
1503+
)
14871504
}
14881505
},
14891506
onLongClick = {
@@ -2465,6 +2482,7 @@ private fun NoteDetailScreen(
24652482
heading: String?,
24662483
startEditing: Boolean,
24672484
navigationRequest: Int,
2485+
initialFindQuery: String?,
24682486
onInitialEditStarted: () -> Unit,
24692487
onBackToList: () -> Unit,
24702488
onOpen: (ResolvedNoteLink) -> Unit
@@ -2569,14 +2587,21 @@ private fun NoteDetailScreen(
25692587
var canRedo by remember(localId) { mutableStateOf(false) }
25702588
var pendingHeading by remember(localId, heading, navigationRequest) { mutableStateOf(heading) }
25712589
var loadImages by remember(localId) { mutableStateOf(true) }
2572-
var finding by rememberSaveable(localId) { mutableStateOf(false) }
2590+
// A note opened from an active note-list search starts by finding that text, so the matches
2591+
// that made the note appear in the list are highlighted and the first one is scrolled to.
2592+
var finding by rememberSaveable(localId) { mutableStateOf(initialFindQuery != null) }
25732593
var togglingTask by remember(localId) { mutableStateOf(false) }
2574-
var findQuery by rememberSaveable(localId) { mutableStateOf("") }
2594+
var findQuery by rememberSaveable(localId) { mutableStateOf(initialFindQuery.orEmpty()) }
2595+
// Find opened for the list search was not a request to type, so it must not raise the keyboard.
2596+
var findFromListSearch by rememberSaveable(localId) {
2597+
mutableStateOf(initialFindQuery != null)
2598+
}
25752599
var currentMatch by rememberSaveable(localId) { mutableStateOf(0) }
25762600
var matches by remember(localId) { mutableStateOf(emptyList<IntRange>()) }
25772601
val closeFind = {
25782602
finding = false
25792603
findQuery = ""
2604+
findFromListSearch = false
25802605
currentMatch = 0
25812606
if (editing) editor?.focusForInput()
25822607
Unit
@@ -3136,7 +3161,8 @@ private fun NoteDetailScreen(
31363161
currentMatch = (currentMatch + 1) % matches.size
31373162
}
31383163
},
3139-
onClose = closeFind
3164+
onClose = closeFind,
3165+
focusOnOpen = !findFromListSearch
31403166
)
31413167
} else {
31423168
Row(
@@ -3365,7 +3391,8 @@ private fun NoteDetailScreen(
33653391
},
33663392
onClose = {
33673393
closeFind()
3368-
}
3394+
},
3395+
focusOnOpen = !findFromListSearch
33693396
)
33703397
}
33713398
if (noteTags.isNotEmpty()) {
@@ -4281,11 +4308,12 @@ private fun FindInNoteBar(
42814308
onQueryChange: (String) -> Unit,
42824309
onPrevious: () -> Unit,
42834310
onNext: () -> Unit,
4284-
onClose: () -> Unit
4311+
onClose: () -> Unit,
4312+
focusOnOpen: Boolean = true
42854313
) {
42864314
val focusRequester = remember { FocusRequester() }
42874315
// Opening the bar is a request to type, so take the focus instead of asking for a second tap.
4288-
LaunchedEffect(Unit) { focusRequester.requestFocus() }
4316+
LaunchedEffect(Unit) { if (focusOnOpen) focusRequester.requestFocus() }
42894317
Row(
42904318
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),
42914319
verticalAlignment = Alignment.CenterVertically

‎mobile-app-plan.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ Notes grow long, and the note list search only says which note contains a word,
305305
- Report the position in the matches, such as `2 of 7`, and say when there are none.
306306
- Move to the next and previous match and wrap around at both ends.
307307
- Leave the note untouched: finding text may only add and remove its own spans.
308+
- Carry an active note-list search into a note opened from the list: the find bar opens with the trimmed search text and scrolls to the first match, but does not take focus or raise the keyboard. Notes opened any other way, such as through links, history, widgets, or shares, open without a find query.
308309

309310
### Editing Mode
310311

0 commit comments

Comments
 (0)