api/ui: allow set bounds row and col to be less than 0; ui_pum_get_pos: return first extui bounds information instead of reducing

This commit is contained in:
Yatao Li
2020-03-22 17:27:49 +08:00
parent ed6230434b
commit d372c804aa
3 changed files with 15 additions and 29 deletions

View File

@@ -382,17 +382,11 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height,
return; return;
} }
if (row < 0) { if (width <= 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos row >= 0"); api_set_error(err, kErrorTypeValidation, "Expected width > 0");
return;
} else if (col < 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos col >= 0");
return;
} else if (width <= 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos width > 0");
return; return;
} else if (height <= 0) { } else if (height <= 0) {
api_set_error(err, kErrorTypeValidation, "Expected pumpos height > 0"); api_set_error(err, kErrorTypeValidation, "Expected height > 0");
return; return;
} }

View File

@@ -237,24 +237,18 @@ int ui_pum_get_height(void)
void ui_pum_get_pos(double *pwidth, double *pheight, double *prow, double *pcol) void ui_pum_get_pos(double *pwidth, double *pheight, double *prow, double *pcol)
{ {
double w = 0.0, h = 0.0, r = -1.0, c = -1.0; double w = 0.0, h = 0.0, r = 0.0, c = 0.0;
bool found = false; bool found = false;
for (size_t i = 1; i < ui_count; i++) { for (size_t i = 1; i < ui_count; i++) {
if (!uis[i]->pum_pos) { if (!uis[i]->pum_pos) {
continue; continue;
} }
if (!found) { w = uis[i]->pum_width;
w = uis[i]->pum_width; h = uis[i]->pum_height;
h = uis[i]->pum_height; r = uis[i]->pum_row;
r = uis[i]->pum_row; c = uis[i]->pum_col;
c = uis[i]->pum_col; found = true;
found = true; break;
} else {
w = MIN(uis[i]->pum_width, w);
h = MIN(uis[i]->pum_height, h);
r = MIN(uis[i]->pum_row, r);
c = MIN(uis[i]->pum_col, c);
}
} }
if (found) { if (found) {
*pwidth = w; *pwidth = w;

View File

@@ -481,16 +481,14 @@ describe('ui/ext_popupmenu', function()
}} }}
end) end)
it('an error occurs if row or col set less than 0', function() it('no error occurs if row or col set less than 0', function()
local ok, err, _ local ok, err, _
ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5)
eq(true, ok) eq(true, ok)
ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, -1.0, 0.0) ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, -1.0, 0.0)
eq(false, ok) eq(true, ok)
matches('.*: Expected pumpos row >= 0', err) ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, -1.0)
ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, -1.0) eq(true, ok)
eq(false, ok)
matches('.*: Expected pumpos col >= 0', err)
end) end)
it('an error occurs if width or height set 0 or less', function() it('an error occurs if width or height set 0 or less', function()