Skip to content

Commit

Permalink
Fix YouTube English not working, fix newlines not parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed Jan 16, 2023
1 parent 449ff18 commit 272ee90
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions yuuna/lib/src/language/implementations/english_language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ Future<List<DictionaryTerm>> prepareSearchResultsEnglishLanguage(
Map<int, List<DictionaryEntry>> termExactResultsByLength = {};
Map<int, List<DictionaryEntry>> termDeinflectedResultsByLength = {};

List<String> words = searchTerm.splitWithDelim(RegExp('[ -]'));
List<String> segments = searchTerm.splitWithDelim(RegExp('[ -]'));
if (segments.length > 1) {
String last = segments.removeLast();
segments.addAll(last.split(''));
}

words.forEachIndexed((index, word) {
segments.forEachIndexed((index, word) {
searchBuffer.write(word);

if (word == ' ') {
Expand Down
2 changes: 1 addition & 1 deletion yuuna/lib/src/language/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ abstract class Language {
if (isSpaceDelimited) {
final workingBuffer = StringBuffer();
final termBuffer = StringBuffer();
List<String> words = textToWords(text);
List<String> words = textToWords(text.replaceAll('\n', ' '));

for (String word in words) {
workingBuffer.write(word);
Expand Down
2 changes: 1 addition & 1 deletion yuuna/lib/src/media/sources/player_youtube_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class PlayerYoutubeSource extends PlayerMediaSource {
targetLanguageItem = items[targetLanguageIndex];
items.remove(targetLanguageItem);
}
if (appLanguageIndex != -1) {
if (appLanguageIndex != -1 && targetLanguageIndex != appLanguageIndex) {
appLanguageItem = items[appLanguageIndex];
items.remove(appLanguageItem);
}
Expand Down
2 changes: 2 additions & 0 deletions yuuna/lib/src/models/app_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,8 @@ class AppModel with ChangeNotifier {
return _dictionarySearchCache[searchTerm]!;
}

searchTerm = searchTerm.replaceAll('\n', ' ');

if (searchTerm.trim().isEmpty) {
return DictionaryResult(
searchTerm: searchTerm,
Expand Down

0 comments on commit 272ee90

Please sign in to comment.