@Override public void replace(FilterBypass fb,
                                          int          offset,
                                          int          length,
                                          String       text,
                                          AttributeSet attrs)
                                   throws BadLocationException {
                int moveCaretLeft = 0;
                boolean singleCharacter = text.length() == 1;
                // avoid new lines, etc, see
                // https://bitbucket.org/coderazzi/tablefilter-swing/issue/
                //   13/nullpointerexception-when-pasting-a-string
                text = newLinePattern.matcher(text).replaceAll(" ");
                if (autoCompletion && userUpdate && singleCharacter) {
                    String now = getText();
                    // autocompletion is only triggered if the user inputs
                    // a character at the end of the current text
                    if (now.length() == (offset + length)) {
                        String begin = now.substring(0, offset) + text;
                        String completion = popup.getCompletion(begin);
                        text += completion;
                        moveCaretLeft = completion.length();
                    }
                }

                super.replace(fb, offset, length, text, attrs);
                editorUpdated();
                // the 'completion' part remains selected, for easily removal
                if (moveCaretLeft > 0) {
                    int caret = getDocument().getLength();
                    setCaretPosition(caret);
                    moveCaretPosition(caret - moveCaretLeft);
                }
            }
@Override public void replace(FilterBypass fb,
                                          int          offset,
                                          int          length,
                                          String       text,
                                          AttributeSet attrs)