From 2d05ca7560ec6a3016eb1dac6e03b4c498536839 Mon Sep 17 00:00:00 2001 From: Tomas Strba <57389842+tomasstrba@users.noreply.github.com> Date: Mon, 22 Nov 2021 13:52:01 +0100 Subject: [PATCH] Forward delete collision with suffix resolved (#334) --- .../View/AddressBarTextField.swift | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift b/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift index a38b4c1a43..384dba3e58 100644 --- a/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift +++ b/DuckDuckGo/NavigationBar/View/AddressBarTextField.swift @@ -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 } }