limetext / lime

Open source API-compatible alternative to the text editor Sublime Text
http://limetext.github.io
BSD 2-Clause "Simplified" License
15.3k stars 1.06k forks source link

Unable to type capital letters #501

Closed bwiggs closed 9 years ago

bwiggs commented 9 years ago

When running the QML frontend, I find I'm not able to type in capital letters to the editor.

bwiggs commented 9 years ago

It seems like at some point we need to capitalize the letter if shift true for the KeyPress struct. I've tracked it down to https://github.com/limetext/lime/blob/master/backend/editor.go#L358 .

It seems like we have two options. Either add some code to capitalize the letter in editor.go inputthread(), or we pass the entire KeyPress object into the insert command and let it handle the capitalization.

Thoughts?

quarnster commented 9 years ago

I recall having a discussion regarding this before, but can't seem to find it now. Perhaps it was with @EdVanDance or @zoli?

IMO the backend shouldn't try to capitalize characters. Point being is that the key press shift+1 on my keyboard should result in the inserted character !. Obviously that's keyboard layout specific and not necessarily known by the backend, but in all likelyhood the frontend knows that.

The insert command should remain as is for backwards compatibility with Sublime Text, but the KeyPress struct should have a new field for storing the ! if it doesn't have that already, and that field in turn should be used when invoking the insert command.

bwiggs commented 9 years ago

The QML KeyEvent Element has a text field, which:

... holds the Unicode text that the key generated. The text returned can be an empty string in cases where modifier keys, such as Shift, Control, Alt, and Meta, are being pressed or released. In such cases key will contain a valid value

I updated main.qml to pass the KeyEvent.text field through to the qmlfrontend.HandleInput function. I then updated the KeyPress struct to have an additional Text string field to represent that value. Finally, I updated editor.HandleInput to pass the insert command that new text field instead of key.

@quarnster @zoli Still need to add some tests, but any other feedback before I PR?

quarnster commented 9 years ago

Please also write a quick code documentation note for the KeyPress fields to clarify how they are used. Saying that Text is used to insert text when no key-binding is matched, and that the other fields are used for key-binding-matching is enough.

Also please update the termbox and html frontends. Simply setting Text = Key is ok for now if the correct way isn't obvious.