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

List:       kde-commits
Subject:    KDE/kdelibs/kate
From:       Pascal Létourneau <pascal.letourneau () gmail ! com>
Date:       2010-11-07 19:30:25
Message-ID: 20101107193025.E57E1AC8A0 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1193975 by pletourn:

Fix commenting empty lines

BUG:233210


 M  +12 -23    document/katedocument.cpp  
 M  +5 -0      syntax/katehighlight.cpp  


--- trunk/KDE/kdelibs/kate/document/katedocument.cpp #1193974:1193975
@@ -3280,35 +3280,24 @@
 */
 void KateDocument::comment( KateView *v, uint line,uint column, int change)
 {
-  // We need to check that we can sanely comment the selectino or region.
-  // It is if the attribute of the first and last character of the range to
-  // comment belongs to the same language definition.
-  // for lines with no text, we need the attribute for the lines context.
   bool hassel = v->selection();
-  int startAttrib;
+  int l = line;
+  int c = 0;
+ 
   if ( hassel )
   {
-    Kate::TextLine ln = kateTextLine( v->selectionRange().start().line() );
-    int l = v->selectionRange().start().line(), c = v->selectionRange().start().column();
-    startAttrib = nextNonSpaceCharPos( l, c ) ? kateTextLine( l )->attribute( c ) : 0;
+    l = v->selectionRange().start().line();
+    c = v->selectionRange().start().column();
   }
-  else
-  {
+
+  int startAttrib = 0;
     Kate::TextLine ln = kateTextLine( line );
-    if ( ln->length() )
-    {
-      startAttrib = ln->attribute( ln->firstChar() );
-    }
-    else
-    {
-      int l = line, c = 0;
-      if ( nextNonSpaceCharPos( l, c )  || previousNonSpaceCharPos( l, c ) )
-        startAttrib = kateTextLine( l )->attribute( c );
-      else
-        startAttrib = 0;
-    }
-  }
 
+  if ( c < ln->length() )
+    startAttrib = ln->attribute( c );
+  else if ( !ln->ctxArray().isEmpty() )
+    startAttrib = highlight()->attribute( ln->ctxArray().last() );
+
   bool hasStartLineCommentMark = !(highlight()->getCommentSingleLineStart( startAttrib ).isEmpty());
   bool hasStartStopCommentMark = ( !(highlight()->getCommentStart( startAttrib ).isEmpty())
       && !(highlight()->getCommentEnd( startAttrib ).isEmpty()) );
--- trunk/KDE/kdelibs/kate/syntax/katehighlight.cpp #1193974:1193975
@@ -987,6 +987,11 @@
   return tmpItem;
 }
 
+int KateHighlighting::attribute(int ctx) const
+{
+  return m_contexts[ctx]->attr;
+}
+
 bool KateHighlighting::attributeRequiresSpellchecking( int attr )
 {
   QList<KTextEditor::Attribute::Ptr> attributeList = attributes("");
[prev in list] [next in list] [prev in thread] [next in thread] 

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