1.1 --- a/PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlTypedBreakInterceptor.java Tue Apr 30 14:57:16 2013 +0200
1.2 +++ b/PLSQL/Formatter/src/org/netbeans/modules/plsql/format/PlsqlTypedBreakInterceptor.java Thu May 02 15:45:24 2013 +0200
1.3 @@ -1,21 +1,14 @@
1.4 -/*
1.5 - * To change this template, choose Tools | Templates
1.6 - * and open the template in the editor.
1.7 - */
1.8 package org.netbeans.modules.plsql.format;
1.9
1.10 import java.util.logging.Level;
1.11 import java.util.logging.Logger;
1.12 import javax.swing.text.BadLocationException;
1.13 -import javax.swing.text.Document;
1.14 import org.netbeans.api.editor.mimelookup.MimePath;
1.15 import org.netbeans.api.editor.mimelookup.MimeRegistration;
1.16 import org.netbeans.editor.BaseDocument;
1.17 +import org.netbeans.editor.Utilities;
1.18 import org.netbeans.modules.plsql.filetype.PlsqlDataLoader;
1.19 -import org.netbeans.modules.plsql.lexer.PlsqlBlockFactory;
1.20 -import org.netbeans.modules.plsql.lexer.PlsqlBlockType;
1.21 import org.netbeans.spi.editor.typinghooks.TypedBreakInterceptor;
1.22 -import org.openide.util.Lookup;
1.23
1.24 /**
1.25 *
1.26 @@ -34,9 +27,18 @@
1.27 @Override
1.28 public void insert(MutableContext context) throws BadLocationException {
1.29 LOG.log(Level.FINER, "insert, context: {0}", context);
1.30 - PlsqlBlockFactory blockFactory = getBlockFactory((BaseDocument) context.getDocument());
1.31 - if (blockFactory.isBlockAtOffsetOfType(context.getCaretOffset(), PlsqlBlockType.COMMENT)) {
1.32 + if (!(context.getDocument() instanceof BaseDocument)) {
1.33 + return;
1.34 + }
1.35 + BaseDocument doc = (BaseDocument) context.getDocument();
1.36 +
1.37 + int insertPos = context.getCaretOffset();
1.38 + int lineStartPos = Utilities.getRowStart(doc, insertPos);
1.39 + String word = Utilities.getWord(doc, lineStartPos);
1.40 + if (word.equals("--")) {
1.41 context.setText("\n-- ", 0, 5);
1.42 + } else if (word.equals("--------------------")) {
1.43 + context.setText("\n-------------------- ", 0, 22);
1.44 }
1.45 }
1.46
1.47 @@ -50,14 +52,6 @@
1.48 LOG.log(Level.FINER, "cancelled, context: {0}", context);
1.49 }
1.50
1.51 - private PlsqlBlockFactory getBlockFactory(BaseDocument doc) {
1.52 - final Object obj = doc.getProperty(Document.StreamDescriptionProperty);
1.53 - if (obj instanceof Lookup.Provider) {
1.54 - return ((Lookup.Provider) obj).getLookup().lookup(PlsqlBlockFactory.class);
1.55 - }
1.56 - return null;
1.57 - }
1.58 -
1.59 @MimeRegistration(mimeType = PlsqlDataLoader.REQUIRED_MIME, service = TypedBreakInterceptor.Factory.class)
1.60 public static class PlsqlFactory implements TypedBreakInterceptor.Factory {
1.61
2.1 --- a/PLSQL/Lexer/src/org/netbeans/modules/plsql/lexer/PlsqlBlockFactory.java Tue Apr 30 14:57:16 2013 +0200
2.2 +++ b/PLSQL/Lexer/src/org/netbeans/modules/plsql/lexer/PlsqlBlockFactory.java Thu May 02 15:45:24 2013 +0200
2.3 @@ -1226,23 +1226,6 @@
2.4 return currentName;
2.5 }
2.6
2.7 - public boolean isBlockAtOffsetOfType(int offset, PlsqlBlockType blockType) {
2.8 - return isBlockAtOffsetOfType(blockHierarchy, offset, blockType);
2.9 - }
2.10 -
2.11 - private boolean isBlockAtOffsetOfType(List<PlsqlBlock> blocks, int offset, PlsqlBlockType blockType) {
2.12 - for (PlsqlBlock plsqlBlock : blocks) {
2.13 - if (plsqlBlock.getStartOffset() <= offset && plsqlBlock.getEndOffset() >= offset && blockType == plsqlBlock.getType()) {
2.14 - return true;
2.15 - }
2.16 - final List<PlsqlBlock> childBlocks = plsqlBlock.getChildBlocks();
2.17 - if (isBlockAtOffsetOfType(childBlocks, offset, blockType)) {
2.18 - return true;
2.19 - }
2.20 - }
2.21 - return false;
2.22 - }
2.23 -
2.24 private static class EventProperties {
2.25
2.26 public int offset = -1;