MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / positionToColAndRow

Function positionToColAndRow

tools/shell/linenoise.cpp:2143–2167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2141}
2142
2143void 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
2169size_t colAndRowToPosition(size_t target_row, size_t target_col, struct linenoiseState* l) {
2170 int plen = linenoiseComputeRenderWidth(l->prompt, strlen(l->prompt));

Callers 4

refreshMultiLineFunction · 0.85
linenoiseEditMoveRowUpFunction · 0.85
linenoiseEditMoveRowDownFunction · 0.85
linenoiseEditFunction · 0.85

Calls 3

isNewlineFunction · 0.85
nextPositionFunction · 0.85

Tested by

no test coverage detected