1 package org.simantics.scl.ui.editor;
3 import org.eclipse.jface.text.DocumentCommand;
4 import org.eclipse.jface.text.IAutoEditStrategy;
5 import org.eclipse.jface.text.IDocument;
7 public class MatchingBracketsEditStrategy implements IAutoEditStrategy {
9 char justAddedClosingBracket = (char)0;
11 public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
12 if (c.length == 0 && c.text != null) {
13 if(c.text.equals("(")) {
15 justAddedClosingBracket = ')';
17 else if(c.text.equals("[")) {
19 justAddedClosingBracket = ']';
22 if(c.text.length() == 1 && c.text.charAt(0) == justAddedClosingBracket) {
24 c.shiftsCaret = false;
25 c.caretOffset = c.offset+1;
27 justAddedClosingBracket = (char)0;
31 // Puts caret between brackets
32 c.caretOffset = c.offset+1;
33 c.shiftsCaret = false;
36 justAddedClosingBracket = (char)0;