~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/client/composer/contact-entry-completion.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-10-10 17:40:37 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20131010174037-5p5o4dlsoewek2kg
Tags: 0.4.0-0ubuntu1
New stable version

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
        if (entry == null)
97
97
            return empty_addresses;
98
98
        
99
 
        int cursor_position = entry.cursor_position;
100
 
        if (cursor_position < 0)
101
 
            return empty_addresses;
102
 
        
103
99
        string? original_text = entry.get_text();
104
100
        if (original_text == null)
105
101
            return empty_addresses;
106
102
        
 
103
        int cursor_position = entry.cursor_position;
 
104
        int cursor_offset = original_text.index_of_nth_char(cursor_position);
 
105
        if (cursor_offset < 0)
 
106
            return empty_addresses;
 
107
        
107
108
        Gee.List<string> addresses = new Gee.ArrayList<string>();
108
109
        string delimiter = ",";
109
110
        string[] addresses_array = original_text.split(delimiter);
113
114
        if (addresses.size < 1)
114
115
            return empty_addresses;
115
116
        
116
 
        int characters_seen_so_far = 0;
 
117
        int bytes_seen_so_far = 0;
117
118
        current_address_index = addresses.size - 1;
118
119
        for (int i = 0; i < addresses.size; i++) {
119
 
            int token_chars = addresses[i].char_count() + delimiter.char_count();
120
 
            if ((characters_seen_so_far + token_chars) > cursor_position) {
 
120
            int token_bytes = addresses[i].length + delimiter.length;
 
121
            if ((bytes_seen_so_far + token_bytes) > cursor_offset) {
121
122
                current_address_index = i;
122
123
                current_address_key = addresses[i]
123
 
                    .substring(0, cursor_position - characters_seen_so_far)
 
124
                    .substring(0, cursor_offset - bytes_seen_so_far)
124
125
                    .strip().normalize().casefold();
125
126
                
126
127
                current_address_remainder = addresses[i]
127
 
                    .substring(cursor_position - characters_seen_so_far).strip();
 
128
                    .substring(cursor_offset - bytes_seen_so_far).strip();
128
129
                break;
129
130
            }
130
 
            characters_seen_so_far += token_chars;
 
131
            bytes_seen_so_far += token_bytes;
131
132
        }
132
133
        
133
134
        return addresses;
176
177
        try {
177
178
            string escaped_needle = Regex.escape_string(needle.normalize());
178
179
            Regex regex = new Regex("\\b" + escaped_needle, RegexCompileFlags.CASELESS);
179
 
            if (regex.match(haystack)) {
180
 
                highlighted_result = regex.replace_eval(haystack, -1, 0, 0, eval_callback);
 
180
            string haystack_normalized = haystack.normalize();
 
181
            if (regex.match(haystack_normalized)) {
 
182
                highlighted_result = regex.replace_eval(haystack_normalized, -1, 0, 0, eval_callback);
181
183
                matched = true;
182
184
            }
183
185
        } catch (RegexError err) {