Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience method for getting a character's absolute position; add variant for other related methods #330

Closed
JordanMartinez opened this issue Jun 20, 2016 · 2 comments

Comments

@JordanMartinez
Copy link
Contributor

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);
}
@TomasMikula
Copy link
Member

TomasMikula commented Jun 20, 2016 via email

@TomasMikula
Copy link
Member

Resolved via #331

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants