[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    KDE/kdelibs/kate/jscript
From:       Dominik Haumann <dhdev () gmx ! de>
Date:       2007-07-19 22:26:37
Message-ID: 1184883997.474174.2853.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 690045 by dhaumann:

use the underlying default styles to check, whether the current char is valid code
or uninteresting part (like comments and strings).

The flow is as follows:
1. get the attribute list of the current highlighting
   (it uses the KateRenderer, is there another way to get the list?)
2. get the current attribute
3. use this attribute as index for the attribute list
4. read the property AttributeDefaultStyleIndex and convert it to int
5. now we have the current character's defaultStyle
6. check, whether the defaultStyle is usable
7. if so, count the braces...

Imo, this is much better than the hack in KDE3 (which used the itemData names).
Todo:
* find a good place for a mapping function from attribute<->defaultStyle
* refactor to avoid code duplication ;)
* write a usable indenter (ewh)

CCMAIL: kwrite-devel@kde.org


 M  +45 -4     katejscript.cpp  


--- trunk/KDE/kdelibs/kate/jscript/katejscript.cpp #690044:690045
@@ -27,6 +27,7 @@
 #include "kateautoindent.h"
 #include "katehighlight.h"
 #include "katetextline.h"
+#include "katerenderer.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -903,15 +904,35 @@
     case KateJSDocument::FindLeftBrace: {
       if (exception.invalidArgs(2)) break;
       KateDocCursor cursor(args[0]->toUInt32(exec), args[1]->toUInt32(exec), doc);
+      QList<KTextEditor::Attribute::Ptr> attributes =
+          doc->highlight()->attributes(((KateView*)doc->activeView())->renderer()->config()->schema());
       int count = 1;
 
       // Move backwards char by char and find the opening brace
       while (cursor.moveBackward(1)) {
         QChar ch = cursor.currentChar();
         if (ch == '{') {
-          --count;
+          KTextEditor::Attribute::Ptr a = attributes[cursor.currentAttrib()];
+          const int ds = a->property(KateExtendedAttribute::AttributeDefaultStyleIndex).toInt();
+          if (ds != KateExtendedAttribute::dsComment
+              && ds != KateExtendedAttribute::dsString
+              && ds != KateExtendedAttribute::dsRegionMarker
+              && ds != KateExtendedAttribute::dsChar
+              && ds != KateExtendedAttribute::dsOthers)
+          {
+            --count;
+          }
         } else if (ch == '}') {
-          ++count;
+          KTextEditor::Attribute::Ptr a = attributes[cursor.currentAttrib()];
+          const int ds = a->property(KateExtendedAttribute::AttributeDefaultStyleIndex).toInt();
+          if (ds != KateExtendedAttribute::dsComment
+              && ds != KateExtendedAttribute::dsString
+              && ds != KateExtendedAttribute::dsRegionMarker
+              && ds != KateExtendedAttribute::dsChar
+              && ds != KateExtendedAttribute::dsOthers)
+          {
+            ++count;
+          }
         }
 
         if (count == 0) {
@@ -928,15 +949,35 @@
     case KateJSDocument::FindLeftParenthesis: {
       if (exception.invalidArgs(2)) break;
       KateDocCursor cursor(args[0]->toUInt32(exec), args[1]->toUInt32(exec), doc);
+      QList<KTextEditor::Attribute::Ptr> attributes =
+          doc->highlight()->attributes(((KateView*)doc->activeView())->renderer()->config()->schema());
       int count = 1;
 
       // Move backwards char by char and find the opening parenthesis
       while (cursor.moveBackward(1)) {
         QChar ch = cursor.currentChar();
         if (ch == '(') {
-          --count;
+          KTextEditor::Attribute::Ptr a = attributes[cursor.currentAttrib()];
+          const int ds = a->property(KateExtendedAttribute::AttributeDefaultStyleIndex).toInt();
+          if (ds != KateExtendedAttribute::dsComment
+              && ds != KateExtendedAttribute::dsString
+              && ds != KateExtendedAttribute::dsRegionMarker
+              && ds != KateExtendedAttribute::dsChar
+              && ds != KateExtendedAttribute::dsOthers)
+          {
+            --count;
+          }
         } else if (ch == ')') {
-          ++count;
+          KTextEditor::Attribute::Ptr a = attributes[cursor.currentAttrib()];
+          const int ds = a->property(KateExtendedAttribute::AttributeDefaultStyleIndex).toInt();
+          if (ds != KateExtendedAttribute::dsComment
+              && ds != KateExtendedAttribute::dsString
+              && ds != KateExtendedAttribute::dsRegionMarker
+              && ds != KateExtendedAttribute::dsChar
+              && ds != KateExtendedAttribute::dsOthers)
+          {
+            ++count;
+          }
         }
 
         if (count == 0) {
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic