mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: refactor FloatRelative usage
This commit is contained in:
parent
86992a7bb1
commit
073ab7cda8
@ -1047,7 +1047,8 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err)
|
||||
///
|
||||
/// @param[out] err Error details, if any
|
||||
/// @return the window handle or 0 when error
|
||||
Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config, Error *err)
|
||||
Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config,
|
||||
Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
FloatConfig fconfig = FLOAT_CONFIG_INIT;
|
||||
|
@ -512,21 +512,9 @@ Dictionary nvim_win_get_config(Window window, Error *err)
|
||||
PUT(rv, "row", FLOAT_OBJ(wp->w_float_config.row));
|
||||
PUT(rv, "col", FLOAT_OBJ(wp->w_float_config.col));
|
||||
|
||||
if (wp->w_floating) {
|
||||
switch (wp->w_float_config.relative) {
|
||||
case kFloatRelativeEditor:
|
||||
PUT(rv, "relative", STRING_OBJ(cstr_to_string("editor")));
|
||||
break;
|
||||
case kFloatRelativeWindow:
|
||||
PUT(rv, "relative", STRING_OBJ(cstr_to_string("win")));
|
||||
break;
|
||||
case kFloatRelativeCursor:
|
||||
PUT(rv, "relative", STRING_OBJ(cstr_to_string("cursor")));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
PUT(rv, "relative", STRING_OBJ(cstr_to_string("")));
|
||||
}
|
||||
const char *rel =
|
||||
wp->w_floating ? float_relative_str[wp->w_float_config.relative] : "";
|
||||
PUT(rv, "relative", STRING_OBJ(cstr_to_string(rel)));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -959,6 +959,7 @@ struct matchitem {
|
||||
};
|
||||
|
||||
typedef int FloatAnchor;
|
||||
typedef int FloatRelative;
|
||||
|
||||
enum {
|
||||
kFloatAnchorEast = 1,
|
||||
@ -971,11 +972,14 @@ enum {
|
||||
// SE -> kFloatAnchorSouth | kFloatAnchorEast
|
||||
EXTERN const char *const float_anchor_str[] INIT(= { "NW", "NE", "SW", "SE" });
|
||||
|
||||
typedef enum {
|
||||
enum {
|
||||
kFloatRelativeEditor = 0,
|
||||
kFloatRelativeWindow = 1,
|
||||
kFloatRelativeCursor = 2,
|
||||
} FloatRelative;
|
||||
};
|
||||
|
||||
EXTERN const char *const float_relative_str[] INIT(= { "editor", "window",
|
||||
"cursor" });
|
||||
|
||||
typedef struct {
|
||||
Window window;
|
||||
|
@ -685,11 +685,11 @@ static bool parse_float_relative(String relative, FloatRelative *out)
|
||||
*out = (FloatRelative)0;
|
||||
}
|
||||
char *str = relative.data;
|
||||
if (!STRICMP(str, "editor")) {
|
||||
if (striequal(str, "editor")) {
|
||||
*out = kFloatRelativeEditor;
|
||||
} else if (!STRICMP(str, "win")) {
|
||||
} else if (striequal(str, "win")) {
|
||||
*out = kFloatRelativeWindow;
|
||||
} else if (!STRICMP(str, "cursor")) {
|
||||
} else if (striequal(str, "cursor")) {
|
||||
*out = kFloatRelativeCursor;
|
||||
} else {
|
||||
return false;
|
||||
@ -804,7 +804,8 @@ bool parse_float_config(Dictionary config, FloatConfig *fconfig, bool reconf,
|
||||
}
|
||||
}
|
||||
|
||||
if (has_window && !(has_relative && fconfig->relative == kFloatRelativeWindow)) {
|
||||
if (has_window && !(has_relative
|
||||
&& fconfig->relative == kFloatRelativeWindow)) {
|
||||
api_set_error(err, kErrorTypeValidation,
|
||||
"'win' key is only valid with relative='win'");
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user