Permalink
Browse files

Add auto-indentation

  • Loading branch information...
xept90
xept90 committed Dec 31, 2010
1 parent b569ae5 commit db73228863600aaa39bb735998f090f2b6397925
Showing with 21 additions and 5 deletions.
  1. +1 −0 config.txt
  2. +1 −2 highlighter.cpp
  3. +1 −0 highlighter.h
  4. +1 −1 readme.txt
  5. +2 −2 syntax/cpp.syn
  6. +15 −0 textedit.cpp
View
@@ -7,4 +7,5 @@ Font-color: #00ff18
Font-bold: false
Font-italic: false
Font-underline: false
+Tab-width: 20
View
@@ -1,5 +1,4 @@
#include "highlighter.h"
-#include <QColor>
Highlighter::Highlighter(Editor * editor, QTextDocument *parent) : QSyntaxHighlighter(parent)
{
@@ -99,7 +98,7 @@ void Highlighter::loadSyntax(QString filename){
// Load data
QString data = editor->fileToStr(filename);
// Find separator *******************************************
- int i = data.indexOf("Separator:");
+ int i = data.indexOf("separator:");
if (i == -1) return;
QString sep = data.mid(i+10,1);
// Find inlinewords *****************************************
View
@@ -9,6 +9,7 @@
#include <QVector>
#include <QTextFormat>
#include <QFont>
+#include <QColor>
class Editor;
View
@@ -1,4 +1,4 @@
-CodeRoom v0.1.5 Alpha
+CodeRoom v0.1.5 Development
Keyboard commands:
Ctrl + S: Save
View
@@ -1,7 +1,7 @@
// Language: C++
// Version: 0.1
-Separator:,
+separator:,
inlinewords:
*, \, ?, ^, +, -, /, %, >, <, =, &, |, !,.,;
@@ -39,7 +39,7 @@ italic: false
underline: false
freewords:
-return, if, else, elseif, break, continue, case, switch, for, while, do, throw, catch, try
+return, if, else, break, continue, case, switch, for, while, do, throw, catch, try
color: #FF0000
bold: false
italic: false
View
@@ -10,6 +10,21 @@ TextEdit::TextEdit(Editor * parent) : QTextEdit(parent){
void TextEdit::keyPressEvent(QKeyEvent * event){
// Keep functionality of QTextEdit
QTextEdit::keyPressEvent(event);
+ // Auto-indentation
+ if (event->key() == Qt::Key_Return) {
+ QString data = editor->dataToStr();
+ int cursorPosition = this->textCursor().position();
+ int i;
+ for (i=cursorPosition-2; i>=0; i--){
+ if (data.mid(i,1) == "\n") {
+ break;
+ }
+ }
+ while (data.mid(i+1,1) == "\t"){
+ this->textCursor().insertText("\t");
+ i++;
+ }
+ }
// Save file
if (event->key() == Qt::Key_S && event->modifiers() == Qt::ControlModifier) {
editor->saveFile();

0 comments on commit db73228

Please sign in to comment.