Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2202bdfef | |||
8daf7ed6bf |
@@ -575,41 +575,6 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
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 {
|
||||
String previousEntry = _previousEntryController.text;
|
||||
String currentEntry = _currentEntryController.text;
|
||||
@@ -619,14 +584,8 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
// Handle current entry
|
||||
if (currentEntry.isNotEmpty) {
|
||||
// Skip saving if it looks like keyboard smashing
|
||||
if (!_isLikelyKeyboardSmashing(currentEntry)) {
|
||||
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
|
||||
|
@@ -43,11 +43,18 @@ Future<Note?> getLatestNote() async {
|
||||
}
|
||||
|
||||
Future<void> createNote(String content) async {
|
||||
// Trim the content to avoid saving just whitespace
|
||||
final trimmedContent = content.trim();
|
||||
// Trim each line, sometimes we fuck up by doing a lil "foobar "
|
||||
// Maybe I should also look for \s{2,}...
|
||||
final lines = content.split('\n');
|
||||
final trimmedLines = <String>[];
|
||||
for (final line in lines) {
|
||||
final trimmedContent = line.trim().replaceAll(RegExp(r'\s{2,}'), ' ');
|
||||
if (trimmedContent.isEmpty) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
trimmedLines.add(trimmedContent);
|
||||
}
|
||||
final trimmedContent = trimmedLines.join('\n');
|
||||
await DB.db.insert('notes', {'content': trimmedContent});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user