-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smart quotes not processed on paste #312
Comments
The feature is named "Replace as you type" for a reason. It only replaces them the moment you press the key. It captures the key press event and sends the character you typed through a filter together with the preceding character (or in the case of ellipsis, the two preceding) to make a decision whether to make a replacement or not. This is consistent with how this is implemented in other text editors, which is why it was written this way. (LibreOffice does the same thing.) You can see the code here: novelWriter/nw/gui/doceditor.py Line 816 in bd1bea2
This feature cannot be used with pasted text, or any other pre-existing text. Currently, you have to go through the pasted text and delete and re-type each quote. A good addition would be a feature that can scan a piece of selected text and replace quotes in it, which is something I've considered. It is also something that could be added to the build tool. This is also why the syntax highlighter distinguishes between text wrapped in straight quotes and open/close quotes: to make it easier to spot. |
This is a hugely valuable feature too. Balancing quotation marks is the bane of the fiction writer. So novelWriter does not try to balance quotation marks when text is pasted into a document, or when text is imported from a file. Fair enough. That gives the power to the writer. I've written some messed up dialog in my time and it's not clear to me if there's a foolproof algorithm to properly balance quotation marks. However, a toggle to balance them in the build tool sounds smart. |
novelWriter doesn't really try to balance them. It just assumes the writer does a sensible thing when placing them in the text. It assumes any quotation mark before a word is an opening mark, and anything else is closing. This assumption also works for mid-word apostrophes when auto-formatting single quotation marks. The rules are simply: if the quote is after a space, or the first character on a line, it's an opening quote. Otherwise it's closing. I think that is pretty much the extent of what LibreOffice does too. You can easily trick them both by not following sensible formatting conventions. A major reason I kept it simple is that this piece of code is executed every time you hit a key. It has to be simple and fast. But it does work surprisingly well. It has never failed in the thousands of word I've written for my own projects. I'm reluctant to write some complicated algorithm for managing this, and balancing them on top. It will be difficult to write one that doesn't fail in some of the many possible edge cases. Especially for single quotes, which can be indistinguishable from apostrophes and contractions. I've noticed, for instance, that the Kindle edition of the Discworld books do exactly this. Everything is single quotes, and quite a chaotic use of them as there are numerous non-standard contractions in the dialogue. When reading them, I've been thinking if there's a way to do this with a set of simple rules. I'm not sure there is. In the end, this is a feature best left to the typesetting tools. But I do see some value in being able to apply the simple rule set novelWriter now follows to a piece of text, executed by the writer. Then they can verify themselves that it was successful, and the syntax highlighter will simplify that process. It can easily be processed by looping through the characters and passing each through the same filter and rules as is done while typing. |
when the user types in quoted text at the keyboard novelWriter converts the straight quotes into an opening and a closing quote. This is as it should be.
But. When we paste into novelWriter text that has opening quotation marks around it, the second quotation mark is not rewritten. We believe it should be rewritten.
I've attached a screenshot from the novelWriter editor pane to illustrate:
What I actually typed in the second case above was:
"What happened?"
and novelWriter rewrote the straight quotes consistent with the preferences setting.
The text was updated successfully, but these errors were encountered: