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
|
/// @param[out] err Error details, if any
|
||||||
/// @return the window handle or 0 when error
|
/// @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)
|
FUNC_API_SINCE(6)
|
||||||
{
|
{
|
||||||
FloatConfig fconfig = FLOAT_CONFIG_INIT;
|
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, "row", FLOAT_OBJ(wp->w_float_config.row));
|
||||||
PUT(rv, "col", FLOAT_OBJ(wp->w_float_config.col));
|
PUT(rv, "col", FLOAT_OBJ(wp->w_float_config.col));
|
||||||
|
|
||||||
if (wp->w_floating) {
|
const char *rel =
|
||||||
switch (wp->w_float_config.relative) {
|
wp->w_floating ? float_relative_str[wp->w_float_config.relative] : "";
|
||||||
case kFloatRelativeEditor:
|
PUT(rv, "relative", STRING_OBJ(cstr_to_string(rel)));
|
||||||
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("")));
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -959,6 +959,7 @@ struct matchitem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef int FloatAnchor;
|
typedef int FloatAnchor;
|
||||||
|
typedef int FloatRelative;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
kFloatAnchorEast = 1,
|
kFloatAnchorEast = 1,
|
||||||
@ -971,11 +972,14 @@ enum {
|
|||||||
// SE -> kFloatAnchorSouth | kFloatAnchorEast
|
// SE -> kFloatAnchorSouth | kFloatAnchorEast
|
||||||
EXTERN const char *const float_anchor_str[] INIT(= { "NW", "NE", "SW", "SE" });
|
EXTERN const char *const float_anchor_str[] INIT(= { "NW", "NE", "SW", "SE" });
|
||||||
|
|
||||||
typedef enum {
|
enum {
|
||||||
kFloatRelativeEditor = 0,
|
kFloatRelativeEditor = 0,
|
||||||
kFloatRelativeWindow = 1,
|
kFloatRelativeWindow = 1,
|
||||||
kFloatRelativeCursor = 2,
|
kFloatRelativeCursor = 2,
|
||||||
} FloatRelative;
|
};
|
||||||
|
|
||||||
|
EXTERN const char *const float_relative_str[] INIT(= { "editor", "window",
|
||||||
|
"cursor" });
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Window window;
|
Window window;
|
||||||
|
@ -685,11 +685,11 @@ static bool parse_float_relative(String relative, FloatRelative *out)
|
|||||||
*out = (FloatRelative)0;
|
*out = (FloatRelative)0;
|
||||||
}
|
}
|
||||||
char *str = relative.data;
|
char *str = relative.data;
|
||||||
if (!STRICMP(str, "editor")) {
|
if (striequal(str, "editor")) {
|
||||||
*out = kFloatRelativeEditor;
|
*out = kFloatRelativeEditor;
|
||||||
} else if (!STRICMP(str, "win")) {
|
} else if (striequal(str, "win")) {
|
||||||
*out = kFloatRelativeWindow;
|
*out = kFloatRelativeWindow;
|
||||||
} else if (!STRICMP(str, "cursor")) {
|
} else if (striequal(str, "cursor")) {
|
||||||
*out = kFloatRelativeCursor;
|
*out = kFloatRelativeCursor;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
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,
|
api_set_error(err, kErrorTypeValidation,
|
||||||
"'win' key is only valid with relative='win'");
|
"'win' key is only valid with relative='win'");
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user