* [sup-talk] [PATCH] show matching aliases before email addresses in auto complete
@ 2008-11-23 19:39 Steve Goldman
2008-11-27 0:29 ` William Morgan
0 siblings, 1 reply; 6+ messages in thread
From: Steve Goldman @ 2008-11-23 19:39 UTC (permalink / raw)
---
lib/sup/buffer.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index ebc3587..e56fbf7 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -433,7 +433,7 @@ EOS
prefix, target = partial.split_on_commas_with_remainder
target ||= prefix.pop || ""
prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
- completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
+ completions.select { |x| x =~ /^#{Regexp::escape target}/i }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] }
end
end
@@ -501,7 +501,7 @@ EOS
recent = Index.load_contacts(AccountManager.user_emails, :num => 10).map { |c| [c.full_address, c.email] }
contacts = ContactManager.contacts.map { |c| [ContactManager.alias_for(c), c.full_address, c.email] }
- completions = (recent + contacts).flatten.uniq.sort
+ completions = (recent + contacts).flatten.uniq
completions += HookManager.run("extra-contact-addresses") || []
answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default
--
1.5.6.4
--
Steve Goldman
sgoldman at tower-research.com
T: 212.219.6014
F: 212.219.6007
Tower Research Capital, LLC
377 Broadway, 11th Fl.
New York, NY 10013
^ permalink raw reply [flat|nested] 6+ messages in thread
* [sup-talk] [PATCH] show matching aliases before email addresses in auto complete
@ 2008-11-07 21:05 Steve Goldman
2008-11-10 5:11 ` William Morgan
0 siblings, 1 reply; 6+ messages in thread
From: Steve Goldman @ 2008-11-07 21:05 UTC (permalink / raw)
---
Suppose I have an alias "william" for "William Morgan
<name at domain.blah>". I hit compose, and in the "To:" field, I type
"wil<TAB>". Sup has two suggestions, listing the longer one first,
and it autocompletes as far as they match. So now my text field says,
"To: William", which doesn't match the alias. If we sort the possible
completions so that aliases are before non-aliases, then the field
would read, "To: william", which would match the alias and work
correctly.
lib/sup/buffer.rb | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index 0447f61..fc9a0a2 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -433,7 +433,9 @@ EOS
prefix, target = partial.split_on_commas_with_remainder
target ||= prefix.pop || ""
prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
- completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
+ completions.select { |x| x =~ /^#{Regexp::escape target}/i }.
+ sort { |x,y| x_is_c = ContactManager.contact_for(x); y_is_c = ContactManager.contact_for(y); x_is_c && !y_is_c ? -1 : !x_is_c && y_is_c ? 1 : x <=> y }.
+ map { |x| [prefix + x, x] }
end
end
@@ -501,7 +503,7 @@ EOS
recent = Index.load_contacts(AccountManager.user_emails, :num => 10).map { |c| [c.full_address, c.email] }
contacts = ContactManager.contacts.map { |c| [ContactManager.alias_for(c), c.full_address, c.email] }
- completions = (recent + contacts).flatten.uniq.sort
+ completions = (contacts + recent).flatten.uniq
completions += HookManager.run("extra-contact-addresses") || []
answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default
--
1.5.5
--
Steve Goldman
sgoldman at tower-research.com
T: 212.219.6014
F: 212.219.6007
Tower Research Capital, LLC
377 Broadway, 11th Fl.
New York, NY 10013
^ permalink raw reply [flat|nested] 6+ messages in thread
* [sup-talk] [PATCH] show matching aliases before email addresses in auto complete
2008-11-07 21:05 Steve Goldman
@ 2008-11-10 5:11 ` William Morgan
2008-11-10 5:14 ` William Morgan
0 siblings, 1 reply; 6+ messages in thread
From: William Morgan @ 2008-11-10 5:11 UTC (permalink / raw)
Hi Steve,
Thanks for the patch! A couple comments:
Reformatted excerpts from Steve Goldman's message of 2008-11-07:
> Suppose I have an alias "william" for "William Morgan
> <name at domain.blah>".
It might be nice to put this helpful explanatory text in the commit
message itself, so that it gets recorded along with the patch.
> + sort { |x,y| x_is_c = ContactManager.contact_for(x); y_is_c
> = ContactManager.contact_for(y); x_is_c && !y_is_c ? -1 : !x_is_c && y_is_c ? 1
I think you can express this more succinctly with something like
sort_by { |c| [ContactManager.contact_for(c) ? 1 : 0, c] }
which makes use of both sort_by (Ruby's answer to the Schwartizan
transform) and the fact that arrays are sorted element-by-element.
Other than that, looks good and I like the idea.
--
William <wmorgan-sup at masanjin.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [sup-talk] [PATCH] show matching aliases before email addresses in auto complete
2008-11-10 5:11 ` William Morgan
@ 2008-11-10 5:14 ` William Morgan
2008-11-10 14:55 ` Steve Goldman
0 siblings, 1 reply; 6+ messages in thread
From: William Morgan @ 2008-11-10 5:14 UTC (permalink / raw)
Reformatted excerpts from William Morgan's message of 2008-11-09:
> sort_by { |c| [ContactManager.contact_for(c) ? 1 : 0, c] }
Oh, 0 : 1, maybe.
--
William <wmorgan-sup at masanjin.net>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [sup-talk] [PATCH] show matching aliases before email addresses in auto complete
2008-11-10 5:14 ` William Morgan
@ 2008-11-10 14:55 ` Steve Goldman
0 siblings, 0 replies; 6+ messages in thread
From: Steve Goldman @ 2008-11-10 14:55 UTC (permalink / raw)
Excerpts from William Morgan's message of Mon Nov 10 00:14:48 -0500 2008:
> Reformatted excerpts from William Morgan's message of 2008-11-09:
> > sort_by { |c| [ContactManager.contact_for(c) ? 1 : 0, c] }
>
> Oh, 0 : 1, maybe.
Ah, much cleaner. Thanks for the ruby lesson. And, yeah, the correct order is 0 : 1.
Thanks.
--
Steve Goldman
sgoldman at tower-research.com
T: 212.219.6014
F: 212.219.6007
Tower Research Capital, LLC
377 Broadway, 11th Fl.
New York, NY 10013
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-11-27 0:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-23 19:39 [sup-talk] [PATCH] show matching aliases before email addresses in auto complete Steve Goldman
2008-11-27 0:29 ` William Morgan
-- strict thread matches above, loose matches on Subject: below --
2008-11-07 21:05 Steve Goldman
2008-11-10 5:11 ` William Morgan
2008-11-10 5:14 ` William Morgan
2008-11-10 14:55 ` Steve Goldman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox