Check for empty history in setSelectionAddToHistory

Issue #1961