Skip to content

fix issue up/down first/last line not jumping to begin/end#220

Closed
louwers wants to merge 2 commits into
pbek:mainfrom
louwers:fix-branch
Closed

fix issue up/down first/last line not jumping to begin/end#220
louwers wants to merge 2 commits into
pbek:mainfrom
louwers:fix-branch

Conversation

@louwers
Copy link
Copy Markdown

@louwers louwers commented Apr 22, 2026

Take into account Qt::KeypadModifier in the if-statement.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates key handling in QMarkdownTextEdit::eventFilter so that pressing Up/Down at the start/end of the document works correctly even when the arrow key originates from the numeric keypad (i.e., with Qt::KeypadModifier).

Changes:

  • Add special-case handling for Qt::Key_Up / Qt::Key_Down at the first/last line.
  • Treat Qt::KeypadModifier as equivalent to “no modifier” for this behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qmarkdowntextedit.cpp
Comment on lines +481 to +483
} else if ((keyEvent->key() == Qt::Key_Down) &&
(keyEvent->modifiers().testFlag(Qt::NoModifier) || keyEvent->modifiers().testFlag(Qt::KeypadModifier))) {
// if you are in the last line and press cursor down the cursor will
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modifier check modifiers().testFlag(Qt::KeypadModifier) will also match combinations like Ctrl+Shift+Keypad, so this branch can intercept shortcuts handled later in this chain (e.g. Ctrl+Shift+Down/Up for moveTextUpDown) when the arrow key comes from the numeric keypad. To avoid breaking those key combos, restrict this condition to only no modifiers or keypad-only (e.g. compare modifiers() for equality, or mask out KeypadModifier and ensure no other flags are set).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@louwers, please review

Comment thread qmarkdowntextedit.cpp
Comment on lines +496 to +498
} else if ((keyEvent->key() == Qt::Key_Up) &&
(keyEvent->modifiers().testFlag(Qt::NoModifier) || keyEvent->modifiers().testFlag(Qt::KeypadModifier))) {
// if you are in the first line and press cursor up the cursor will
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: testFlag(Qt::KeypadModifier) will be true even when other modifiers are pressed (e.g. Shift/Ctrl with keypad arrows), which can change or bypass intended behavior for those combos. Limit this branch to the keypad-only/no-modifier cases (e.g. modifiers() == Qt::NoModifier || modifiers() == Qt::KeypadModifier).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@louwers, please review

@pbek
Copy link
Copy Markdown
Owner

pbek commented Apr 23, 2026

And is

// Handle boundary arrow navigation here because Qt6 no longer reliably
// runs the event-filter path for these cursor moves on macOS.
if (handleBoundaryArrowNavigation(this, event)) {
return;
}
(including the method implementation) then redundant and can be removed?

@louwers
Copy link
Copy Markdown
Author

louwers commented Apr 23, 2026

@pbek Oh yes it is.

@louwers
Copy link
Copy Markdown
Author

louwers commented Apr 23, 2026

Let me close this and open a new PR, somehow I only expected this to be a two line change.

@louwers louwers closed this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants