mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Ignore chapter markers and single newlines when calculating text length
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
# v1.0.7 (pre-release)
|
||||||
|
- Ignore chapter markers and single newlines when calculating text length.
|
||||||
|
|
||||||
# v1.0.6
|
# v1.0.6
|
||||||
- Added `Insert chapter marker` button in text editor to insert chapter markers at the current cursor position.
|
- 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.
|
- Added `Preview` button in voice mixer to preview the voice mix with the selected settings.
|
||||||
|
|||||||
+7
-1
@@ -386,8 +386,14 @@ class TextboxDialog(QDialog):
|
|||||||
return self.text_edit.toPlainText()
|
return self.text_edit.toPlainText()
|
||||||
|
|
||||||
def handle_ok(self):
|
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 the text hasn't changed, treat as cancel
|
||||||
if self.text_edit.toPlainText() == self.original_text:
|
if text == self.original_text:
|
||||||
self.reject()
|
self.reject()
|
||||||
else:
|
else:
|
||||||
# Check if we need to warn about overwriting a non-temporary file
|
# Check if we need to warn about overwriting a non-temporary file
|
||||||
|
|||||||
+4
-2
@@ -119,8 +119,10 @@ def save_config(config):
|
|||||||
|
|
||||||
|
|
||||||
def calculate_text_length(text):
|
def calculate_text_length(text):
|
||||||
# Remove double newlines (replace them with single newlines)
|
# Ignore chapter markers
|
||||||
cleaned_text = text.replace("\n\n", "")
|
text_no_markers = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
|
||||||
|
# Ignore newlines
|
||||||
|
cleaned_text = text_no_markers.replace("\n", "")
|
||||||
# Calculate character count
|
# Calculate character count
|
||||||
char_count = len(cleaned_text)
|
char_count = len(cleaned_text)
|
||||||
return char_count
|
return char_count
|
||||||
|
|||||||
Reference in New Issue
Block a user