| 2141 | } |
| 2142 | |
| 2143 | void positionToColAndRow(size_t target_pos, int& out_row, int& out_col, size_t& rows, size_t& cols, |
| 2144 | struct linenoiseState* l) { |
| 2145 | int plen = linenoiseComputeRenderWidth(l->prompt, strlen(l->prompt)); |
| 2146 | out_row = -1; |
| 2147 | out_col = 0; |
| 2148 | rows = 1; |
| 2149 | cols = plen; |
| 2150 | size_t cpos = 0; |
| 2151 | while (cpos < l->len) { |
| 2152 | if (cols >= l->cols && !isNewline(l->buf[cpos])) { |
| 2153 | // exceeded width - move to next line |
| 2154 | rows++; |
| 2155 | cols = 0; |
| 2156 | } |
| 2157 | if (out_row < 0 && cpos >= target_pos) { |
| 2158 | out_row = rows; |
| 2159 | out_col = cols; |
| 2160 | } |
| 2161 | nextPosition(l->buf, l->len, cpos, rows, cols, plen, l->cols); |
| 2162 | } |
| 2163 | if (target_pos == l->len) { |
| 2164 | out_row = rows; |
| 2165 | out_col = cols; |
| 2166 | } |
| 2167 | } |
| 2168 | |
| 2169 | size_t colAndRowToPosition(size_t target_row, size_t target_col, struct linenoiseState* l) { |
| 2170 | int plen = linenoiseComputeRenderWidth(l->prompt, strlen(l->prompt)); |
no test coverage detected