Skip to content

Commit

Permalink
Forward delete collision with suffix resolved (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasstrba authored Nov 22, 2021
1 parent 3ddcc52 commit 2d05ca7
Showing 1 changed file with 29 additions and 19 deletions.
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

0 comments on commit 2d05ca7

Please sign in to comment.