Commit 0987a51e authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 425081

"Ctrl-Up" to take the cursor to the beginning of the line or paragraph. "

CCBUG: 425081
parent 62937b9f
Pipeline #29976 passed with stage
in 24 minutes and 9 seconds
......@@ -626,13 +626,25 @@ void PlainTextEditor::deleteEndOfLine()
setTextCursor(cursor);
}
void PlainTextEditor::moveCursorBeginUpDown(bool moveUp)
{
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.beginEditBlock();
cursor.clearSelection();
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(moveUp ? QTextCursor::PreviousBlock : QTextCursor::NextBlock);
move.endEditBlock();
setTextCursor(move);
}
void PlainTextEditor::moveLineUpDown(bool moveUp)
{
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
const bool hasSelection = cursor.hasSelection();
if (hasSelection) {
move.setPosition(cursor.selectionStart());
......@@ -644,7 +656,7 @@ void PlainTextEditor::moveLineUpDown(bool moveUp)
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
QString text = move.selectedText();
const QString text = move.selectedText();
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
move.removeSelectedText();
......@@ -706,6 +718,12 @@ void PlainTextEditor::keyPressEvent(QKeyEvent *event)
} else if (event->key() == Qt::Key_Down && isControlClicked && isShiftClicked) {
moveLineUpDown(false);
event->accept();
} else if (event->key() == Qt::Key_Up && isControlClicked) {
moveCursorBeginUpDown(true);
event->accept();
} else if (event->key() == Qt::Key_Down && isControlClicked) {
moveCursorBeginUpDown(false);
event->accept();
} else {
QPlainTextEdit::keyPressEvent(event);
}
......
......@@ -127,6 +127,7 @@ private:
void highlightWord(int length, int pos);
void deleteEndOfLine();
void moveLineUpDown(bool moveUp);
void moveCursorBeginUpDown(bool moveUp);
class PlainTextEditorPrivate;
PlainTextEditorPrivate *const d;
};
......
......@@ -936,6 +936,12 @@ void RichTextEditor::keyPressEvent(QKeyEvent *event)
} else if (event->key() == Qt::Key_Down && isControlClicked && isShiftClicked) {
moveLineUpDown(false);
event->accept();
} else if (event->key() == Qt::Key_Up && isControlClicked) {
moveCursorBeginUpDown(true);
event->accept();
} else if (event->key() == Qt::Key_Down && isControlClicked) {
moveCursorBeginUpDown(false);
event->accept();
} else {
QTextEdit::keyPressEvent(event);
}
......@@ -960,13 +966,25 @@ void RichTextEditor::slotZoomReset()
}
}
void RichTextEditor::moveCursorBeginUpDown(bool moveUp)
{
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.beginEditBlock();
cursor.clearSelection();
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(moveUp ? QTextCursor::PreviousBlock : QTextCursor::NextBlock);
move.endEditBlock();
setTextCursor(move);
}
void RichTextEditor::moveLineUpDown(bool moveUp)
{
QTextCursor cursor = textCursor();
QTextCursor move = cursor;
move.beginEditBlock();
bool hasSelection = cursor.hasSelection();
const bool hasSelection = cursor.hasSelection();
if (hasSelection) {
move.setPosition(cursor.selectionStart());
......@@ -978,7 +996,7 @@ void RichTextEditor::moveLineUpDown(bool moveUp)
move.movePosition(QTextCursor::StartOfBlock);
move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
}
QString text = move.selectedText();
const QString text = move.selectedText();
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
move.removeSelectedText();
......
......@@ -151,6 +151,7 @@ private:
void highlightWord(int length, int pos);
void checkSpelling(bool force);
void moveLineUpDown(bool moveUp);
void moveCursorBeginUpDown(bool moveUp);
class RichTextEditorPrivate;
RichTextEditorPrivate *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