Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit fe535a76 authored by Laurent Montel's avatar Laurent Montel 😁

Add moveup/movedown

parent 56d04e10
......@@ -636,16 +636,59 @@ void PlainTextEditor::deleteEndOfLine()
setTextCursor(cursor);
}
void PlainTextEditor::moveUpDownText(bool moveUp)
void PlainTextEditor::moveLineUpDown(bool moveUp)
{
//TODO select all block text
qDebug() << " void PlainTextEditor::moveUpDownText(bool moveUp)" << moveUp;
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
//TODO more
cursor.endEditBlock();
setTextCursor(cursor);
QTextCursor move = cursor;
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
if (hasSelection) {
move.setPosition(cursor.selectionStart());
move.movePosition(QTextCursor::StartOfBlock);
move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor);
move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock,
QTextCursor::KeepAnchor);
} else {
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
QString text = move.selectedText();
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
move.removeSelectedText();
if (moveUp) {
move.movePosition(QTextCursor::PreviousBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.movePosition(QTextCursor::EndOfBlock);
if (move.atBlockStart()) { // empty block
move.movePosition(QTextCursor::NextBlock);
move.insertBlock();
move.movePosition(QTextCursor::Left);
} else {
move.insertBlock();
}
}
int start = move.position();
move.clearSelection();
move.insertText(text);
int end = move.position();
if (hasSelection) {
move.setPosition(end);
move.setPosition(start, QTextCursor::KeepAnchor);
} else {
move.setPosition(start);
}
move.endEditBlock();
setTextCursor(move);
}
void PlainTextEditor::wheelEvent(QWheelEvent *event)
......
......@@ -122,7 +122,7 @@ private:
void deleteWordForward();
void highlightWord(int length, int pos);
void deleteEndOfLine();
void moveUpDownText(bool moveUp);
void moveLineUpDown(bool moveUp);
class PlainTextEditorPrivate;
PlainTextEditorPrivate *const d;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment