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

Fixed checking for indices in getSelectedLines #2421

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading