fix: run search bar commands on Enter and filter by /folder

This commit is contained in:
randogoth 2026-10-13 12:13:29 +03:00
parent b3df7fba9f
commit 0940fec5e8
4 changed files with 138 additions and 41 deletions

View file

@ -336,10 +336,20 @@ Happy note taking! ✨
final terms = query.split(' '); // Split search into words
final searchTags = terms.where((t) => t.startsWith(RegExp(r'[#@+]'))).toSet();
final searchText = terms.where((t) => !t.startsWith(RegExp(r'[#@+]'))).join(' ');
final searchFolders =
terms.where((t) => t.startsWith('/')).map((t) => t.substring(1));
final searchText =
terms.where((t) => !t.startsWith(RegExp(r'[#@+/]'))).join(' ');
filteredNotes = notes.where((note) {
final filename = note.uri.pathSegments.last.toLowerCase();
// Folder terms match the start of the note's folder path, like tags do.
final relative = path.relative(note.parent.path, from: notesDirectoryPath);
final folder =
relative == '.' ? '' : path.split(relative).join('/').toLowerCase();
if (!searchFolders.every(folder.startsWith)) return false;
final noteTags = _extractTags(note.readAsStringSync());
// ✅ Read file content ONLY if `Include File Content` is enabled
@ -822,7 +832,9 @@ Happy note taking! ✨
onEditingComplete: () {},
onSubmitted: (text) {
final trimmedText = text.trim();
if (_highlighted != null) {
if (trimmedText.startsWith(':')) {
_handleCommand(trimmedText);
} else if (_highlighted != null) {
_openNote(filteredNotes[_highlighted!]);
} else if (trimmedText.isNotEmpty && _isNewNote(trimmedText)) {
_createNewNote(trimmedText);