API: buf_get_lines, buf_line_count handle unloaded buffers #7688

This commit is contained in:
Peter Hodge
2018-06-29 11:43:37 +10:00
parent ae52170a52
commit 40e2d6b59b

View File

@@ -45,6 +45,11 @@ Integer nvim_buf_line_count(Buffer buffer, Error *err)
return 0;
}
// return sentinel value if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) {
return 0;
}
return buf->b_ml.ml_line_count;
}
@@ -221,6 +226,11 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
return rv;
}
// return sentinel value if the buffer isn't loaded
if (buf->b_ml.ml_mfp == NULL) {
return rv;
}
bool oob = false;
start = normalize_index(buf, start, &oob);
end = normalize_index(buf, end, &oob);