Why Apples SimpleTextInput sample code is inefficient

Im looking at Apples Sample SimpleTextInput code , which is a sample project for an iOS text editor that uses Core Text to display text. This is a wonderful thing.

But the ReadMe document says:

This sample code should not be considered as a template for a text editor, but rather as an example of how to bind a text input system to an existing text editor. Using the CoreText project is naive and inefficient; it only touches the text layout from left to right, and this is by no means a good template for any text editor. This is an implementation intended only to illustrate how to attach a system keyboard (that is, a text input system) to some existing text editor.

I am wondering how this text editor is inefficient. Is this something fundamental in his design? Maybe this can improve simple settings? UITextView can have really complex caching algorithms hidden in it; so will the problem be that SimpleTextInput is missing them?

+6
source share
2 answers

Apples SimpleTextInput sample code , uses Text to draw immediately in one CTFrameRef : object . These are the simplest options, since you can get the main text to just draw everything in one block. The only drawback to this is that it can be inefficient, because recreating the CTFrameRef each time you press a key and redrawing all the text every time you edit it slows down your application, especially if there is a lot of text plus a lot of attributes.

For more efficient ways to implement the main text editor, read Rich Text Editing: selection : Draw by Rows .

+3
source

I saw this, it does not implement all the methods, perhaps for this very reason they talk about it. Depending on your project and the need for it, you can use and expand it.

0
source

Source: https://habr.com/ru/post/900379/


All Articles