#1269 <https://github.com/leo-editor/leo-editor/issues/1269> has been a
great success. Testing continues.
Simplifying Leo's key code was unexpectedly easy. The first step was to
eliminate all evil kwargs in the key-handling code. It was then possible to
refactor the code. The results were better than I had hoped.
Scripts and plugins can now use k.masterKeyHandler, c.doCommandByName, and
c.insertCharFromEvent as *resources *for handling incoming keystrokes.
Scripts and plugins may choose to execute or ignore any commands that might
be bound to those keys.
k.masterKeyHandler has been around for decades. Now, it's easy to see what
k.masterKeyHandler does. At last, its top level shows all and *only *the
most important code*. *No mysterious hacks remain. This new transparency
means that devs can use various parts of k.masterKeyHandler for their own
purposes. I'll give an example below.
k.doCommandByName looks up the function corresponding to the command name
and calls that function. That's all. k.simulateCommand has collapsed in
complexity. It is now a thin wrapper around k.doCommandByName.
Finally, c.insertCharFromEvent handles an incoming character *without*
executing
any command that might be bound to it. k.masterKeyHandler calls
c.insertCharFromEvent if there is no binding for the character in the
widget having focus.
Here is an example of adapting the code in k.masterKeyHandler for specific
purposes. Suppose you want a script that handles abbreviations before
calling c.insertCharFromEvent. k.masterKeyHandler shows how. It ends with:
# Handle abbreviations.
if k.abbrevOn and c.abbrevCommands.expandAbbrev(event, event.stroke):
return
c.insertCharFromEvent(event)
*Summary*
#1269 <https://github.com/leo-editor/leo-editor/issues/1269> has been a
great success:
Leo's key-handling code is no longer an embarrassment. Evil kwargs are
gone. All functions do just one well-defined thing.
Scripts and plugins can now use k.masterKeyHandler, c.doCommandByName, and
c.insertCharFromEvent as *resources *for handling incoming keystrokes.
The top-level of k.masterKeyHandler now clearly shows the essential steps
involved in handling incoming keystrokes. Devs can use parts of this top
level code for their own purposes.
Testing will continue for a few more days before I merge the "keys" branch
into devel. Please report any problems immediately.
Edward
P.S. As noted in #1269, I have abandoned the #1594
<https://github.com/leo-editor/leo-editor/issues/1594>, which was the old
"phase 2" of the project. Imo, the new code is good enough as it is.
EKR
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/6d1b1a95-6369-4fad-9150-23159416e863%40googlegroups.com.