@Override public void customizeDocumentCommand(IDocument d, DocumentCommand c) { try { if ("-".equals(c.text) && c.offset >= 3 && d.get(c.offset - 3, 3).equals("<!-")) { c.text = "- -->"; c.shiftsCaret = false; c.caretOffset = c.offset + 2; c.doit = false; return; } if ("[".equals(c.text) && c.offset >= 2 && d.get(c.offset - 2, 2).equals("<!")) { c.text = "[CDATA[]]>"; c.shiftsCaret = false; c.caretOffset = c.offset + 7; c.doit = false; return; } if ("l".equals(c.text) && c.offset >= 4 && d.get(c.offset - 4, 4).equals("<?xm")) { c.text = "l version = \"1.0\" encoding = \"" + charset + "\"?>"; return; } } catch (BadLocationException e) { HTMLPlugin.logException(e); } super.customizeDocumentCommand(d, c); }
@Override public void customizeDocumentCommand(IDocument d, DocumentCommand c) { try { // if("%".equals(c.text) && c.offset > 0){ // if(d.getChar(c.offset - 1) == '<'){ // c.text = "% %>"; // c.shiftsCaret = false; // c.caretOffset = c.offset + 1; // c.doit = false; // return; // } // } if ("{".equals(c.text) && c.offset > 0) { if (d.getChar(c.offset - 1) == '$') { c.text = "{}"; c.shiftsCaret = false; c.caretOffset = c.offset + 1; c.doit = false; return; } } if ("-".equals(c.text) && c.offset >= 3 && d.get(c.offset - 3, 3).equals("<%-")) { c.text = "- --%>"; c.shiftsCaret = false; c.caretOffset = c.offset + 2; c.doit = false; return; } } catch (BadLocationException e) { HTMLPlugin.logException(e); } super.customizeDocumentCommand(d, c); }
private void handleSmartTrigger(IDocument document, char trigger, int referenceOffset) throws BadLocationException { DocumentCommand cmd = new DocumentCommand() {}; cmd.offset = referenceOffset; cmd.length = 0; cmd.text = Character.toString(trigger); cmd.doit = true; cmd.shiftsCaret = true; cmd.caretOffset = getReplacementOffset() + getCursorPosition(); SmartSemicolonAutoEditStrategy strategy = new SmartSemicolonAutoEditStrategy(DartPartitions.DART_PARTITIONING); strategy.customizeDocumentCommand(document, cmd); replace(document, cmd.offset, cmd.length, cmd.text); setCursorPosition(cmd.caretOffset - getReplacementOffset() + cmd.text.length()); }