void (char ch) { Document document = editor.getDocument(); int offset = editor.getCaretModel().getOffset(); CharSequence sequence = document.getCharsSequence(); while (offset > 0 && sequence.charAt(offset) != ch) { offset--; } editor.getCaretModel().moveToOffset(offset); }