@Test public void testGetCharToTheLeftOfCaret() { JTextPane pane = new JTextPane(); pane.setText("abc"); pane.setCaretPosition(0); String lhs = JTextPaneToolbox.getCharToTheLeftOfCaret(pane); assertEquals("", lhs); pane.setCaretPosition(1); lhs = JTextPaneToolbox.getCharToTheLeftOfCaret(pane); assertEquals("a", lhs); pane.setCaretPosition(2); lhs = JTextPaneToolbox.getCharToTheLeftOfCaret(pane); assertEquals("b", lhs); pane.setCaretPosition(3); lhs = JTextPaneToolbox.getCharToTheLeftOfCaret(pane); assertEquals("c", lhs); }
public static String getCharToTheLeftOfCaret(JTextPane pane) { String code = getText(pane); int caretPos = pane.getCaretPosition(); if(caretPos == 0) return ""; else { return code.substring(caretPos - 1, caretPos); } }
JTextPaneToolbox { public static String getCharToTheLeftOfCaret(JTextPane pane) { String code = getText(pane); int caretPos = pane.getCaretPosition(); if(caretPos == 0) return ""; else { return code.substring(caretPos - 1, caretPos); } } }
JTextPaneToolbox { public static String getCharToTheLeftOfCaret(JTextPane pane) { String code = getText(pane); int caretPos = pane.getCaretPosition(); if(caretPos == 0) return ""; else { return code.substring(caretPos - 1, caretPos); } }  }
JTextPaneToolbox { public static String getCharToTheLeftOfCaret(JTextPane pane) { String code = getText(pane); int caretPos = pane.getCaretPosition(); if(caretPos == 0) return ""; else { return code.substring(caretPos - 1, caretPos); } }  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 String getCharToTheLeftOfCaret(JTextPane pane) { String code = getText(pane); int caretPos = pane.getCaretPosition(); if(caretPos == 0) return ""; else { return code.substring(caretPos - 1, caretPos); } }  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);  }