Skip to content

Commit

Permalink
Github Issue #202: Added preservation of the longest character length…
Browse files Browse the repository at this point in the history
… in a text block when navigating using up/down key through empty blocks or blocks with lesser character length
  • Loading branch information
AngryFender committed Aug 8, 2024
1 parent ea943cc commit 2acacb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions mkedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void MkEdit::keyPressEvent(QKeyEvent *event)
case Qt::Key_Up:
case Qt::Key_Right:
case Qt::Key_Left:
case Qt::Key_Down: setPreArrowKeys(event->modifiers()==Qt::SHIFT);
case Qt::Key_Down: setPreArrowKeys(event->modifiers()==Qt::SHIFT,event->key() == Qt::Key_Up || event->key() == Qt::Key_Down);
QTextEdit::keyPressEvent(event);
setPostArrowKeys(event->modifiers() == Qt::SHIFT, event->key() == Qt::Key_Left,event->key() == Qt::Key_Up || event->key() == Qt::Key_Down);
return;
Expand Down Expand Up @@ -179,7 +179,7 @@ void MkEdit::keyPressEvent(QKeyEvent *event)
clearMkEffects(undoData.editType);
QTextEdit::keyPressEvent(event);
selectRange.currentBlockNo = textCursor().blockNumber();
selectRange.currentposInBlock = textCursor().positionInBlock();
selectRange.currentposInBlock = selectRange.arrowPosInBlock = textCursor().positionInBlock();

switch(event->key()){
case Qt::Key_Enter:
Expand Down Expand Up @@ -272,18 +272,18 @@ void MkEdit::showSelectionAfterRedo()
}
}

void MkEdit::setPreArrowKeys(const bool isShiftPressed)
void MkEdit::setPreArrowKeys(const bool isShiftPressed, const bool isUpOrDownArrowPressed)
{
QTextCursor cursor = this->textCursor();
if(!cursor.hasSelection() && isShiftPressed){
selectRange.selectionFirstStartBlock = cursor.blockNumber();
selectRange.selectionFirstStartPosInBlock = cursor.positionInBlock();
}

selectRange.arrowPosInBlock = cursor.positionInBlock()? cursor.positionInBlock() : selectRange.arrowPosInBlock;
selectRange.arrowPosInBlock = isUpOrDownArrowPressed && cursor.positionInBlock()<selectRange.arrowPosInBlock ? selectRange.arrowPosInBlock: cursor.positionInBlock() ;
}

void MkEdit::setPostArrowKeys(bool isShiftPressed, bool isLeftArrowPressed, const bool isUpOrDownArrowPressed)
void MkEdit::setPostArrowKeys(const bool isShiftPressed, const bool isLeftArrowPressed, const bool isUpOrDownArrowPressed)
{
disconnectSignals(true);
QTextCursor cursor = this->textCursor();
Expand Down
2 changes: 1 addition & 1 deletion mkedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class MkEdit : public QTextEdit
bool isMouseOnCheckBox(QMouseEvent *e);
void showSelectionAfterUndo();
void showSelectionAfterRedo();
void setPreArrowKeys(const bool isShiftPressed);
void setPreArrowKeys(const bool isShiftPressed, const bool isUpOrDownArrowPressed);
void setPostArrowKeys(const bool isShiftPressed, const bool isLeftArrowPressed, const bool isUpOrDownArrowPressed);

void restoreTextCursor(int blockNo, int posInBlock, bool hasSelection);
Expand Down

0 comments on commit 2acacb9

Please sign in to comment.