From 8f782d93251979182939f258d2c8106140aa3a52 Mon Sep 17 00:00:00 2001 From: rampaa Date: Thu, 16 Jan 2025 13:10:37 +0300 Subject: [PATCH] Allow newlines in Definition (Custom Word) and Extra info (Custom Name) fields --- JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs | 4 ++++ JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs | 2 +- JL.Windows/GUI/AddNameWindow.xaml | 2 +- JL.Windows/GUI/AddNameWindow.xaml.cs | 4 ++-- JL.Windows/GUI/AddWordWindow.xaml | 2 +- JL.Windows/GUI/AddWordWindow.xaml.cs | 6 +++--- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs b/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs index 24fa18dd..01cdd85b 100644 --- a/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs +++ b/JL.Core/Dicts/CustomNameDict/CustomNameLoader.cs @@ -44,6 +44,10 @@ internal static void Load(Dict dict, CancellationToken cancellationToken) { extraInfo = null; } + else + { + extraInfo = extraInfo.Replace("\\n", "\n", StringComparison.Ordinal); + } } AddToDictionary(spelling, reading, nameType, extraInfo, customNameDictionary); diff --git a/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs b/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs index cf90f7b6..87ceaed2 100644 --- a/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs +++ b/JL.Core/Dicts/CustomWordDict/CustomWordLoader.cs @@ -75,7 +75,7 @@ internal static void Load(Dict dict, CancellationToken cancellationToken) readings = null; } - string[] definitions = lParts[2].Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + string[] definitions = lParts[2].Replace("\\n", "\n", StringComparison.Ordinal).Split(';', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); string partOfSpeech = lParts[3]; string[]? wordClasses = null; diff --git a/JL.Windows/GUI/AddNameWindow.xaml b/JL.Windows/GUI/AddNameWindow.xaml index 0d721eeb..6634c120 100644 --- a/JL.Windows/GUI/AddNameWindow.xaml +++ b/JL.Windows/GUI/AddNameWindow.xaml @@ -24,7 +24,7 @@ - + diff --git a/JL.Windows/GUI/AddNameWindow.xaml.cs b/JL.Windows/GUI/AddNameWindow.xaml.cs index 187d470d..769ea847 100644 --- a/JL.Windows/GUI/AddNameWindow.xaml.cs +++ b/JL.Windows/GUI/AddNameWindow.xaml.cs @@ -74,7 +74,7 @@ private Task HandleSaveButtonClick() Close(); string path = Path.GetFullPath(dict.Path, Utils.ApplicationPath); - string line = $"{spelling}\t{reading}\t{nameType}\t{extraInfo}\n"; + string line = $"{spelling}\t{reading}\t{nameType}\t{extraInfo?.ReplaceLineEndings("\\n")}\n"; return File.AppendAllTextAsync(path, line); } @@ -105,7 +105,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) // ReSharper disable once AsyncVoidMethod private async void Window_PreviewKeyUp(object sender, KeyEventArgs e) { - if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On) + if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On && !ExtraInfoTextBox.IsFocused) { e.Handled = true; await HandleSaveButtonClick().ConfigureAwait(false); diff --git a/JL.Windows/GUI/AddWordWindow.xaml b/JL.Windows/GUI/AddWordWindow.xaml index af12bbf3..ef4e29e8 100644 --- a/JL.Windows/GUI/AddWordWindow.xaml +++ b/JL.Windows/GUI/AddWordWindow.xaml @@ -22,7 +22,7 @@ - diff --git a/JL.Windows/GUI/AddWordWindow.xaml.cs b/JL.Windows/GUI/AddWordWindow.xaml.cs index 2a44ed0f..c0fbbb72 100644 --- a/JL.Windows/GUI/AddWordWindow.xaml.cs +++ b/JL.Windows/GUI/AddWordWindow.xaml.cs @@ -91,8 +91,8 @@ private Task HandleSaveButtonClick() Close(); string line = string.IsNullOrWhiteSpace(rawWordClasses) - ? $"{rawSpellings}\t{rawReadings}\t{rawDefinitions}\t{rawPartOfSpeech}\n" - : $"{rawSpellings}\t{rawReadings}\t{rawDefinitions}\t{rawPartOfSpeech}\t{rawWordClasses}\n"; + ? $"{rawSpellings}\t{rawReadings}\t{rawDefinitions.ReplaceLineEndings("\\n")}\t{rawPartOfSpeech}\n" + : $"{rawSpellings}\t{rawReadings}\t{rawDefinitions.ReplaceLineEndings("\\n")}\t{rawPartOfSpeech}\t{rawWordClasses}\n"; string path = Path.GetFullPath(dict.Path, Utils.ApplicationPath); return File.AppendAllTextAsync(path, line); @@ -172,7 +172,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e) // ReSharper disable once AsyncVoidMethod private async void Window_PreviewKeyUp(object sender, KeyEventArgs e) { - if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On) + if (e.Key is Key.Enter && InputMethod.Current?.ImeState is not InputMethodState.On && !DefinitionsTextBox.IsFocused) { e.Handled = true; await HandleSaveButtonClick().ConfigureAwait(false);