Skip to content

Commit

Permalink
Convert to curly quotes & Check curly quotes (#517)
Browse files Browse the repository at this point in the history
* Add Convert to curly quotes feature

This commit makes the changes.
Second commit will check for suspects.

* Add Check curly Quotes feature

Pops a dialog listing suspected quote errors such as
quote at start/end of line or after/before space when
curl is the wrong direction, or open quote preceded
by word character, or paragraph end without closing
double quotes (unless next para begins with double
quotes), unconverted straight quotes.

Dialog has several buttons that make corrections,
and also supports Cmd/Ctrl+left/right click to make
best guess fix, which is to convert to open curly if
quote is straight, or to swap open & close if quote
is curly.

After Convert to Curly Quotes is run, the Check is run
automatically.  However, unlike GG1, the conversion to
curly quotes does notneed to be done with the convert
feature for the check to work. So if the user makes
manual quote changes at any point they can just
re-run the check.

* Review fixes

1. Add `T'ain't` to custom contractions list
2. Change label for Swap Quote/Space button
  • Loading branch information
windymilla authored Nov 27, 2024
1 parent 4a200d4 commit 39acd52
Show file tree
Hide file tree
Showing 3 changed files with 414 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/guiguts/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
DEFAULT_SCANNOS_DIR,
DEFAULT_REGEX_SCANNOS,
DEFAULT_STEALTH_SCANNOS,
convert_to_curly_quotes,
check_curly_quotes,
)
from guiguts.page_details import PageDetailsDialog
from guiguts.preferences import preferences, PrefKey
Expand Down Expand Up @@ -700,6 +702,8 @@ def init_tools_menu(self) -> None:
menu_tools.add_button("R~ewrap Selection", self.file.rewrap_selection)
menu_tools.add_button("C~lean Up Rewrap Markers", self.file.rewrap_cleanup)
menu_tools.add_separator()
menu_tools.add_button("Convert to Curly ~Quotes", convert_to_curly_quotes)
menu_tools.add_button("Check Curly Q~uotes", check_curly_quotes)
unmatched_menu = Menu(menu_tools, "Un~matched")
unmatched_menu.add_button("Bloc~k Markup...", unmatched_block_markup)
unmatched_menu.add_button("~DP Markup...", unmatched_dp_markup)
Expand Down
5 changes: 4 additions & 1 deletion src/guiguts/maintext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ def _replace_preserving_pagemarks(
)

def _replace_preserving_pagemarks_block(
self, start_index: Any, end_index: Any, replacement: str, *tags: Any
self, start_point: Any, end_point: Any, replacement: str, *tags: Any
) -> None:
"""Replace text indicated by indexes with given string (& optional tags).
Expand All @@ -1362,6 +1362,9 @@ def _replace_preserving_pagemarks_block(
replacement: Replacement text.
tags: Optional tuple of tags to be applied to inserted text.
"""
# Convert input args to index because if marks, can get odd behavior depending on gravity.
start_index = self.index(start_point)
end_index = self.index(end_point)
# Get lengths from start of replacement to each page marker
len_to_marks: list[int] = []
mark = end_index
Expand Down
Loading

0 comments on commit 39acd52

Please sign in to comment.