-
Notifications
You must be signed in to change notification settings - Fork 113
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
Add IME support, extended actions, customize appearance #178
Conversation
I would appreciate any feedback on this. |
This needs to be rebased to resolve conflicts first |
062304e
to
d04b3f2
Compare
I rebased and updated the PR (it wasn't easy after half a year :D). Thanks to the added separation between |
d04b3f2
to
8e2a68c
Compare
I fixed the |
Let me know if I can do something to help move this forward. |
This is a large set of changes, so it is admittedly hard for me to review and approve. If it could be split into a few more PRs, that would be helpful. There are changes that are more likely to be merged as-is and other changes that probably need some refactoring. |
Sure! Here are the separated PRs:
Once we're done with these ones, I'll open PRs with the remaining changes. |
Thanks! I will review when I am back at work on Monday. |
I was trying to implement a text input that works the same way as a native text input on desktop platforms. I would like to contribute the changes I had to make to
cosmic-text
.IME support
Input method editors are required for convenient text input in some languages, so its support is essential for good user experience. While it's possible to implement some of the following changes in a wrapper around
cosmic-text
, I think it would be better to incorporate them here and provide this support to all users.SetPreedit
action that inserts text with a specialis_preedit
flag in the attributes and clears any previous preedit. This is the most straightforward way to show a preedit inline, so that it works naturally with shaping and word wrapping. The downside is that the buffer's text is not the same as the document text anymore. For example, if the user wants to retrieve the text from the buffer, they should delete the part corresponding to the preedit (or clear the preedit). To help with this, I addedBuffer::text_without_preedit()
andBufferLine::text_without_preedit()
.Edit::cursor_position()
method to retrieve the coordinates of the visual cursor. This is required to set the IME position, so that the input method window is displayed close to the cursor. The current implementation simply reuses theEditor::draw()
code (moved out to a function). This can probably be done more efficiently.There are also some aspects that I decided to implement outside of
cosmic-text
for now:Buffer
(for example, by integrating withline-straddler
), at which point it would be pretty easy to change the default preedit attributes to underline instead of the current color change.Hiding text cursor
Edit::set_cursor_hidden()
to hide cursor manually, which can be used to implement cursor blinking, and to hide cursor when the input is unfocused or read only.While I generally prefer "positive" boolean flags (e.g.
set_cursor_visible()
would generally be better), in this case the logic looks simpler when we use thehidden
flag:cursor_hidden = has_selection || has_preedit_without_cursor || set_cursor_hidden
.Extended mouse and keyboard actions
I was aiming to implement all standard keyboard shortcuts and mouse actions that are usually present on desktop systems.
DocumentStart
,DocumentEnd
,SelectAll
,DeleteStartOfWord
,DeleteEndOfWord
,SelectWord
,SelectParagraph
.select
flag toEdit::action()
to implement hotkeys withShift
modifier (e.g.Shift + ArrowRight
to create or extend the selection) and fix hotkeys withoutShift
(e.g.ArrowRight
previously didn't clear existing selection). I think this is the simplest way to implement it currently. It's not ideal because this flag only makes sense for some actions, but refactoring this API would be more dirsuptive.Previous
andNext
behavior when there is a selection. They now clear selection and put the cursor to the start and end of the selection, respectively.NextWord
action to go to the end of line if there are no more word boundaries. Previously, it could get stuck and not move forward at all in some cases.All new actions can be tested in the
editor-orbclient
example (I chose it because it already had some keyboard modifiers support, unlike the other examples).More styling options