Skip to content
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

Closed
johnblommers opened this issue Jun 14, 2020 · 3 comments · Fixed by #315
Closed

Smart quotes not processed on paste #312

johnblommers opened this issue Jun 14, 2020 · 3 comments · Fixed by #315
Assignees
Labels
potential feature Request: May be considered later

Comments

@johnblommers
Copy link

johnblommers commented Jun 14, 2020

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:

Quote

What I actually typed in the second case above was:

"What happened?"

and novelWriter rewrote the straight quotes consistent with the preferences setting.

@vkbo
Copy link
Owner

vkbo commented Jun 14, 2020

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:

def _docAutoReplace(self, theBlock):

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.

@vkbo vkbo self-assigned this Jun 14, 2020
@vkbo vkbo added the potential feature Request: May be considered later label Jun 14, 2020
@johnblommers
Copy link
Author

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.

@vkbo
Copy link
Owner

vkbo commented Jun 14, 2020

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.

@vkbo vkbo added this to To Do (Features) in Release 1.0 - Core Features Jun 15, 2020
@vkbo vkbo linked a pull request Jun 19, 2020 that will close this issue
@vkbo vkbo moved this from To Do (Features) to In Progress in Release 1.0 - Core Features Jun 19, 2020
@vkbo vkbo closed this as completed in #315 Jun 20, 2020
Release 1.0 - Core Features automation moved this from In Progress to Done Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential feature Request: May be considered later
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants