Yesterday's work demonstrates all the essential features of #423: Simplify 
key handling with a new KeyStroke class. 
<https://github.com/leo-editor/leo-editor/issues/423>

This post documents the details and discusses future work. Feel free to 
ignore.

*Surprises*

1. There is no real advantage in separating modifiers from keystroke 
"tails" when creating KeyStroke objects.  The new ks.find_mods and 
ks.strip_mods easily convert any incoming binding strings into the 
so-called canonical form.

As a result, *all* new instances of KeyStroke are created using simple 
strings.

2. Aha: KeyStroke.s *is* the "canonicalized" version of the keystroke.  

This Aha has very important, very happy, consequences. None of the *uses* 
of stroke.s in Leo's code ever have to change.

3. I had forgotten that the KeyStroke class already can be used as a 
dictionary key.  This class has a __hash__ method and a full set of rich 
comparison methods.  All such methods use ks.s.  

Because ks.s is the "canonical" setting, there is no longer ever any 
confusion about whether dictionary keys match keys.



*Input logic*filter.toTkKey and its helpers convert Qt key events to a 
binding string.  This string is then used to g.KeyStroke objects 
representing the incoming Qt key.

This is extraordinarily difficult code. Much of that difficulty is 
inherent, but I was able to make some simplifications. A few more are 
simplifications are coming.



*Summary*Work is going well, but much more testing is needed, especially 
with other keyboards.

Remaining work will focus on more routine simplifications. I expect this 
work to be completed today.

All changed code is marked with g.new_keys.  These are comments, as well as 
safeguards.

Remarkably, only about a dozen methods/nodes contain tests on g.new_keys. *The 
recent changes do not cascade throughout Leo's core*. This may be the 
biggest surprise of all.

Indeed, stroke.s can never be confused with non-canonicalized strings, 
because no non-canonical strings remain.  As a result, stroke.s is now 
completely benign. There is no need to change how Leo's core uses it. For 
example, the print-bindings command "just works" with the new code.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to