Skip to content

Commit

Permalink
liteeditor : tab to space
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Dec 27, 2012
1 parent e475a3c commit d19e891
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
7 changes: 7 additions & 0 deletions liteidex/src/plugins/liteeditor/liteeditorfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ bool LiteEditorFile::open(const QString &fileName, const QString &mimeType, bool
}
}

int tab = m_liteApp->settings()->value(EDITOR_TABWIDTH+m_mimeType,4).toInt();
int useSpace = m_liteApp->settings()->value(EDITOR_TABUSESPACE+m_mimeType,false).toBool();
if (!m_hasDecodingError && useSpace) {
QString space(tab,' ');
text.replace('\t',space);
}

m_document->setPlainText(text);
return true;
}
Expand Down
23 changes: 12 additions & 11 deletions liteidex/src/plugins/liteeditor/liteeditorwidgetbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,23 +1126,24 @@ void LiteEditorWidgetBase::indentBlock(QTextBlock block, bool bIndent)

void LiteEditorWidgetBase::indentCursor(QTextCursor cur, bool bIndent)
{
cur.beginEditBlock();
cur.beginEditBlock();
if (bIndent) {
cur.insertText(this->tabText());
} else {
} else {
QString text = cur.block().text();
int pos = cur.positionInBlock();
if (pos >= 0 && pos < text.length()) {
text = text.mid(cur.positionInBlock());
if (text.at(0) == '\t') {
cur.deleteChar();
} else if (m_bTabUseSpace && text.startsWith(QString(m_nTabSize,' '))) {
int pos = cur.positionInBlock()-1;
if (pos >= 0) {
if (text.at(pos) == '\t') {
cur.deletePreviousChar();
} else if (m_bTabUseSpace &&
(pos-m_nTabSize+1 >= 0) &&
(text.mid(pos-m_nTabSize+1,m_nTabSize) == QString(m_nTabSize,' '))) {
int count = m_nTabSize;
while (count--) {
cur.deleteChar();
cur.deletePreviousChar();
}
} else if (text.at(0) == ' ') {
cur.deleteChar();
} else if (text.at(pos) == ' ') {
cur.deletePreviousChar();
}
}
}
Expand Down

0 comments on commit d19e891

Please sign in to comment.