diff --git a/CHANGELOG.md b/CHANGELOG.md index ef5808a..af5b50d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# v1.0.7 (pre-release) +- Ignore chapter markers and single newlines when calculating text length. + # v1.0.6 - Added `Insert chapter marker` button in text editor to insert chapter markers at the current cursor position. - Added `Preview` button in voice mixer to preview the voice mix with the selected settings. diff --git a/abogen/gui.py b/abogen/gui.py index 401a096..97e2a11 100644 --- a/abogen/gui.py +++ b/abogen/gui.py @@ -386,8 +386,14 @@ class TextboxDialog(QDialog): return self.text_edit.toPlainText() def handle_ok(self): + text = self.text_edit.toPlainText() + # Check if text is empty based on character count + if calculate_text_length(text) == 0: + QMessageBox.warning(self, "Textbox Error", "Text cannot be empty.") + return + # If the text hasn't changed, treat as cancel - if self.text_edit.toPlainText() == self.original_text: + if text == self.original_text: self.reject() else: # Check if we need to warn about overwriting a non-temporary file diff --git a/abogen/utils.py b/abogen/utils.py index 1ea9dd8..58aab35 100644 --- a/abogen/utils.py +++ b/abogen/utils.py @@ -119,8 +119,10 @@ def save_config(config): def calculate_text_length(text): - # Remove double newlines (replace them with single newlines) - cleaned_text = text.replace("\n\n", "") + # Ignore chapter markers + text_no_markers = re.sub(r"<>", "", text) + # Ignore newlines + cleaned_text = text_no_markers.replace("\n", "") # Calculate character count char_count = len(cleaned_text) return char_count