I believe we've discussed this before, but rather than typing....
int row = 4;
int col = 20;
int charPos = area.position(row, col).toOffset();
... to get the absolute position (which isn't readily obvious to new users of the code) that is necessary for other actions, for example...
area.moveTo(charPos);
area.selectRange(charPos, charPos + 2);
area.replaceText(charPos, charPos - 10, "some text")
Why not provide a convenience method that gets a character's absolute position? This would be more readably apparent than area.position(int, int).toOffset():
public int getAbsoluteCharPosition(int row, int col) {
return position(row, col).toOffset();
}
(I'm not sure if the supplied method name should be used. absoluteCharPosition might be better?)
Additionally, the above methods could be expanded to include the new row-column format:
public void moveTo(int row, int col) {
moveTo(getAbsoluteCharPosition(startRow, startCol));
}
public void selectRange(int startRow, int startCol, int endRow, int endCol) {
int startPos = getAbsoluteCharPosition(startRow, startCol);
int endPos = getAbsoluteCharPosition(endRow, endCol);
selectRange(startPos, endPos);
}
public void replaceText(int startRow, int startCol, int endRow, int endCol, String text) {
int startPos = getAbsoluteCharPosition(startRow, startCol);
int endPos = getAbsoluteCharPosition(endRow, endCol);
replaceText(startPos, endPos, text);
}
I believe we've discussed this before, but rather than typing....
... to get the absolute position (which isn't readily obvious to new users of the code) that is necessary for other actions, for example...
Why not provide a convenience method that gets a character's absolute position? This would be more readably apparent than
area.position(int, int).toOffset():(I'm not sure if the supplied method name should be used.
absoluteCharPositionmight be better?)Additionally, the above methods could be expanded to include the new row-column format: