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

"Highlight multiple spaces" does not work on line breaks #1043

Closed
HeyMyian opened this issue Apr 19, 2022 · 4 comments · Fixed by #1046
Closed

"Highlight multiple spaces" does not work on line breaks #1043

HeyMyian opened this issue Apr 19, 2022 · 4 comments · Fixed by #1046
Assignees
Labels
user interface Component: General user interface

Comments

@HeyMyian
Copy link
Contributor

Hi, me again.

When an automatic (not a hard) line break occurs at two consecutive spaces, they are not highlighted. This has me frequently go back during editing and check if I have accidentally inserted an additional space by inserting a temporary hard line break.

Multiple spaces at an automatic line break (shown at the cursor):

2022-04-19___18_18_27

Spaces not shown when text is selected. This doesn't feel like a bug, just the way text is handled, but is maybe the reason why multiple spaces aren't highlighted?

2022-04-19___18_18_41


That said, I usually don't have the feature turned on anyway, because it highlights a single space as soon as I typed it. Of course, because it thinks I'm at the end of a line and spaces at the end of a line are errorenous. But it's a single space, and the feature is about highlighting multiple spaces. 🤷

Perhaps the feature could be split in two:

  • Highlight multiple consecutive spaces (to be used while typing)
  • Highlight single spaces at the end of a line (mainly to be used as a check only when done typing)
@HeyMyian HeyMyian added the bug Issue: Something isn't working label Apr 19, 2022
@vkbo
Copy link
Owner

vkbo commented Apr 19, 2022

Hi, me again.

😆

When an automatic (not a hard) line break occurs at two consecutive spaces, they are not highlighted. This has me frequently go back during editing and check if I have accidentally inserted an additional space by inserting a temporary hard line break.

Spaces not shown when text is selected. This doesn't feel like a bug, just the way text is handled, but is maybe the reason why multiple spaces aren't highlighted?

Hmm, interesting. I've never noticed this. It has something to do with how the Qt library renders the text. The highlighting is handled there. I just tell it to look for the spaces with a regex. I'll play around with it to see if I can make it detect them also when wrapping.

Perhaps the feature could be split in two:

Nah, it should say "redundant" spaces instead. As for the trailing space, it is intended to detect them as it does. Even during typing. I could perhaps make it either ignore it if the cursor is parked next to it, or make it only highlight them if they are after punctuation.

@vkbo vkbo self-assigned this Apr 19, 2022
@vkbo
Copy link
Owner

vkbo commented Apr 20, 2022

I spent some time looking at the source code of Qt last night, and the class that actually draws the lines on the GUI after the wrapping has been applied seems to subtract the room taken up by spaces. You can test this yourself by adding multiple spaces to the end of a wrapped line. Even if you enable the "show tabs and spaces" feature, which is Qt's own feature, they are hidden. In other words: there is no way for me to control this behaviour from Python.

I've considered replacing this highlight feature with a general cleanup tool that can do a lot of different cleanup tasks on the text. This could include removing redundant spaces. I'll make a new feature issue on this.

I'll fix the label on the Preferences dialog though, so it's more accurate.

@tmarplatt
Copy link
Contributor

tmarplatt commented Jan 26, 2023

So what was the fix for this issue? I noticed it happening recently on master main.

Is it something you can report to Qt and wait for a fix?

@vkbo
Copy link
Owner

vkbo commented Jan 26, 2023

It is not fixable in novelWriter. It is also not a bug in Qt, so I doubt they will change anything. It would cause problems with their word wrapping implementation.

The feature to highlight multi-spaces will have to live with this limitation until I come up with a better feature. I have plans to implement a different feature to alert the writer to issues in the text. It's been discussed as part of issue #515 in this comment.

Edit: As mentioned in my comment further up this thread, even Qt's own feature to show white spaces has this limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user interface Component: General user interface
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants