Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
597ce8c9cf | |||
c2202bdfef | |||
8daf7ed6bf |
@@ -390,6 +390,7 @@ END;
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ftsQuery = ftsQuery.replaceAll('-', ' ');
|
||||||
debugPrint('FTS query: "$ftsQuery"');
|
debugPrint('FTS query: "$ftsQuery"');
|
||||||
|
|
||||||
// Execute the FTS query
|
// Execute the FTS query
|
||||||
@@ -401,7 +402,6 @@ END;
|
|||||||
JOIN notes n ON notes_fts.rowid = n.id
|
JOIN notes n ON notes_fts.rowid = n.id
|
||||||
WHERE notes_fts MATCH ?
|
WHERE notes_fts MATCH ?
|
||||||
ORDER BY rank
|
ORDER BY rank
|
||||||
LIMIT 100
|
|
||||||
''',
|
''',
|
||||||
[ftsQuery],
|
[ftsQuery],
|
||||||
);
|
);
|
||||||
|
@@ -575,41 +575,6 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
debugPrint("Volume saved: $_volume");
|
debugPrint("Volume saved: $_volume");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if content appears to be keyboard smashing or repeated characters
|
|
||||||
bool _isLikelyKeyboardSmashing(String content) {
|
|
||||||
// Skip empty content
|
|
||||||
if (content.trim().isEmpty) return false;
|
|
||||||
|
|
||||||
// Check for repeated characters (like "wwwwwwww")
|
|
||||||
final repeatedCharPattern = RegExp(
|
|
||||||
r'(.)\1{4,}',
|
|
||||||
); // 5 or more repeated chars
|
|
||||||
if (repeatedCharPattern.hasMatch(content)) {
|
|
||||||
// But allow if it's a legitimate pattern like base64
|
|
||||||
if (RegExp(r'^[A-Za-z0-9+/=]+$').hasMatch(content)) return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for alternating characters (like "asdfasdf")
|
|
||||||
final alternatingPattern = RegExp(r'(.)(.)\1\2{2,}');
|
|
||||||
if (alternatingPattern.hasMatch(content)) return true;
|
|
||||||
|
|
||||||
// Check for common keyboard smashing patterns
|
|
||||||
final commonPatterns = [
|
|
||||||
r'[qwerty]{5,}', // Common keyboard rows
|
|
||||||
r'[asdf]{5,}',
|
|
||||||
r'[zxcv]{5,}',
|
|
||||||
r'[1234]{5,}',
|
|
||||||
r'[wasd]{5,}', // Common gaming keys
|
|
||||||
];
|
|
||||||
|
|
||||||
for (final pattern in commonPatterns) {
|
|
||||||
if (RegExp(pattern, caseSensitive: false).hasMatch(content)) return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _saveData() async {
|
Future<void> _saveData() async {
|
||||||
String previousEntry = _previousEntryController.text;
|
String previousEntry = _previousEntryController.text;
|
||||||
String currentEntry = _currentEntryController.text;
|
String currentEntry = _currentEntryController.text;
|
||||||
@@ -619,14 +584,8 @@ class MainPageState extends State<MainPage> with WindowListener {
|
|||||||
|
|
||||||
// Handle current entry
|
// Handle current entry
|
||||||
if (currentEntry.isNotEmpty) {
|
if (currentEntry.isNotEmpty) {
|
||||||
// Skip saving if it looks like keyboard smashing
|
await createNote(currentEntry);
|
||||||
if (!_isLikelyKeyboardSmashing(currentEntry)) {
|
_currentEntryController.clear(); // Clear the input field after saving
|
||||||
await createNote(currentEntry);
|
|
||||||
_currentEntryController.clear(); // Clear the input field after saving
|
|
||||||
} else {
|
|
||||||
debugPrint("Skipping save of likely keyboard smashing: $currentEntry");
|
|
||||||
_currentEntryController.clear(); // Still clear the input
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle scratch pad
|
// Handle scratch pad
|
||||||
|
@@ -43,11 +43,18 @@ Future<Note?> getLatestNote() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createNote(String content) async {
|
Future<void> createNote(String content) async {
|
||||||
// Trim the content to avoid saving just whitespace
|
// Trim each line, sometimes we fuck up by doing a lil "foobar "
|
||||||
final trimmedContent = content.trim();
|
// Maybe I should also look for \s{2,}...
|
||||||
if (trimmedContent.isEmpty) {
|
final lines = content.split('\n');
|
||||||
return;
|
final trimmedLines = <String>[];
|
||||||
|
for (final line in lines) {
|
||||||
|
final trimmedContent = line.trim().replaceAll(RegExp(r'\s{2,}'), ' ');
|
||||||
|
if (trimmedContent.isEmpty) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
trimmedLines.add(trimmedContent);
|
||||||
}
|
}
|
||||||
|
final trimmedContent = trimmedLines.join('\n');
|
||||||
await DB.db.insert('notes', {'content': trimmedContent});
|
await DB.db.insert('notes', {'content': trimmedContent});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user