void (InsertionContext context) { final Document document = context.getDocument(); final CharSequence sequence = document.getCharsSequence(); int offset = context.getStartOffset() - 1; while (offset >= 0) { final char c = sequence.charAt(offset); if (c != ' ' && c != '\t') { if (c == '\n') { offset--; } else { offset = context.getStartOffset() - 1; } break; } offset--; } document.deleteString(offset + 1, context.getTailOffset()); context.commitDocument(); }