openstenoproject / plover

Open source stenotype engine
http://opensteno.org/plover
GNU General Public License v2.0
2.34k stars 281 forks source link

{*!}{*-|} (retroactive capitalize and remove space) stroke doesn't remove a space #1438

Open Abkwreu opened 2 years ago

Abkwreu commented 2 years ago

Describe the bug

The dictionary translation {*!}{*-|} (retroactive capitalize + retroactive remove space) doesn't function as expected. The stroke capitalizes the last word as expected (the {*-|} part), but does not attach the last word (the {*!} part). Both the {*!} and {*-|} strokes function correctly when used alone, but {*!} (retroactive remove space) does not function when combined with {*-|} (retroactive capitalize). This holds no matter the order of the two parts of the translation.

To Reproduce

Steps to reproduce the behavior:

  1. Add a dictionary entry for {*!}{*-|} or {*-|}{*!} (this bug seems to apply to both)
  2. Write a few words then switch to a new tab or window (causing the next word entered to be neither attached nor capitalized)
  3. Write another random word
  4. Strike the entry you just created. The last word will get capitalized, but not attached to the word before (should do both).

Expected behavior

{*!}{*-|} and {*-|}{*!} should both attach the previous word and capitalize it.

Operating system

Hardware

Abkwreu commented 2 years ago

Seems like this issue comes from retrospective add/remove space being a different type of macro from the rest, while others have the format of {:something:something}, retroactive add/remove space start with =. Retroactive spacing also isn't in _parse_meta in plover/formatting.py, which seems to handle every macro except retroactive add/remove space, retroactive asterisk, and repeat stroke.

JoshuaGrams commented 2 years ago

There also seems to be something going on with them being in the same definition: if I do them as separate strokes {*!} followed by {*-|} does what I'd expect: it turns "now you can" into "now Youcan". But the other way around (doing the capitalization first) turns "now you can" into "now you Can" instead of the expected "now youCan".

Also, the order should matter, shouldn't it? It seems to me that attaching first should then capitalize the whole joined word, while capitalizing first should capitalize and then attach leaving the capitalized letter in the middle.

user202729 commented 2 years ago

The ones that start with = are formally called macros, the rest are called metas. See https://github.com/openstenoproject/plover/wiki/Dictionary-Format.

=retrospective_delete_space is a macro and you can't invoke more than one macro/the macro and some text in one stroke. {*!} is just the "backwards compatible" name.

So this is actually a feature request for allowing a stroke to trigger a macro and something else.

If you don't need the functionality of the macro, you can look for a meta (*) that does the same thing.

*: may be in a plugin?

user202729 commented 2 years ago

A meta that does the same thing is {}{:retro_stringop:5:__import__('re').sub(r"\s+(\S+)\s*$", lambda match: match[1][0].upper()+match[1][1:], text)}.

(this probably can be done without the retro_stringop plugin, but use retro_stringop for everything is convenient.)

I originally intend to write some plugin to make regex substitution, but I don't see it adds much value (and it would not support change case/some other transformation like the example above)

d3zd3z commented 2 years ago

There also seems to be something going on with them being in the same definition: if I do them as separate strokes {*!} followed by {*-|} does what I'd expect: it turns "now you can" into "now Youcan". But the other way around (doing the capitalization first) turns "now you can" into "now you Can" instead of the expected "now youCan".

This is the part that seems to be broken. I've found myself wanting this when I move to a new window and start writing, and get both a space and a lowercase word. I've starting getting into the habit of deleting the new word, and stroking {^}{-|} to get the upper case word without space.