Skip to content

Commit

Permalink
Fixed checking for indices
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Sep 20, 2024
1 parent 169664f commit 6e2fc10
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public static String getSelectedLines(final CharSequence seq) {
**/
public static String getSelectedLines(final CharSequence seq, final int... sel) {
if (sel != null && sel.length > 0 && GsTextUtils.isValidSelection(seq, sel)) {
return seq.subSequence(getLineStart(seq, sel[0]), getLineEnd(seq, sel[1])).toString();
final int start = sel[0], end = sel.length > 1 ? sel[1] : sel[0];
return seq.subSequence(getLineStart(seq, start), getLineEnd(seq, end)).toString();
} else {
return "";
}
Expand All @@ -178,9 +179,7 @@ public static String getSelectedLines(final CharSequence seq, final int... sel)
/**
* Convert a char index to a line index + offset from end of line
*
* @param s text to parse
* @param p position in text
* @return int[2] where index 0 is line and index 1 is position from end of line
* @return int[n][2] where for each input, index 0 is line and index 1 is position from end of line
*/
public static int[][] getLineOffsetFromIndex(final CharSequence text, final int ... sel) {
final int[][] offsets = new int[sel.length][2];
Expand Down

0 comments on commit 6e2fc10

Please sign in to comment.