Caret movement in tables
As SimplyHTML now has all functionality to create and manipulate tables, it has to provide a way to move the caret inside a table conveniently. Most text processors usually allow to jump to the next or previous cell with the tab key while the caret is inside a table cell. Class SHTMLEditorPane therefore has an own section of methods dealing with this kind of caret movement.
Method getCurTableCell
With method getCurTableCell the caret position inside a table is determined. It returns the cell the caret currently is in or null, if the caret is not inside a table. This is done by using method findElementUp of class Util which looks for the next occurrence of a certain element ( TD in this case) starting at a given element (the character element at the current position in this case).
This method is used in almost any table related methods.
Methods getFirstTableCell and getLastTableCell
When the caret shall be moved from one cell of the table to another, it has to be determined if there are cells to move to from the current cell in a certain direction (previous or next). Methods getFirstTableCell and getLastTableCell return the first and last cell in a table given any cell of that table.
PrevCellAction and NextCellAction
Actions are used to actually move the caret from one cell to the next or previous one. Actions PrevCellAction and NextCellAction use above methods to determine the next or previous cell to move to and then place the caret into that cell. Both actions are added to the key map of SHTMLEditorPane with method adjustKeyBindings upon construction of the editor pane. NextCellAction is connected to the TAB key, PrevCellAction is related to SHIFT TAB .
For the case that the caret is not inside a table, both actions store the original action found in the key map for TAB and SHIFT TAB respectively. If a table action is invoked by TAB or SHIFT TAB thereafter and the caret is not inside a table cell, the original action for the associated key is invoked.