Stop Return in the search box from deleting the matched text#596
Open
HaozheZhang6 wants to merge 1 commit into
Open
Stop Return in the search box from deleting the matched text#596HaozheZhang6 wants to merge 1 commit into
HaozheZhang6 wants to merge 1 commit into
Conversation
QLineEdit ignores Return once it has emitted returnPressed. The search widget is a child of the editor, so the key propagated up and was inserted into the document. highlight_current_match() selects the current match with setTextCursor(), so the inserted newline replaced the match: searching for 'key' in 'key=1' and pressing Return left '\n=1'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pressing Return in the Ctrl+F search box deletes the match instead of moving to the next one.
Repro on master:
key=1in the editorkeyThe document is now
\n=1. Each further Return eats another match.Cause:
QLineEditignores Return after emittingreturnPressed, andSearchWidgetis a child of the editor, so the key propagates up toCodeEditor.keyPressEventandQPlainTextEditinserts a newline.highlight_current_match()puts the current match into the editor's text cursor viasetTextCursor(), so that newline lands on a selection and replaces it.Fix: accept Return/Enter in
SearchWidget.keyPressEventso it stops there.find_next()still runs fromreturnPressed, and Escape/F3 still reach the editor by propagation as before.Test:
test_search_return_does_not_edit_documentsends real key events through the search input. It fails on master: