mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-13 07:19:48 -05:00
Merge pull request #258 from schdub/master
Suggestion: 'Tab' indents multiline selection in SQL editor
This commit is contained in:
@@ -292,6 +292,13 @@ void SqlTextEdit::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
}
|
||||
|
||||
// indent on tab
|
||||
if (e->key() == Qt::Key_Tab && textCursor().hasSelection())
|
||||
{
|
||||
increaseSelectionIndent();
|
||||
return;
|
||||
}
|
||||
|
||||
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space); // CTRL+SPACE
|
||||
if (!m_Completer || !isShortcut) // do not process the shortcut when we have a completer
|
||||
QPlainTextEdit::keyPressEvent(e);
|
||||
@@ -354,3 +361,38 @@ void SqlTextEdit::keyPressEvent(QKeyEvent *e)
|
||||
+ m_Completer->popup()->verticalScrollBar()->sizeHint().width());
|
||||
m_Completer->complete(cr); // popup it up!
|
||||
}
|
||||
|
||||
void SqlTextEdit::increaseSelectionIndent()
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
int spos = cursor.anchor();
|
||||
int epos = cursor.position();
|
||||
if (spos > epos) std::swap(spos, epos);
|
||||
|
||||
cursor.setPosition(spos, QTextCursor::MoveAnchor);
|
||||
int sblock = cursor.block().blockNumber();
|
||||
|
||||
cursor.setPosition(epos, QTextCursor::MoveAnchor);
|
||||
int eblock = cursor.block().blockNumber();
|
||||
|
||||
cursor.setPosition(spos, QTextCursor::MoveAnchor);
|
||||
const int diff = eblock - sblock;
|
||||
|
||||
cursor.beginEditBlock();
|
||||
for (int i = 0; i <= diff; ++i)
|
||||
{
|
||||
cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
|
||||
cursor.insertText(" ");
|
||||
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor);
|
||||
}
|
||||
cursor.endEditBlock();
|
||||
|
||||
cursor.setPosition(spos, QTextCursor::MoveAnchor);
|
||||
cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
|
||||
|
||||
while (cursor.block().blockNumber() < eblock)
|
||||
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor);
|
||||
|
||||
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
||||
setTextCursor(cursor);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ private slots:
|
||||
void highlightCurrentLine();
|
||||
void updateLineNumberAreaWidth();
|
||||
void updateLineNumberArea(const QRect& rect, int dy);
|
||||
void increaseSelectionIndent();
|
||||
|
||||
private:
|
||||
QCompleter* m_Completer;
|
||||
|
||||
Reference in New Issue
Block a user