Re: Redy 1.0.a1 released!
- Posted by ryanj Dec 20, 2014
- 3448 views
Update:
I am making good progress on the textedit.e library. It can now draw text with line numbers, and bookmark/code folding indicators. Word wrapping works, and readjusts when the canvas is resized. The display works correctly even if i change the font size, paragraph spacing, and line spacing. The next step is to get selecting/editing to work, which will require a lot of work.
This library uses what i call "tokens" to do word wrapping, syntax highlighting, and formatted text. A token is like a word of text, except it may not be a "word" in the English sense. It is a string of white space, punctuation, alphanumeric, etc. Each paragraph is broken up into tokens by the syntax parser, and each token has it's own position, size, font style, color, etc. Each paragraph also has a position and size, so when text needs to be drawn, edited, selected, etc. the paragraphs and tokens will be scanned and updated, only applying changes to ranges that actually changed, or drawing only tokens that are inside the area that need to be redrawn. I am using this technique because it seems to make it easier to add lots of features in a structured way, and i believe it will be efficient for large files (this will have to be verified once the library is complete).
Because every token has position and size pre-calculated, it makes it easier to determine which one the mouse is over, and to make the viewing area jump to the right position to show a token (for find/replace, goto line number, goto bookmarked line, goto line that has the error, etc.) Each token will be assigned a type, such as ttWhiteSpace, ttIdentifier, ttKeyword, ttNumber, ttSymbol, etc. and different types can be different text styles and have different behavior when you are typing, such as poping up different auto-complete options or help info.
Here is a screenshot. Notice the debugging rectangles, which show the outline of each paragraph and token. At this point, it won't be difficult to add syntax highlighting, formatted text (different fonts and sizes), justification, line spacing, paragraph spacing, indentation, etc. This will be useful for not just code editing, but displaying basic html/creole as formatted text.