Internals

The majority of the code in Guppy is implementing the logic involved with modifying the XML tree (described above) via an editor which displays a kind of flattened version of this tree to the user. Specifically, the functions that contribute many of the lines are left, right, sel_left, sel_right, sel_cut, sel_copy, sel_paste, backspace, and insert_symbol functions.

These fall into two major categories: Moving the cursor around within the tree, and adding/removing/changing fragments of the tree. We’ll discuss a few examples of each:

Cursor functions

In Guppy, the cursor is only allowed to be inside <e> nodes. Since these only contain text, we can describe the cursor position by a reference to an <e> node within the tree, (this.current in the code), and a numerical offset indicating where the cursor sits within the text (this.caret in the code).

We outline here the basic flow of two of the cursor-related functions:

Editing functions