Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward delete collision with suffix resolved #334

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions DuckDuckGo/NavigationBar/View/AddressBarTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -658,28 +658,38 @@ extension AddressBarTextField: NSTextFieldDelegate {
return false
}

guard suggestionWindowController?.window?.isVisible == true else {
return false
// Collision of suffix and forward deleting
if [#selector(NSResponder.deleteForward(_:)), #selector(NSResponder.deleteWordForward(_:))].contains(commandSelector) {
if let currentEditor = currentEditor(),
currentEditor.selectedRange.location == value.string.utf16.count,
currentEditor.selectedRange.length == 0 {
// Don't do delete when cursor is in the end
return true
}
}

switch commandSelector {
case #selector(NSResponder.moveDown(_:)):
suggestionContainerViewModel.selectNextIfPossible(); return true
case #selector(NSResponder.moveUp(_:)):
suggestionContainerViewModel.selectPreviousIfPossible(); return true
case #selector(NSResponder.deleteBackward(_:)),
#selector(NSResponder.deleteForward(_:)),
#selector(NSResponder.deleteToMark(_:)),
#selector(NSResponder.deleteWordForward(_:)),
#selector(NSResponder.deleteWordBackward(_:)),
#selector(NSResponder.deleteToEndOfLine(_:)),
#selector(NSResponder.deleteToEndOfParagraph(_:)),
#selector(NSResponder.deleteToBeginningOfLine(_:)),
#selector(NSResponder.deleteBackwardByDecomposingPreviousCharacter(_:)):
suggestionContainerViewModel.clearSelection(); return false
default:
return false
if suggestionWindowController?.window?.isVisible ?? false {
switch commandSelector {
case #selector(NSResponder.moveDown(_:)):
suggestionContainerViewModel.selectNextIfPossible(); return true
case #selector(NSResponder.moveUp(_:)):
suggestionContainerViewModel.selectPreviousIfPossible(); return true
case #selector(NSResponder.deleteBackward(_:)),
#selector(NSResponder.deleteForward(_:)),
#selector(NSResponder.deleteToMark(_:)),
#selector(NSResponder.deleteWordForward(_:)),
#selector(NSResponder.deleteWordBackward(_:)),
#selector(NSResponder.deleteToEndOfLine(_:)),
#selector(NSResponder.deleteToEndOfParagraph(_:)),
#selector(NSResponder.deleteToBeginningOfLine(_:)),
#selector(NSResponder.deleteBackwardByDecomposingPreviousCharacter(_:)):
suggestionContainerViewModel.clearSelection(); return false
default:
return false
}
}

return false
}

}
Expand Down