@Test public void testGetDistanceToClosestLineBeginning() { JTextPane pane = new JTextPane(); pane.setText("123456"); pane.setCaretPosition(3); int dist = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, 4); assertEquals(4, dist); pane.setText("123\n456"); dist = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, 4); assertEquals(0, dist); dist = JTextPaneToolbox.getDistanceToClosestLineBeginning(pane, 6); assertEquals(2, dist); }
public static int getDistanceToClosestLineBeginning(JTextPane pane, int pos) { String code = getText(pane); for(int i = pos - 1; i >= 0; --i) { if(code.charAt(i) == '\n') return pos - i - 1; } return pos; }
JTextPaneToolbox { public static int getDistanceToClosestLineBeginning(JTextPane pane, int pos) { String code = getText(pane); for(int i = pos - 1; i >= 0; --i) { if(code.charAt(i) == '\n') return pos - i - 1; } return pos; } }
JTextPaneToolbox { public static int getDistanceToClosestLineBeginning(JTextPane pane, int pos) { String code = getText(pane); for(int i = pos - 1; i >= 0; --i) { if(code.charAt(i) == '\n') return pos - i - 1; } return pos; }  }
JTextPaneToolbox { public static int getDistanceToClosestLineBeginning(JTextPane pane, int pos) { String code = getText(pane); for(int i = pos - 1; i >= 0; --i) { if(code.charAt(i) == '\n') return pos - i - 1; } return pos; }  static String getText(JTextPane pane); static int getDistanceToClosestLineBeginning(JTextPane pane, int pos); static int transformToLineNumber(JTextPane pane, int absPos); static int transformToLineNumber(String code, int absPos); static int getLineBeginning(JTextPane pane, int line); static int getClosestLineBeginningAfter(JTextPane pane, int absPos); static ArrayList<Integer> getLinesBetween(JTextPane pane, int start, int end); static String getCharToTheLeftOfCaret(JTextPane pane); static String getCharToTheRightOfCaret(JTextPane pane); static int getFirstCharPosInLine(JTextPane pane, int line); static int getWordBeginningAtCursor(JTextPane pane); }
JTextPaneToolbox { public static int getDistanceToClosestLineBeginning(JTextPane pane, int pos) { String code = getText(pane); for(int i = pos - 1; i >= 0; --i) { if(code.charAt(i) == '\n') return pos - i - 1; } return pos; }  static String getText(JTextPane pane); static int getDistanceToClosestLineBeginning(JTextPane pane, int pos); static int transformToLineNumber(JTextPane pane, int absPos); static int transformToLineNumber(String code, int absPos); static int getLineBeginning(JTextPane pane, int line); static int getClosestLineBeginningAfter(JTextPane pane, int absPos); static ArrayList<Integer> getLinesBetween(JTextPane pane, int start, int end); static String getCharToTheLeftOfCaret(JTextPane pane); static String getCharToTheRightOfCaret(JTextPane pane); static int getFirstCharPosInLine(JTextPane pane, int line); static int getWordBeginningAtCursor(JTextPane pane);  }