Implement Text Tool Cursor
This MR tries to tackle on-canvas text editing. It does so by creating a SvgTextCursor that keeps track of the text position, while KoSvgTextShape now keeps a list of cursor positions. These cursor positions are used to determine the index of the text and thus to allow for insertion and deletion of text.
Update:
This MR is complete now. Right now, there's the following caveats:
- Text insertion/deletion/copy/paste are plaintext only.
- Text deletion doesn't clean up empty text-spans. I didn't try this because of the complex way KoShapes need to be manipulated to remove correctly. A refactor to make the textChunks simple structs that are accessed via a KisForest is needed to allow deleting empty-text spans.
- Caret positions have been set to be after their corresponding glyph cluster. This makes it simpler to insert text into the place folks will expect (same chunk as last glyph), as well as make it possible to have synthetic line starts for block scripts.
- We do support 'synthetic' cursor positions already, and eventually we should use these to insert extra cursor positions in places like soft-linebreaks, baseline-shifts or SVG anchored chunks. Eventually I'd also like to be able to have synthetic positions inside empty text-paths or specific chunks like, say, ruby.
- The default cursor position for when there's no text is pretty simplistic, and I hope we'll be able to make it more accurate as time goes on.
- There's a problem where canvas input settings still get checked when editing text, I do not know how to fix this.
- Undos for text are more complex than they might seem (see my comment below).
- In general I need a primer on how we handle actions inside Krita.
Task list:
Proof of concept:
-
Cursor -
Selections -
Basic movement -
Basic text insertion and removal.
Basic functionality
-
Text insertion in an empty text (this still has issues). -
Text removal for multiple spans. -
Command-ify text insertion and removal for undo -
Unit-tests -
Copy - cut - paste (plaintext)
Cursor:
-
Blinking cursor -
Using configured cursor blink speed. -
With time out (though no clue how to get config for that: windows and gnome have values for this, but macOS and kde/qt don't. -
Using the configured cursor width.
-
-
Ligature carets -
Slant for italics. -
Color for cursor.Can't figure out what to do for white-text with a white background, but still colored outline... -
Figure out what to do with collapsed white-spaces. -
Figure out default cursor in empty text. -
Cursor move -
Previous -
Next -
Previous word -
Next word -
Line start -
Line end -
Paragraph start -
Paragraph end -
Visual movement -
Previous line -
Next line.
-
-
Bidi cursor indicator. -
Action-ify cursor movement.Skipping for now.
Selections
-
Draw selections with highlight theme color -
Use caret to italicize the selection. -
Partial selections for ligatures.
Interaction on canvas
-
Add cursor icons to give more feedback on what kind of interaction is happening. -
Press to set cursor. -
The search algo for this should be refined.
-
-
Refine situation setting the text cursor object and text editing mode.
Test Plan
Select a text object in Krita. with the text tool.
Formalities Checklist
-
I confirmed this builds. -
I confirmed Krita ran and the relevant functions work. -
I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!) -
I made sure my commits build individually and have good descriptions as per KDE guidelines. -
I made sure my code conforms to the standards set in the HACKING file. -
I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.
Reminder: the reviewer is responsible for merging the patch, this is to ensure at the least two people can build the patch. In case a patch breaks the build, both the author and the reviewer should be contacted to fix the build. If this is not possible, the commits shall be reverted, and a notification with the reasoning and any relevant logs shall be sent to the mailing list, kimageshop@kde.org.