From c09835306dfdce7b1cb7309b10ac7b87407025d0 Mon Sep 17 00:00:00 2001 From: Harshad Vedartham Date: Fri, 20 Sep 2024 16:50:59 -0700 Subject: [PATCH] Fixed checking for indices (#2421) (cherry picked from commit dcd77e2336b160d8550e6ce5210aeb2a15aea021) --- .../gsantner/notepad2/frontend/textview/TextViewUtils.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/gsantner/notepad2/frontend/textview/TextViewUtils.java b/app/src/main/java/net/gsantner/notepad2/frontend/textview/TextViewUtils.java index 7cbc573be..9dbd3a5c7 100644 --- a/app/src/main/java/net/gsantner/notepad2/frontend/textview/TextViewUtils.java +++ b/app/src/main/java/net/gsantner/notepad2/frontend/textview/TextViewUtils.java @@ -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 ""; } @@ -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];