X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Feditor%2FMatchingBracketsEditStrategy.java;h=68b3f638bc5860af2acc5d32e41b9456bbe4a354;hb=HEAD;hp=5a9b12e3979b469fa3749db6292dcf32d6eacd69;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/MatchingBracketsEditStrategy.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/MatchingBracketsEditStrategy.java old mode 100755 new mode 100644 index 5a9b12e39..68b3f638b --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/MatchingBracketsEditStrategy.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/MatchingBracketsEditStrategy.java @@ -1,39 +1,39 @@ -package org.simantics.scl.ui.editor; - -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; - -public class MatchingBracketsEditStrategy implements IAutoEditStrategy { - - char justAddedClosingBracket = (char)0; - - public void customizeDocumentCommand(IDocument d, DocumentCommand c) { - if (c.length == 0 && c.text != null) { - if(c.text.equals("(")) { - c.text = "()"; - justAddedClosingBracket = ')'; - } - else if(c.text.equals("[")) { - c.text = "[]"; - justAddedClosingBracket = ']'; - } - else { - if(c.text.length() == 1 && c.text.charAt(0) == justAddedClosingBracket) { - c.text = ""; - c.shiftsCaret = false; - c.caretOffset = c.offset+1; - } - justAddedClosingBracket = (char)0; - return; - } - - // Puts caret between brackets - c.caretOffset = c.offset+1; - c.shiftsCaret = false; - } - else - justAddedClosingBracket = (char)0; - } - -} +package org.simantics.scl.ui.editor; + +import org.eclipse.jface.text.DocumentCommand; +import org.eclipse.jface.text.IAutoEditStrategy; +import org.eclipse.jface.text.IDocument; + +public class MatchingBracketsEditStrategy implements IAutoEditStrategy { + + char justAddedClosingBracket = (char)0; + + public void customizeDocumentCommand(IDocument d, DocumentCommand c) { + if (c.length == 0 && c.text != null) { + if(c.text.equals("(")) { //$NON-NLS-1$ + c.text = "()"; //$NON-NLS-1$ + justAddedClosingBracket = ')'; + } + else if(c.text.equals("[")) { //$NON-NLS-1$ + c.text = "[]"; //$NON-NLS-1$ + justAddedClosingBracket = ']'; + } + else { + if(c.text.length() == 1 && c.text.charAt(0) == justAddedClosingBracket) { + c.text = ""; //$NON-NLS-1$ + c.shiftsCaret = false; + c.caretOffset = c.offset+1; + } + justAddedClosingBracket = (char)0; + return; + } + + // Puts caret between brackets + c.caretOffset = c.offset+1; + c.shiftsCaret = false; + } + else + justAddedClosingBracket = (char)0; + } + +}