| @@ -788,9 +788,7 @@ impl ApplicationInfo for IambInfo { |
| 788 | 788 | IambBufferId::Command(CommandType::Command) => complete_cmdbar(text, cursor, store), |
| 789 | 789 | IambBufferId::Command(CommandType::Search) => vec![], |
| 790 | 790 | |
| 791 | | IambBufferId::Room(_, RoomFocus::MessageBar) => { |
| 792 | | complete_matrix_names(text, cursor, store) |
| 793 | | }, |
| 791 | IambBufferId::Room(_, RoomFocus::MessageBar) => complete_msgbar(text, cursor, store), |
| 794 | 792 | IambBufferId::Room(_, RoomFocus::Scrollback) => vec![], |
| 795 | 793 | |
| 796 | 794 | IambBufferId::DirectList => vec![], |
| @@ -822,6 +820,53 @@ fn complete_users(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> |
| 822 | 820 | .collect() |
| 823 | 821 | } |
| 824 | 822 | |
| 823 | fn complete_msgbar(text: &EditRope, cursor: &mut Cursor, store: &ProgramStore) -> Vec<String> { |
| 824 | let id = text |
| 825 | .get_prefix_word_mut(cursor, &MATRIX_ID_WORD) |
| 826 | .unwrap_or_else(EditRope::empty); |
| 827 | let id = Cow::from(&id); |
| 828 | |
| 829 | match id.chars().next() { |
| 830 | // Complete room aliases. |
| 831 | Some('#') => { |
| 832 | return store.application.names.complete(id.as_ref()); |
| 833 | }, |
| 834 | |
| 835 | // Complete room identifiers. |
| 836 | Some('!') => { |
| 837 | return store |
| 838 | .application |
| 839 | .rooms |
| 840 | .complete(id.as_ref()) |
| 841 | .into_iter() |
| 842 | .map(|i| i.to_string()) |
| 843 | .collect(); |
| 844 | }, |
| 845 | |
| 846 | // Complete Emoji shortcodes. |
| 847 | Some(':') => { |
| 848 | let list = store.application.emojis.complete(&id[1..]); |
| 849 | let iter = list.into_iter().take(200).map(|s| format!(":{}:", s)); |
| 850 | |
| 851 | return iter.collect(); |
| 852 | }, |
| 853 | |
| 854 | // Complete usernames for @ and empty strings. |
| 855 | Some('@') | None => { |
| 856 | return store |
| 857 | .application |
| 858 | .presences |
| 859 | .complete(id.as_ref()) |
| 860 | .into_iter() |
| 861 | .map(|i| i.to_string()) |
| 862 | .collect(); |
| 863 | }, |
| 864 | |
| 865 | // Unknown sigil. |
| 866 | Some(_) => return vec![], |
| 867 | } |
| 868 | } |
| 869 | |
| 825 | 870 | fn complete_matrix_names( |
| 826 | 871 | text: &EditRope, |
| 827 | 872 | cursor: &mut Cursor, |
| @@ -1011,6 +1056,29 @@ pub mod tests { |
| 1011 | 1056 | ); |
| 1012 | 1057 | } |
| 1013 | 1058 | |
| 1059 | #[tokio::test] |
| 1060 | async fn test_complete_msgbar() { |
| 1061 | let store = mock_store().await; |
| 1062 | |
| 1063 | let text = EditRope::from("going for a walk :walk "); |
| 1064 | let mut cursor = Cursor::new(0, 22); |
| 1065 | let res = complete_msgbar(&text, &mut cursor, &store); |
| 1066 | assert_eq!(res, vec![":walking:", ":walking_man:", ":walking_woman:"]); |
| 1067 | assert_eq!(cursor, Cursor::new(0, 17)); |
| 1068 | |
| 1069 | let text = EditRope::from("hello @user1 "); |
| 1070 | let mut cursor = Cursor::new(0, 12); |
| 1071 | let res = complete_msgbar(&text, &mut cursor, &store); |
| 1072 | assert_eq!(res, vec!["@user1:example.com"]); |
| 1073 | assert_eq!(cursor, Cursor::new(0, 6)); |
| 1074 | |
| 1075 | let text = EditRope::from("see #room "); |
| 1076 | let mut cursor = Cursor::new(0, 9); |
| 1077 | let res = complete_msgbar(&text, &mut cursor, &store); |
| 1078 | assert_eq!(res, vec!["#room1:example.com"]); |
| 1079 | assert_eq!(cursor, Cursor::new(0, 4)); |
| 1080 | } |
| 1081 | |
| 1014 | 1082 | #[tokio::test] |
| 1015 | 1083 | async fn test_complete_cmdbar() { |
| 1016 | 1084 | let store = mock_store().await; |