Skip to content

Commit

Permalink
Smart home/end enanced
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Ribelotta <[email protected]>
  • Loading branch information
martinribelotta committed Oct 9, 2016
1 parent 643318c commit 334f7ef
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,19 @@ bool CodeEditor::save()
void CodeEditor::smartHome()
{
QTextCursor c = textCursor();
QTextCursor::MoveMode moveAnchor = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)?
QTextCursor::KeepAnchor:QTextCursor::MoveAnchor;
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
c.movePosition(QTextCursor::Start, moveAnchor);
setTextCursor(c);
return;
}

int blockLen = c.block().text().length();
if (blockLen == 0 )
return;

int originalPosition = c.position();
QTextCursor::MoveMode moveAnchor = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)?
QTextCursor::KeepAnchor:QTextCursor::MoveAnchor;
c.movePosition(QTextCursor::StartOfLine, moveAnchor);
int startOfLine = c.position();
int i = 0;
Expand All @@ -315,13 +321,19 @@ void CodeEditor::smartHome()
void CodeEditor::smartEnd()
{
QTextCursor c = textCursor();
QTextCursor::MoveMode moveAnchor = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)?
QTextCursor::KeepAnchor:QTextCursor::MoveAnchor;
if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
c.movePosition(QTextCursor::End, moveAnchor);
setTextCursor(c);
return;
}

int blockLen = c.block().text().length();
if (blockLen == 0)
return;

int originalPosition = c.position();
QTextCursor::MoveMode moveAnchor = QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)?
QTextCursor::KeepAnchor:QTextCursor::MoveAnchor;
c.movePosition(QTextCursor::StartOfLine,moveAnchor);
int startOfLine = c.position();
c.movePosition(QTextCursor::EndOfLine,moveAnchor);
Expand Down

0 comments on commit 334f7ef

Please sign in to comment.