Skip to content

Commit adda790

Browse files
committed
fix(subtitle): fix a bug where words were treated as symbols in Japanese
1 parent 8f12742 commit adda790

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

LLPlayer/Controls/SelectableSubtitleText.xaml.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ private static void OnLanguageChanged(DependencyObject d, DependencyPropertyChan
170170
}
171171
}
172172

173+
// SelectableTextBox uses char.IsPunctuation(), so use a regular expression for it.
174+
// TODO: L: Sharing the code with TextBox
175+
private static readonly Regex WordSplitReg = new(@"((?:[^\P{P}'-]+|\s))", RegexOptions.Compiled);
176+
private static readonly Regex WordSplitFullReg = new(@"^(?:[^\P{P}'-]+|\s)$", RegexOptions.Compiled);
177+
173178
private static readonly Lazy<MeCabIpaDicTagger> MeCabTagger = new(() => MeCabIpaDicTagger.Create(), true);
174179

175180
private void SetText(string text)
@@ -200,10 +205,6 @@ private void SetText(string text)
200205

201206
var wordOffset = 0;
202207

203-
// SelectableTextBox uses char.IsPunctuation(), so use a regular expression for it.
204-
// TODO: L: Sharing the code with TextBox
205-
string splitPattern = @"((?:[^\P{P}'-]+|\s))";
206-
207208
// Use an OutlinedTextBlock for each word to display the border Text and enclose it in a WrapPanel
208209
for (int i = 0; i < lines.Length; i++)
209210
{
@@ -228,8 +229,7 @@ private void SetText(string text)
228229
}
229230
else
230231
{
231-
words = Regex.Split(lines[i], splitPattern)
232-
.Where(w => w != "").ToList();
232+
words = WordSplitReg.Split(lines[i]).Where(w => w != "").ToList();
233233
}
234234

235235
foreach (string word in words)
@@ -252,7 +252,7 @@ private void SetText(string text)
252252
continue;
253253
}
254254

255-
bool isSplitChar = Regex.IsMatch(word, splitPattern);
255+
bool isSplitChar = WordSplitFullReg.IsMatch(word);
256256

257257
OutlinedTextBlock textBlock = new()
258258
{

0 commit comments

Comments
 (0)