Jexi开发 (13) 实现编辑功能

今天把Caret重新设计了一遍,用一个Position表示Caret的位置:

public final class Position {
??? private int pageIndex;
??? private int rowIndex;
??? private int columnIndex;
??? ...
}

Caret的位置无法用Paragraph和Index表示,因为第N行末尾和第N+1行开头是一个位置。

为了实现输入,删除的功能,采用Command模式,定义Command接口:

interface Command {
??? boolean execute();
??? void unexecute();
}

由单态CommandManager管理Command链表,负者实现Undo/Redo。

Undo还没有实现,因为InsertCommand和DeleteCommand的unexecute()还没有写。

最新的版本可以实现输入,删除,光标定位的功能:

欢迎大家下载,并提出宝贵意见和建议!

你可能感兴趣的:(设计模式)