forked from qt-creator/qt-creator
Add join-line up/down feature to text editor
Merge-request: 1823 Reviewed-by: Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com> Task-number: QTCREATORBUG-510
This commit is contained in:
committed by
Thorbjørn Lindeijer
parent
e2400f5788
commit
ec2b738d61
@@ -877,6 +877,40 @@ void BaseTextEditor::copyLineUpDown(bool up)
|
||||
setTextCursor(move);
|
||||
}
|
||||
|
||||
void BaseTextEditor::joinLineUp()
|
||||
{
|
||||
joinLineUpDown(true);
|
||||
}
|
||||
|
||||
void BaseTextEditor::joinLineDown()
|
||||
{
|
||||
joinLineUpDown(false);
|
||||
}
|
||||
|
||||
void BaseTextEditor::joinLineUpDown(bool up)
|
||||
{
|
||||
QTextCursor move = textCursor();
|
||||
move.beginEditBlock();
|
||||
|
||||
if(up)
|
||||
move.movePosition(QTextCursor::Up);
|
||||
else
|
||||
move.movePosition(QTextCursor::Down);
|
||||
move.movePosition(QTextCursor::StartOfBlock);
|
||||
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
|
||||
QString cutLine = move.selectedText();
|
||||
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
|
||||
move.removeSelectedText();
|
||||
move.clearSelection();
|
||||
|
||||
if(!up)
|
||||
move.movePosition(QTextCursor::Up);
|
||||
move.movePosition(QTextCursor::EndOfBlock);
|
||||
move.insertText(cutLine);
|
||||
move.endEditBlock();
|
||||
setTextCursor(move);
|
||||
}
|
||||
|
||||
void BaseTextEditor::moveLineUp()
|
||||
{
|
||||
moveLineUpDown(true);
|
||||
|
||||
@@ -412,6 +412,9 @@ public slots:
|
||||
void copyLineUp();
|
||||
void copyLineDown();
|
||||
|
||||
void joinLineUp();
|
||||
void joinLineDown();
|
||||
|
||||
void cleanWhitespace();
|
||||
|
||||
signals:
|
||||
@@ -620,6 +623,7 @@ private:
|
||||
void handleBackspaceKey();
|
||||
void moveLineUpDown(bool up);
|
||||
void copyLineUpDown(bool up);
|
||||
void joinLineUpDown(bool up);
|
||||
void saveCurrentCursorPositionForNavigation();
|
||||
void updateCurrentLineHighlight();
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ TextEditorActionHandler::TextEditorActionHandler(const QString &context,
|
||||
m_moveLineDownAction(0),
|
||||
m_copyLineUpAction(0),
|
||||
m_copyLineDownAction(0),
|
||||
m_joinLineUpAction(0),
|
||||
m_joinLineDownAction(0),
|
||||
m_optionalActions(optionalActions),
|
||||
m_currentEditor(0),
|
||||
m_initialized(false)
|
||||
@@ -282,6 +284,16 @@ void TextEditorActionHandler::createActions()
|
||||
command = am->registerAction(m_copyLineDownAction, Constants::COPY_LINE_DOWN, m_contextId);
|
||||
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Down")));
|
||||
connect(m_copyLineDownAction, SIGNAL(triggered()), this, SLOT(copyLineDown()));
|
||||
|
||||
m_joinLineUpAction= new QAction(tr("Join Line Up"), this);
|
||||
command = am->registerAction(m_joinLineUpAction, Constants::JOIN_LINE_UP, m_contextId);
|
||||
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+J")));
|
||||
connect(m_joinLineUpAction, SIGNAL(triggered()), this, SLOT(joinLineUp()));
|
||||
|
||||
m_joinLineDownAction= new QAction(tr("Join Line Down"), this);
|
||||
command = am->registerAction(m_joinLineDownAction, Constants::JOIN_LINE_DOWN, m_contextId);
|
||||
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+J")));
|
||||
connect(m_joinLineDownAction, SIGNAL(triggered()), this, SLOT(joinLineDown()));
|
||||
}
|
||||
|
||||
bool TextEditorActionHandler::supportsAction(const QString & /*id */) const
|
||||
@@ -443,6 +455,8 @@ FUNCTION(moveLineUp)
|
||||
FUNCTION(moveLineDown)
|
||||
FUNCTION(copyLineUp)
|
||||
FUNCTION(copyLineDown)
|
||||
FUNCTION(joinLineUp)
|
||||
FUNCTION(joinLineDown)
|
||||
|
||||
void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
|
||||
{
|
||||
|
||||
@@ -115,6 +115,8 @@ private slots:
|
||||
void moveLineDown();
|
||||
void copyLineUp();
|
||||
void copyLineDown();
|
||||
void joinLineUp();
|
||||
void joinLineDown();
|
||||
void updateCurrentEditor(Core::IEditor *editor);
|
||||
|
||||
private:
|
||||
@@ -151,6 +153,8 @@ private:
|
||||
QAction *m_moveLineDownAction;
|
||||
QAction *m_copyLineUpAction;
|
||||
QAction *m_copyLineDownAction;
|
||||
QAction *m_joinLineUpAction;
|
||||
QAction *m_joinLineDownAction;
|
||||
|
||||
uint m_optionalActions;
|
||||
QPointer<BaseTextEditor> m_currentEditor;
|
||||
|
||||
@@ -60,6 +60,8 @@ const char * const MOVE_LINE_UP = "TextEditor.MoveLineUp";
|
||||
const char * const MOVE_LINE_DOWN = "TextEditor.MoveLineDown";
|
||||
const char * const COPY_LINE_UP = "TextEditor.CopyLineUp";
|
||||
const char * const COPY_LINE_DOWN = "TextEditor.CopyLineDown";
|
||||
const char * const JOIN_LINE_UP = "TextEditor.JoinLineUp";
|
||||
const char * const JOIN_LINE_DOWN = "TextEditor.JoinLineDown";
|
||||
const char * const CUT_LINE = "TextEditor.CutLine";
|
||||
const char * const DELETE_LINE = "TextEditor.DeleteLine";
|
||||
const char * const DELETE_WORD = "TextEditor.DeleteWord";
|
||||
|
||||
Reference in New Issue
Block a user