Editor module enables creating and modification of source code stored in blocks. It also provides a means to control the whole system via commands entered into command line. This module receives characters and control codes from the USB module, processes them, and communicates with Video module, SRAM module, and Interpreter module.
Editor module works in two modes. Out of reset it is set to command mode. In this mode commands can be sent to Interpreter module. Editing mode is invoked with command edit. It loads block whose number is on Interpreter's stack into video buffer, and starts editing mode. This is indicated by cursor being moved from the command line to the top of the screen.
Similarly to colorForth, editing mode has two states; navigation state and text state. In the navigation state we can move cursor within a block, move to another block, and delete whole words. In the text state we can enter new words. Editor allows to choose color of the new word, and correct typos. While in editing mode, we can switch between the two states as necessary. Leaving the editor with Esc key brings us back to the command mode.
In order to simplify the code a trick has been used; when typing into the command line we are actually editing block zero, although we can't choose text color, which is always white. Thus, from the system's point of view there is no significant difference between command mode and the text state of the editing mode.
Node 011 keeps track of the current mode, and dispatches characters and control codes received from USB module either to command/text or to navigation path.
Navigation path starts in node 111, where alphanumeric keys used for navigation are decoded into actions, which are essentially pieces of code that when executed move cursor left/right by one word (nodes 212, 213, and 113), up/down by one line (node 112), switch between source and shadow block, alternate blocks, and move to the next/previous block on disk (node 211).
When in text state of editing mode, node 011 ignores all characters received until color of a word to be typed has been selected with one of function keys F1-F12. The selected color is kept in node 010, and used for all words typed in until the color is changed. Following color selection characters are inserted at the current cursor position. Insert function is implemented in the heart of the Editor, a bridge between SRAM module and Video module (nodes 308, 309, and 310). Inserting a character consists of sending a request to SRAM to fill video buffer with content of the current block, while characters are counted one by one, and the new character is inserted into the stream at the cursor position in node 309. Whole content of video buffer is then written back to SRAM.
Similarly, while inserting characters into a word, they can be deleted with Backspace key. The process is the same, characters are counted one by one in node 309 while video buffer is being filled, and the character to be deleted is skipped. Deleting characters is possible until the word is entered with Space key, which moves cursor past this word, and a new word can be entered.