mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-21 20:00:49 +01:00
Finish the right-to-left lyrics from PR #844 on the current lyrics code. A line's direction now follows the Unicode paragraph rule: its first strong letter decides, so a Latin line with one Arabic word stays left to right, and digits, punctuation, marks, emoji or a byte order mark decide nothing. A line without letters (an instrumental "..." or a gap) takes its neighbour's direction. The scan is a rune loop over sorted ranges with an ASCII fast path, in lib/utils/text_direction.dart, and replaces the PR's any-RTL-character regex and its re-export from player_lyrics.dart. - The synced view works the directions out once per set of lyrics, with its line keys, and lays every row out in its line's direction, so the row cache, reveal, scale, backing vocals and duet alignment follow it. Mornye's line measurement uses the same directions. - The word sweep orders a word's runs by the line's direction and sweeps each run the way it is laid out, so a Latin word inside an Arabic line fills from its left. - A translation or pronunciation reads in its own direction and stays on its line's side, timed or not. Phrase-aligned pronunciation stays off for right-to-left lines. - Plain lyrics keep one text when every line shares a direction and get a text a line when they mix; the directions are cached per lyrics. - The lyric line under the header reads, and slides, in the line's direction: a long Arabic line moves right to bring its end in. - The editor keeps each field's direction in a notifier that changes only with the first letter's script, instead of rebuilding the field on every keystroke. - The share card and mini player use the same rule. In a right-to-left app a Latin line now reads left to right from the left edge; the repaint test records that. Co-authored-by: itzSho3aib <mamomema123@gmail.com>
85 lines
2.8 KiB
Dart
85 lines
2.8 KiB
Dart
import 'package:flutter/painting.dart' show TextDirection;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mornye/utils/text_direction.dart';
|
|
|
|
void main() {
|
|
group('strongTextDirection', () {
|
|
test('takes the first letter of a script', () {
|
|
expect(strongTextDirection('قطة صغيرة على الشباك'), TextDirection.rtl);
|
|
expect(strongTextDirection('הדלת הכחולה בגינה'), TextDirection.rtl);
|
|
expect(
|
|
strongTextDirection('qitta saghira ala ashubbak'),
|
|
TextDirection.ltr,
|
|
);
|
|
expect(strongTextDirection('Ein kleines Beispiel'), TextDirection.ltr);
|
|
expect(strongTextDirection('ねこ が いる'), TextDirection.ltr);
|
|
expect(strongTextDirection('Όμορφη μέρα'), TextDirection.ltr);
|
|
});
|
|
|
|
test('a single word of the other script does not turn the line', () {
|
|
expect(
|
|
strongTextDirection('The blue door says قطة tonight'),
|
|
TextDirection.ltr,
|
|
);
|
|
expect(strongTextDirection('قطة صغيرة says hello'), TextDirection.rtl);
|
|
});
|
|
|
|
test('digits, punctuation, spaces and marks decide nothing', () {
|
|
expect(strongTextDirection(' 2026, (...) "قطة"'), TextDirection.rtl);
|
|
expect(strongTextDirection('١٢٣ - qitta'), TextDirection.ltr);
|
|
expect(strongTextDirection('\u{1F3B5} ♪ qitta'), TextDirection.ltr);
|
|
expect(strongTextDirection('\u{064E}\u{0650} qitta'), TextDirection.ltr);
|
|
});
|
|
|
|
test('a byte order mark is not right to left', () {
|
|
expect(strongTextDirection('\u{FEFF}qitta saghira'), TextDirection.ltr);
|
|
expect(strongTextDirection('\u{FEFF}قطة'), TextDirection.rtl);
|
|
expect(strongTextDirection('\u{FEFF}'), isNull);
|
|
});
|
|
|
|
test('directional marks count as their direction', () {
|
|
expect(strongTextDirection('\u{200F}123 qitta'), TextDirection.rtl);
|
|
expect(strongTextDirection('\u{200E}123 قطة'), TextDirection.ltr);
|
|
});
|
|
|
|
test('text without a letter has no direction', () {
|
|
for (final text in [
|
|
'',
|
|
' ',
|
|
'...',
|
|
'♪ ♪',
|
|
'2026',
|
|
'١٢٣',
|
|
'\u{1F3B6}',
|
|
]) {
|
|
expect(strongTextDirection(text), isNull, reason: text);
|
|
}
|
|
});
|
|
});
|
|
|
|
test('lines without a letter follow their neighbours', () {
|
|
expect(
|
|
lyricLineDirections([
|
|
'...',
|
|
'قطة صغيرة',
|
|
'♪',
|
|
'qitta saghira',
|
|
'',
|
|
'على الشباك',
|
|
'...',
|
|
]),
|
|
[
|
|
TextDirection.rtl,
|
|
TextDirection.rtl,
|
|
TextDirection.rtl,
|
|
TextDirection.ltr,
|
|
TextDirection.ltr,
|
|
TextDirection.rtl,
|
|
TextDirection.rtl,
|
|
],
|
|
);
|
|
expect(lyricLineDirections(['...', '♪']), [null, null]);
|
|
expect(lyricLineDirections(const []), isEmpty);
|
|
});
|
|
}
|