Planned improvements to Editor::Buffer for the text editor and other Buffer consumers (LineEditor, etc.).
Buffer's up/down methods move cursor_y but leave cursor_x
unchanged. When moving from a long line to a short line and back,
the original column position is lost because cursor_x is clamped
to the shorter line's byte length.
Most editors remember a "desired display column" across vertical
movements. The fix adds @desired_col to Buffer:
up/down: Convertcursor_xto display column on the first vertical move. On the destination line, convert back to byte position viaEditor.display_col_to_byte, clamping to line end.left/right/head/tail/put(String): Reset@desired_col = nilso the next vertical move starts fresh.
This requires changes to picoruby-editor (submodule). An alternative is to handle it in the editor application, but that duplicates Buffer's cursor logic.
delete removes the character at cursor_x within the current line
but does nothing when the cursor is at the end of a line. In contrast,
put(:BSPACE) at the beginning of a line joins it with the previous
line. delete should mirror this behavior: when the cursor is at the
end of a line, append the next line to the current line and remove it.
The text editor currently works around this in application code
(rootfs/app/edit.rb). Moving the logic into Buffer makes it
consistent with Backspace and removes the need for the workaround.
put(:TAB) inserts two spaces unconditionally:
when :TAB
put " "
put " "Improvements:
- Make tab width configurable (default 2, support 4 and 8).
- Align to the next tab stop rather than inserting a fixed number
of spaces. The tab stop column is
(current_display_col / width + 1) * width.