-
-
Notifications
You must be signed in to change notification settings - Fork 624
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
handle non-breaking spaces for indentation indication #5610
Conversation
The relevant code is in speech.getIndentationSpeech. This isn't quite as
easy as it seems because the counting is done with a regular expression
(for performance) and a different character starts a new group.
Normally, this is what you want; you want tabs to be reported separately
to spaces, for example. However, in the case of no-break spaces, they
are basically just a space semantically speaking, so they're a bit
different.
|
There's two things I'd like to do to this that I think make it better, though it looks like best may not be achievable:
|
I guess we could do this; it'd just be two passes instead of one, which is fine. We can do this just for indentation text so we're not doing it over the all text; it's only useful for indentation reporting.
It can be quite different visually. At least in decent editors (Notepad++ certainly does this), tab doesn't always just get mapped to a fixed number of spaces. Rather, it moves to the next point evenly divisible by that number of spaces. If you do space tab, it will indent the same distance as just tab; i.e. the tab consumes the equivalent of 3 spaces. So, tab space tab space tab looks the same as 3 tabs, but not the same as 3 tab 2 space. |
Everyone says mixing them is a bad idea. If we said "3 space 3 tab mixed" and you care, you could look. That's my thinking anyway. I'd want to stick a pause after mixed if we did it, but honestly replacing non-breaking spaces is probably enough anyway. I'll go ahead and prepare a PR for the first part of this at least. |
…announcement. Work for nvaccess#5610.
This works for the first part. I left it open because I'm not sure if we want to do the second or not. |
@@ -421,6 +422,8 @@ def getIndentationSpeech(indentation): | |||
# Translators: This is spoken when the given line has no indentation. | |||
return _("no indent") | |||
|
|||
#The non-breaking space is semantically a space, so we replace it here. | |||
indentation = RE_NBSP_CONVERT.sub(" ", indentation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously totally cool with using regexps if it allows you to do multiple string passes in one step and thus improve performance, but in this case, is there any advantage of using a regexp over a simple:
indentation = indentation.replace(u"\xa0", " ")
Yeah, actually. |
ah, very good point. However, it seems this fails already for Unicode:
Given this and the fact that I can't think of a case when it would ever be passed an ANSI string, just change the docstring to say unicode instead of basestring for the parameter type, which should also make the unicode.replace safe. |
That should do it. |
I didn't see this before, but I see you've based this on (and are requesting merge into) next. For future reference, all pull requests should be based on (and submitted against) master; see the Contributing guidelines. No need to resubmit or anything for this one; I'll take care of it. |
…s normal spaces. Previously, this could cause announcements such as "space space space" instead of "3 space". Fixes #5610.
Incubated in 67f080d. |
I've seen this a lot, only just figured out what it is. if you're in the web browser and indentation indication is on, non-breaking spaces cause it to blow up annoyingly. For an example, see this thread, post 6. It causes indentation to be read in Firefox, Thunderbird, etc. as "space space space space..."
If someone says where the indentation function is, I can probably submit a PR. I imagine this isn't hard.