Java Code Examples for org.netbeans.editor.BaseDocument#remove()

The following examples show how to use org.netbeans.editor.BaseDocument#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPACompletionItem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void substituteText(JTextComponent c, int offset, int len, String toAdd) {
    BaseDocument doc = (BaseDocument) c.getDocument();
    CharSequence prefix = getInsertPrefix();
    String text = prefix.toString();
    if (toAdd != null) {
        text += toAdd;
    }

    doc.atomicLock();
    try {
        Position position = doc.createPosition(offset);
        doc.remove(offset, len);
        doc.insertString(position.getOffset(), text.toString(), null);
    } catch (BadLocationException ble) {
        // nothing can be done to update
    } finally {
        doc.atomicUnlock();
    }
}
 
Example 2
Source File: FormatContext.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void remove(int voffset, int vlength) {
    int offset = getDocumentOffset(voffset);
    if (offset < 0) {
        return;
    }
    int length = computeLength(voffset, vlength);
    if (length <= 0) {
        return;
    }

    BaseDocument doc = getDocument();
    try {
        if(doc.getText(offset + offsetDiff, length).contains("\n")) {
            LOGGER.log(Level.WARNING, "Tried to remove EOL");
        }
        if (SAFE_DELETE_PATTERN.matcher(doc.getText(offset + offsetDiff, length)).matches()) {
            doc.remove(offset + offsetDiff, length);
            setOffsetDiff(offsetDiff - length);
        } else {
            LOGGER.log(Level.WARNING, "Tried to remove non empty text: {0}",
                    doc.getText(offset + offsetDiff, length));
        }
    } catch (BadLocationException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }
}
 
Example 3
Source File: CompletionImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 
 * Consumes identifier part of text behind caret upto first non-identifier
 * char.
 */
private void consumeIdentifier() {
    JTextComponent comp = getActiveComponent();
    BaseDocument doc = (BaseDocument) comp.getDocument();
    int initCarPos = comp.getCaretPosition();
    int carPos = initCarPos;
    boolean nonChar = false;
    char c;
    try {
        while(nonChar == false) {
            c = doc.getChars(carPos, 1)[0];
            if(!Character.isJavaIdentifierPart(c)) {
                nonChar = true;
            }
            carPos++;
        }
        doc.remove(initCarPos, carPos - initCarPos -1);
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 4
Source File: PhpDeletedTextInterceptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Context context) throws BadLocationException  {
    BaseDocument doc = (BaseDocument) context.getDocument();
    int dotPos = context.getOffset() - 1;
    if (TypingHooksUtils.isInsertMatchingEnabled()) {
        char tokenAtDot = LexUtilities.getTokenChar(doc, dotPos);
        if (tokenAtDot == getClosingBracket() && LexUtilities.getTokenBalance(doc, getOpeningBracket(), getClosingBracket(), dotPos) != 0) {
            doc.remove(dotPos, 1);
        }
    }
}
 
Example 5
Source File: TwigDeletedTextInterceptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Context context) throws BadLocationException {
    if (TypingHooksUtils.isInsertMatchingEnabled()) {
        BaseDocument doc = (BaseDocument) context.getDocument();
        int dotPos = context.getOffset() - 1;
        if (TypingHooksUtils.sameAsExistingChar(doc, getClosingBracket(), dotPos)
                && TwigLexerUtils.getTokenBalance(doc, getOpeningBracket(), getClosingBracket(), dotPos) < 0) {
            // opening bracket is already removed
            doc.remove(dotPos, 1);
        }
    }
}
 
Example 6
Source File: InsertSemicolonAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    if (!target.isEditable() || !target.isEnabled()) {
        target.getToolkit().beep();
        return;
    }
    final BaseDocument doc = (BaseDocument) target.getDocument();
    final Indent indenter = Indent.get(doc);
    final class R implements Runnable {
        public @Override void run() {
            try {
                Caret caret = target.getCaret();
                int dotpos = caret.getDot();
                int eoloffset = Utilities.getRowEnd(target, dotpos);
                doc.insertString(eoloffset, "" + what, null); //NOI18N
                if (withNewline) {
                    //This is code from the editor module, but it is
                    //a pretty strange way to do this:
                    doc.insertString(dotpos, "-", null); //NOI18N
                    doc.remove(dotpos, 1);
                    int eolDot = Utilities.getRowEnd(target, caret.getDot());
                    int newDotPos = indenter.indentNewLine(eolDot);
                    caret.setDot(newDotPos);
                }
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    indenter.lock();
    try {
        doc.runAtomicAsUser(new R());
    } finally {
        indenter.unlock();
    }
}
 
Example 7
Source File: FormatContext.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void replace(int voffset, int vlength, String newString) {
    int offset = getDocumentOffset(voffset);
    if (offset < 0) {
        return;
    }
    int length = computeLength(voffset, vlength);
    if (length <= 0) {
        insert(voffset, newString);
        return;
    }

    BaseDocument doc = getDocument();
    try {
        String oldText = doc.getText(offset + offsetDiff, length);
        if (newString.equals(oldText)) {
            return;
        }
        if (SAFE_DELETE_PATTERN.matcher(oldText).matches()) {
            doc.remove(offset + offsetDiff, length);
            doc.insertString(offset + offsetDiff, newString, null);
            setOffsetDiff(offsetDiff + (newString.length() - length));
        } else {
            LOGGER.log(Level.WARNING, "Tried to remove non empty text: {0}",
                    doc.getText(offset + offsetDiff, length));
        }
    } catch (BadLocationException ex) {
        LOGGER.log(Level.INFO, null, ex);
    }
}
 
Example 8
Source File: ToggleBlockCommentAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void uncomment(BaseDocument baseDocument, TokenSequence<? extends LatteTopTokenId> topTs) {
    moveToOpeningCommentDelimiter(topTs);
    int start = topTs.offset() + topTs.token().length() - COMMENT_DELIMITER_PART_LENGTH;
    moveToClosingCommentDelimiter(topTs);
    int end = topTs.offset() - COMMENT_DELIMITER_PART_LENGTH;
    try {
        baseDocument.remove(start, COMMENT_DELIMITER_PART_LENGTH);
        baseDocument.remove(end, COMMENT_DELIMITER_PART_LENGTH);
    } catch (BadLocationException ex) {
        LOGGER.log(Level.WARNING, null, ex);
    }
}
 
Example 9
Source File: ExtFormatter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Reformat a block of code.
* @param doc document to work with
* @param startOffset position at which the formatting starts
* @param endOffset position at which the formatting ends
* @param indentOnly whether just the indentation should be changed
*  or regular formatting should be performed.
* @return formatting writer. The text was already reformatted
*  but the writer can contain useful information.
*/
public Writer reformat(BaseDocument doc, int startOffset, int endOffset, boolean indentOnly) throws BadLocationException, IOException {
    pushFormattingContextDocument(doc);
    try {
        CharArrayWriter cw = new CharArrayWriter();
        Writer w = createWriter(doc, startOffset, cw);
        FormatWriter fw = (w instanceof FormatWriter) ? (FormatWriter)w : null;

        boolean fix5620 = true; // whether apply fix for #5620 or not

        if (fw != null) {
            fw.setIndentOnly(indentOnly);
            if (fix5620) {
                fw.setReformatting(true); // #5620
            }
        }

        w.write(doc.getChars(startOffset, endOffset - startOffset));
        w.close();

        if (!fix5620 || fw == null) { // #5620 - for (fw != null) the doc was already modified
            String out = new String(cw.toCharArray());
            doc.remove(startOffset, endOffset - startOffset);
            doc.insertString(startOffset, out, null);
        }

        return w;
    } finally {
        popFormattingContextDocument(doc);
    }
}
 
Example 10
Source File: GroovyDeletedTextInterceptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void remove(Context context) throws BadLocationException {
    final BaseDocument doc = (BaseDocument) context.getDocument();
    final char ch = context.getText().charAt(0);
    final int dotPos = context.getOffset() - 1;

    switch (ch) {

        case '{':
        case '(':
        case '[': { // and '{' via fallthrough
            char tokenAtDot = LexUtilities.getTokenChar(doc, dotPos);

            if (((tokenAtDot == ']')
                    && (LexUtilities.getTokenBalance(doc, GroovyTokenId.LBRACKET, GroovyTokenId.RBRACKET, dotPos) != 0))
                    || ((tokenAtDot == ')')
                    && (LexUtilities.getTokenBalance(doc, GroovyTokenId.LPAREN, GroovyTokenId.RPAREN, dotPos) != 0))
                    || ((tokenAtDot == '}')
                    && (LexUtilities.getTokenBalance(doc, GroovyTokenId.LBRACE, GroovyTokenId.RBRACE, dotPos) != 0))) {
                doc.remove(dotPos, 1);
            }
            break;
        }

        case '|':
        case '\"':
        case '\'':
            char[] match = doc.getChars(dotPos, 1);

            if ((match != null) && (match[0] == ch)) {
                doc.remove(dotPos, 1);
            }
    }
}
 
Example 11
Source File: GroovyTypedTextInterceptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Called to add semicolon after bracket for some conditions
 *
 * @param context
 * @return relative caretOffset change
 * @throws BadLocationException
 */
private static boolean moveSemicolon(BaseDocument doc, int dotPos, Caret caret) throws BadLocationException {
    TokenSequence<GroovyTokenId> ts = LexUtilities.getPositionedSequence(doc, dotPos);
    if (ts == null || isStringOrComment(ts.token().id())) {
        return false;
    }
    int lastParenPos = dotPos;
    int index = ts.index();
    // Move beyond semicolon
    while (ts.moveNext() && !(ts.token().id() == GroovyTokenId.NLS)) {
        switch (ts.token().id()) {
            case RPAREN:
                lastParenPos = ts.offset();
                break;
            case WHITESPACE:
                break;
            default:
                return false;
        }
    }
    // Restore javaTS position
    ts.moveIndex(index);
    ts.moveNext();
    if (isForLoopOrTryWithResourcesSemicolon(ts) || posWithinAnyQuote(doc, dotPos, ts) || (lastParenPos == dotPos && !ts.token().id().equals(GroovyTokenId.RPAREN))) {
        return false;
    }
    
    doc.remove(dotPos, 1);
    doc.insertString(lastParenPos, ";", null); // NOI18N
    caret.setDot(lastParenPos + 1);
    return true;
}
 
Example 12
Source File: BraceCompletionDeleteAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void charBackspaced (
    BaseDocument        document, 
    int                 offset, 
    Caret               caret, 
    char                character
) throws BadLocationException {
    TokenSequence tokenSequence = Utils.getTokenSequence (document, offset);
    if (tokenSequence != null) {
        String mimeType = tokenSequence.language ().mimeType ();
        try {
            Language l = LanguagesManager.getDefault ().getLanguage (mimeType);
            List<Feature> completes = l.getFeatureList ().getFeatures ("COMPLETE");
            Iterator<Feature> it = completes.iterator ();
            while (it.hasNext ()) {
                Feature complete = it.next ();
                if (complete.getType () != Feature.Type.STRING)
                    continue;
                String s = (String) complete.getValue ();
                int i = s.indexOf (':');
                if (i != 1) continue;
                String ss = document.getText (
                    caret.getDot (), 
                    s.length () - i - 1
                );
                if (s.endsWith (ss) && 
                    s.charAt (0) == character
                ) {
                    document.remove (caret.getDot (), s.length () - i - 1);
                    return;
                }
            }
        } catch (LanguageDefinitionNotFoundException ex) {
            // ignore the exception
        }
    }
    super.charBackspaced (document, offset, caret, character);
}
 
Example 13
Source File: YamlKeystrokeHandler.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public int beforeBreak(Document document, int offset, JTextComponent target) throws BadLocationException {

    Caret caret = target.getCaret();
    BaseDocument doc = (BaseDocument) document;

    // Very simple algorithm for now..
    // Basically, use the same indent as the current line, unless the caret is immediately preceeded by a ":" (possibly with whitespace
    // in between)

    int lineBegin = Utilities.getRowStart(doc, offset);
    int lineEnd = Utilities.getRowEnd(doc, offset);

    if (lineBegin == offset && lineEnd == offset) {
        // Pressed return on a blank newline - do nothing
        return -1;
    }

    int indent = getLineIndent(doc, offset);
    String linePrefix = doc.getText(lineBegin, offset - lineBegin);
    String lineSuffix = doc.getText(offset, lineEnd + 1 - offset);
    if (linePrefix.trim().endsWith(":") && lineSuffix.trim().length() == 0) {
        // Yes, new key: increase indent
        indent += IndentUtils.getIndentSize(doc);
    } else {
        // No, just use same indent as parent
    }

    // Also remove the whitespace from the caret up to the first nonspace character on the current line
    int remove = 0;
    String line = doc.getText(lineBegin, lineEnd + 1 - lineBegin);
    for (int n = line.length(), i = offset - lineBegin; i < n; i++) {
        char c = line.charAt(i);
        if (c == ' ' || c == '\t') {
            remove++;
        } else {
            break;
        }
    }
    if (remove > 0) {
        doc.remove(offset, remove);
    }
    String str = IndentUtils.getIndentString(indent);
    int newPos = offset + str.length();
    doc.insertString(offset, str, null);
    caret.setDot(offset);
    return newPos + 1;
}
 
Example 14
Source File: BeansCompletionItem.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean substituteText(JTextComponent c, int offset, int len, boolean shifted) {
    BaseDocument doc = (BaseDocument) c.getDocument();
    String text = getSubstitutionText();

    if (text != null) {
        if (toAdd != null && !toAdd.equals("\n")) // NOI18N
        {
            text += toAdd;
        }
        // Update the text
        doc.atomicLock();
        try {
            String textToReplace = doc.getText(offset, len);
            if (text.equals(textToReplace)) {
                return false;
            }

            if(!shifted) {//we are not in part of literal completion
                //dirty hack for @Table(name=CUS|
                if (!text.startsWith("\"")) {
                    text = quoteText(text);
                }

                //check if there is already an end quote
                char ch = doc.getText(offset + len, 1).charAt(0);
                if (ch == '"') {
                    //remove also this end quote since the inserted value is always quoted
                    len++;
                }
            }

            doc.remove(offset, len);
            doc.insertString(offset, text, null);
        } catch (BadLocationException e) {
            // Can't update
        } finally {
            doc.atomicUnlock();
        }
        return true;

    } else {
        return false;
    }
}
 
Example 15
Source File: ToggleBlockCommentAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void uncommentToken(TokenSequence<? extends TwigTopTokenId> ts, BaseDocument baseDocument) throws BadLocationException {
    int start = ts.offset();
    int end = ts.offset() + ts.token().text().length() - TwigTopLexer.OPEN_COMMENT.length() - TwigTopLexer.CLOSE_COMMENT.length();
    baseDocument.remove(start, TwigTopLexer.OPEN_COMMENT.length());
    baseDocument.remove(end, TwigTopLexer.CLOSE_COMMENT.length());
}
 
Example 16
Source File: PHPFormatterTestBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void reformatFileContents(String file, Map<String, Object> options, boolean isTemplate, IndentPrefs indentPrefs) throws Exception {
    FileObject fo = getTestFile(file);
    assertNotNull(fo);

    String text = read(fo);

    int formatStart = 0;
    int formatEnd = text.length();
    int startMarkPos = text.indexOf(FORMAT_START_MARK);

    if (startMarkPos >= 0) {
        formatStart = startMarkPos;
        text = text.substring(0, formatStart) + text.substring(formatStart + FORMAT_START_MARK.length());
        formatEnd = text.indexOf(FORMAT_END_MARK);
        text = text.substring(0, formatEnd) + text.substring(formatEnd + FORMAT_END_MARK.length());
        GSFPHPParserTestUtil.setUnitTestCaretPosition(formatEnd);
        if (!isTemplate) {
            formatEnd --;
        }
        if (formatEnd == -1) {
            throw new IllegalStateException();
        }
    }

    BaseDocument doc = getDocument(text);
    assertNotNull(doc);

    if (isTemplate) {
        int carretPosition = text.indexOf('^');
        if (carretPosition == -1) {
            carretPosition = formatEnd;
        } else {
            if (carretPosition < formatStart) {
                formatStart--;
            }
            if (carretPosition < formatEnd) {
                formatEnd--;
            }
            text = text.substring(0, carretPosition) + text.substring(carretPosition + 1);
        }

        TokenFormatter.setUnitTestCarretPosition(carretPosition);
        GSFPHPParserTestUtil.setUnitTestCaretPosition(carretPosition);
        doc.remove(0, doc.getLength());
        doc.insertString(0, text, null);
        doc.putProperty(TokenFormatter.TEMPLATE_HANDLER_PROPERTY, new Object());
    }

    Formatter formatter = getFormatter(indentPrefs);
    //assertNotNull("getFormatter must be implemented", formatter);

    setupDocumentIndentation(doc, indentPrefs);

    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
    for (String option : options.keySet()) {
        Object value = options.get(option);
        if (value instanceof Integer) {
            prefs.putInt(option, ((Integer) value).intValue());
        } else if (value instanceof String) {
            prefs.put(option, (String) value);
        } else if (value instanceof Boolean) {
            prefs.put(option, ((Boolean) value).toString());
        } else if (value instanceof CodeStyle.BracePlacement) {
            prefs.put(option, ((CodeStyle.BracePlacement) value).name());
        } else if (value instanceof CodeStyle.WrapStyle) {
            prefs.put(option, ((CodeStyle.WrapStyle) value).name());
        }
    }

    format(doc, formatter, formatStart, formatEnd, false);
    String after = doc.getText(0, doc.getLength());
    assertDescriptionMatches(file, after, false, ".formatted");
    GSFPHPParserTestUtil.setUnitTestCaretPosition(-1);
}
 
Example 17
Source File: FormatContext.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static int setLineIndentation(BaseDocument doc, int lineOffset,
        int newIndent, CodeStyle.Holder codeStyle) throws BadLocationException {
    int lineStartOffset = Utilities.getRowStart(doc, lineOffset);

    // Determine old indent first together with oldIndentEndOffset
    int indent = 0;
    int tabSize = -1;
    CharSequence docText = DocumentUtilities.getText(doc);
    int oldIndentEndOffset = lineStartOffset;
    while (oldIndentEndOffset < docText.length()) {
        char ch = docText.charAt(oldIndentEndOffset);
        if (ch == '\n') {
            break;
        } else if (ch == '\t') {
            if (tabSize == -1) {
                tabSize = codeStyle.tabSize;
            }
            // Round to next tab stop
            indent = (indent + tabSize) / tabSize * tabSize;
        } else if (Character.isWhitespace(ch)) {
            indent++;
        } else { // non-whitespace
            break;
        }
        oldIndentEndOffset++;
    }

    String newIndentString = IndentUtils.createIndentString(newIndent, codeStyle.expandTabsToSpaces, codeStyle.tabSize);
    // Attempt to match the begining characters
    int offset = lineStartOffset;
    boolean different = false;
    int i = 0;
    for (; i < newIndentString.length() && lineStartOffset + i < oldIndentEndOffset; i++) {
        if (newIndentString.charAt(i) != docText.charAt(lineStartOffset + i)) {
            offset = lineStartOffset + i;
            newIndentString = newIndentString.substring(i);
            different = true;
            break;
        }
    }
    if (!different) {
        offset = lineStartOffset + i;
        newIndentString = newIndentString.substring(i);
    }

    // Replace the old indent
    if (offset < oldIndentEndOffset) {
        doc.remove(offset, oldIndentEndOffset - offset);
    }
    if (newIndentString.length() > 0) {
        doc.insertString(offset, newIndentString, null);
    }
    return newIndentString.length() - (oldIndentEndOffset - offset);
}
 
Example 18
Source File: GsfUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Adjust the indentation of the line containing the given offset to the provided
 * indentation, and return the length difference of old and new indentation.
 *
 * Copied from Indent module's "modifyIndent"
 */
public static int setLineIndentation(BaseDocument doc, int lineOffset, int newIndent) throws BadLocationException {
    int lineStartOffset = Utilities.getRowStart(doc, lineOffset);

    // Determine old indent first together with oldIndentEndOffset
    int indent = 0;
    int tabSize = -1;
    CharSequence docText = DocumentUtilities.getText(doc);
    int oldIndentEndOffset = lineStartOffset;
    while (oldIndentEndOffset < docText.length()) {
        char ch = docText.charAt(oldIndentEndOffset);
        if (ch == '\n') {
            break;
        } else if (ch == '\t') {
            if (tabSize == -1) {
                tabSize = IndentUtils.tabSize(doc);
            }
            // Round to next tab stop
            indent = (indent + tabSize) / tabSize * tabSize;
        } else if (Character.isWhitespace(ch)) {
            indent++;
        } else { // non-whitespace
            break;
        }
        oldIndentEndOffset++;
    }

    String newIndentString = IndentUtils.createIndentString(doc, newIndent);
    // Attempt to match the begining characters
    int offset = lineStartOffset;
    boolean different = false;
    int i = 0;
    for (; i < newIndentString.length() && lineStartOffset + i < oldIndentEndOffset; i++) {
        if (newIndentString.charAt(i) != docText.charAt(lineStartOffset + i)) {
            offset = lineStartOffset + i;
            newIndentString = newIndentString.substring(i);
            different = true;
            break;
        }
    }
    if (!different) {
        offset = lineStartOffset + i;
        newIndentString = newIndentString.substring(i);
    }

    // Replace the old indent
    if (offset < oldIndentEndOffset) {
        doc.remove(offset, oldIndentEndOffset - offset);
    }
    if (newIndentString.length() > 0) {
        doc.insertString(offset, newIndentString, null);
    }
    return newIndentString.length() - (oldIndentEndOffset - offset);
}
 
Example 19
Source File: GroovyTypedTextInterceptor.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * A hook to be called after closing bracket ) or ] was inserted into
 * the document. The method checks if the bracket should stay there
 * or be removed and some exisitng bracket just skipped.
 *
 * @param doc the document
 * @param dotPos position of the inserted bracket
 * @param caret caret
 * @param bracket the bracket character ']' or ')'
 */
private void skipClosingBracket(BaseDocument doc, Caret caret, char bracket, TokenId bracketId)
    throws BadLocationException {
    int caretOffset = caret.getDot();

    if (isSkipClosingBracket(doc, caretOffset, bracketId)) {
        doc.remove(caretOffset - 1, 1);
        caret.setDot(caretOffset); // skip closing bracket
    }
}
 
Example 20
Source File: PhpTypedTextInterceptor.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * A hook to be called after closing bracket ) or ] was inserted into the
 * document. The method checks if the bracket should stay there or be
 * removed and some exisitng bracket just skipped.
 *
 * @param doc the document
 * @param dotPos position of the inserted bracket
 * @param caret caret
 * @param bracket the bracket character ']' or ')'
 */
private void skipClosingBracket(BaseDocument doc, Caret caret, char bracket) throws BadLocationException {
    int caretOffset = caret.getDot();
    if (isSkipClosingBracket(doc, caretOffset, bracket)) {
        doc.remove(caretOffset - 1, 1);
        caret.setDot(caretOffset); // skip closing bracket
    }
}