ed_insert(): * Add character to the line * Insert a character [bound to all insert keys] */
| 66 | * Insert a character [bound to all insert keys] |
| 67 | */ |
| 68 | protected el_action_t |
| 69 | ed_insert(EditLine *el, Int c) |
| 70 | { |
| 71 | int count = el->el_state.argument; |
| 72 | |
| 73 | if (c == '\0') |
| 74 | return CC_ERROR; |
| 75 | |
| 76 | if (el->el_line.lastchar + el->el_state.argument >= |
| 77 | el->el_line.limit) { |
| 78 | /* end of buffer space, try to allocate more */ |
| 79 | if (!ch_enlargebufs(el, (size_t) count)) |
| 80 | return CC_ERROR; /* error allocating more */ |
| 81 | } |
| 82 | |
| 83 | if (count == 1) { |
| 84 | if (el->el_state.inputmode == MODE_INSERT |
| 85 | || el->el_line.cursor >= el->el_line.lastchar) |
| 86 | c_insert(el, 1); |
| 87 | |
| 88 | *el->el_line.cursor++ = c; |
| 89 | re_fastaddc(el); /* fast refresh for one char. */ |
| 90 | } else { |
| 91 | if (el->el_state.inputmode != MODE_REPLACE_1) |
| 92 | c_insert(el, el->el_state.argument); |
| 93 | |
| 94 | while (count-- && el->el_line.cursor < el->el_line.lastchar) |
| 95 | *el->el_line.cursor++ = c; |
| 96 | re_refresh(el); |
| 97 | } |
| 98 | |
| 99 | if (el->el_state.inputmode == MODE_REPLACE_1) |
| 100 | return vi_command_mode(el, 0); |
| 101 | |
| 102 | return CC_NORM; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | /* ed_delete_prev_word(): |
no test coverage detected