| 3234 | } |
| 3235 | |
| 3236 | void TextEdit::_delete(bool p_word, bool p_all_to_right) { |
| 3237 | if (!editable) { |
| 3238 | return; |
| 3239 | } |
| 3240 | |
| 3241 | start_action(EditAction::ACTION_DELETE); |
| 3242 | begin_multicaret_edit(); |
| 3243 | |
| 3244 | Vector<int> sorted_carets = get_sorted_carets(); |
| 3245 | for (int i = 0; i < sorted_carets.size(); i++) { |
| 3246 | int caret_index = sorted_carets[i]; |
| 3247 | if (multicaret_edit_ignore_caret(caret_index)) { |
| 3248 | continue; |
| 3249 | } |
| 3250 | |
| 3251 | if (has_selection(caret_index)) { |
| 3252 | delete_selection(caret_index); |
| 3253 | continue; |
| 3254 | } |
| 3255 | |
| 3256 | int curline_len = text[get_caret_line(caret_index)].length(); |
| 3257 | if (get_caret_line(caret_index) == text.size() - 1 && get_caret_column(caret_index) == curline_len) { |
| 3258 | continue; // Last line, last column: Nothing to do. |
| 3259 | } |
| 3260 | |
| 3261 | int next_line = get_caret_column(caret_index) < curline_len ? get_caret_line(caret_index) : get_caret_line(caret_index) + 1; |
| 3262 | int next_column; |
| 3263 | |
| 3264 | if (p_all_to_right) { |
| 3265 | if (get_caret_column(caret_index) == curline_len) { |
| 3266 | continue; |
| 3267 | } |
| 3268 | |
| 3269 | // Delete everything to right of caret. |
| 3270 | next_column = curline_len; |
| 3271 | next_line = get_caret_line(caret_index); |
| 3272 | } else if (p_word && get_caret_column(caret_index) < curline_len - 1) { |
| 3273 | // Delete next word to right of caret. |
| 3274 | int line = get_caret_line(caret_index); |
| 3275 | int column = get_caret_column(caret_index); |
| 3276 | |
| 3277 | PackedInt32Array words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid()); |
| 3278 | if (words.is_empty() || column >= words[words.size() - 1]) { |
| 3279 | // Delete to the end when there are no more words. |
| 3280 | column = text[get_caret_line(i)].length(); |
| 3281 | } else { |
| 3282 | for (int j = 1; j < words.size(); j = j + 2) { |
| 3283 | if (words[j] > column) { |
| 3284 | column = words[j]; |
| 3285 | break; |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | next_line = line; |
| 3291 | next_column = column; |
| 3292 | } else { |
| 3293 | // Delete one character. |
nothing calls this directly
no test coverage detected