[prev in list] [next in list] [prev in thread] [next in thread]
List: kwrite-devel
Subject: KDE/kdelibs/kate/script
From: Christoph Cullmann <cullmann () kde ! org>
Date: 2010-05-11 19:22:13
Message-ID: 20100511192213.E0D71AC8B2 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1125583 by cullmann:
mwolff:
when placing cursor between {} and pressing return, properly indent:
if () {}
becomes
if () {
|
}
it feels kinda hackish but works rather well. please review
CCMAIL: kwrite-devel@kde.org
M +17 -1 data/cstyle.js
M +5 -0 katescriptdocument.cpp
M +2 -0 katescriptdocument.h
--- trunk/KDE/kdelibs/kate/script/data/cstyle.js #1125582:1125583
@@ -561,6 +561,22 @@
return indentation;
}
+/// called when a newline got inserted before a closing brace
+function tryMatchedBrace(line)
+{
+ var indentation = findLeftBrace(line, document.firstColumn(line));
+ if (indentation == -1) {
+ // no opening brace found
+ return indentation;
+ }
+ // otherwise it's found, increase indentation and place closing brace on the next line
+ document.insertText(line, document.firstColumn(line), "\n");
+ view.setCursorPosition(line, indentation);
+ // indent closing brace
+ document.indent(new Range(line + 1, 0, line + 1, 1), indentation / 2);
+ return indentation + gIndentWidth;
+}
+
/**
* Indent line.
* Return filler or null.
@@ -573,7 +589,7 @@
var filler = -1;
if (filler == -1 && firstChar == '}')
- filler = findLeftBrace(line, document.firstColumn(line));
+ filler = tryMatchedBrace(line);
if (filler == -1)
filler = tryCComment(line);
if (filler == -1 && !alignOnly)
--- trunk/KDE/kdelibs/kate/script/katescriptdocument.cpp #1125582:1125583
@@ -676,5 +676,10 @@
&& defaultStyle != KTextEditor::HighlightInterface::dsOthers);
}
+void KateScriptDocument::indent(KTextEditor::Range range, int change)
+{
+ m_document->indent(range, change);
+}
+
// kate: space-indent on; indent-width 2; replace-tabs on;
--- trunk/KDE/kdelibs/kate/script/katescriptdocument.h #1125582:1125583
@@ -172,6 +172,8 @@
Q_INVOKABLE bool startsWith (int line, const QString &pattern, bool skipWhiteSpaces);
Q_INVOKABLE bool endsWith (int line, const QString &pattern, bool skipWhiteSpaces);
+ Q_INVOKABLE void indent(KTextEditor::Range range, int change);
+
private:
bool _isCode(int defaultStyle);
_______________________________________________
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