Ignore chapter markers and single newlines when calculating text length

This commit is contained in:
Deniz Şafak
2025-05-08 16:29:43 +03:00
parent 4d0aabc13e
commit 311cdaeae1
3 changed files with 14 additions and 3 deletions
+7 -1
View File
@@ -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
+4 -2
View File
@@ -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"<<CHAPTER_MARKER:.*?>>", "", text)
# Ignore newlines
cleaned_text = text_no_markers.replace("\n", "")
# Calculate character count
char_count = len(cleaned_text)
return char_count