Skip to content

Commit b6e085e

Browse files
committed
Fix an issue where the contents of a duplicated query favorite would be overwritten if the selection was changed bevore saving (#2938)
1 parent 2f0099e commit b6e085e

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

Source/SPQueryFavoriteManager.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,19 @@ - (IBAction)addQueryFavorite:(id)sender
201201
[[self window] makeFirstResponder:favoriteNameTextField];
202202

203203
// Duplicate a selected favorite if sender == self
204-
if (sender == self)
205-
favorite = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[[favoriteNameTextField stringValue] stringByAppendingFormat:@" Copy"], [favoriteQueryTextView string], nil] forKeys:[NSArray arrayWithObjects:@"name", @"query", nil]];
204+
if (sender == self) {
205+
favorite = [NSMutableDictionary dictionaryWithDictionary:@{
206+
@"name": [NSString stringWithFormat:NSLocalizedString(@"%@ Copy", @"query favorite manager : duplicate favorite : new favorite name"),[favoriteNameTextField stringValue]],
207+
@"query": [NSString stringWithString:[favoriteQueryTextView string]] // #2938 - without copying the string we would store the live NS*MutableString object that backs the text view and changes its contents when selection changes!
208+
}];
209+
}
206210
// Add a new favorite
207-
else
208-
favorite = [NSMutableDictionary dictionaryWithObjects:@[@"New Favorite", @""] forKeys:@[@"name", @"query"]];
211+
else {
212+
favorite = [NSMutableDictionary dictionaryWithDictionary:@{
213+
@"name": NSLocalizedString(@"New Favorite",@"query favorite manager : new favorite : name"),
214+
@"query": @""
215+
}];
216+
}
209217

210218
// If a favourite is currently selected, add the new favourite next to it
211219
if ([favoritesTableView numberOfSelectedRows] > 0) {

0 commit comments

Comments
 (0)