Fix search highlighting

This commit is contained in:
2025-05-24 01:16:01 +02:00
parent 6eb55c5d50
commit 716a02a1dc
2 changed files with 16 additions and 26 deletions

View File

@@ -644,8 +644,8 @@ class MainPageState extends State<MainPage> with WindowListener {
// Build rich text with highlights for search results
List<InlineSpan> _buildHighlightedText(String highlightedText) {
List<InlineSpan> spans = [];
// The text comes with <b>highlighted parts</b>
RegExp exp = RegExp(r'<b>(.*?)</b>');
// The text comes with <highlight>highlighted parts</highlight>
RegExp exp = RegExp(r'<highlight>(.*?)</highlight>');
int lastIndex = 0;
for (final match in exp.allMatches(highlightedText)) {
@@ -656,7 +656,7 @@ class MainPageState extends State<MainPage> with WindowListener {
text: highlightedText.substring(lastIndex, match.start),
style: const TextStyle(
fontSize: 13,
), // Smaller font for regular text
),
),
);
}
@@ -669,7 +669,7 @@ class MainPageState extends State<MainPage> with WindowListener {
fontWeight: FontWeight.bold,
backgroundColor: Colors.yellow,
color: Colors.black,
fontSize: 13, // Smaller font for highlighted text
fontSize: 13,
),
),
);
@@ -682,7 +682,7 @@ class MainPageState extends State<MainPage> with WindowListener {
spans.add(
TextSpan(
text: highlightedText.substring(lastIndex),
style: const TextStyle(fontSize: 13), // Smaller font for regular text
style: const TextStyle(fontSize: 13),
),
);
}
@@ -805,24 +805,13 @@ class MainPageState extends State<MainPage> with WindowListener {
12, // Smaller font for date
),
),
subtitle:
note.snippet != null
? Text.rich(
TextSpan(
children:
_buildHighlightedText(
note.snippet!,
),
),
)
: Text(
note.content.length > 200
? '${note.content.substring(0, 200)}...'
: note.content,
style: const TextStyle(
fontSize: 13,
), // Smaller font for content
),
subtitle: Text.rich(
TextSpan(
children: _buildHighlightedText(
note.snippet ?? note.content,
),
),
),
isThreeLine: true,
onTap: () async {
// Save current note if needed