aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarco Hinz <mh.codebro@gmail.com>2019-03-13 20:09:00 +0100
committerMarco Hinz <mh.codebro@gmail.com>2019-03-16 12:35:57 +0100
commit98391cd6abb4079ffd79bbc31ed949fd6f2d1a31 (patch)
tree5231b7719d9a65bf7b5a81dd179152825908c329 /src
parentcfed9a4123afe3184c3914b6123869f2a52be250 (diff)
downloadrneovim-98391cd6abb4079ffd79bbc31ed949fd6f2d1a31.tar.gz
rneovim-98391cd6abb4079ffd79bbc31ed949fd6f2d1a31.tar.bz2
rneovim-98391cd6abb4079ffd79bbc31ed949fd6f2d1a31.zip
api: refactor FloatAnchor usage
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/window.c2
-rw-r--r--src/nvim/buffer_defs.h25
-rw-r--r--src/nvim/window.c24
3 files changed, 24 insertions, 27 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 8a03d7acef..b3acbe90cb 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -495,7 +495,7 @@ Dictionary nvim_win_get_config(Window window, Error *err)
PUT(rv, "focusable", BOOLEAN_OBJ(wp->w_float_config.focusable));
PUT(rv, "external", BOOLEAN_OBJ(wp->w_float_config.external));
PUT(rv, "anchor", STRING_OBJ(cstr_to_string(
- float_anchor_str[wp->w_float_config.anchor])));
+ float_anchor_str[wp->w_float_config.anchor])));
if (wp->w_float_config.relative == kFloatRelativeWindow) {
PUT(rv, "win", INTEGER_OBJ(wp->w_float_config.window));
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 48cef9b1e7..199399cf4d 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -958,20 +958,23 @@ struct matchitem {
int conceal_char; ///< cchar for Conceal highlighting
};
-typedef enum {
- kFloatAnchorEast = 1,
- kFloatAnchorSouth = 2,
+typedef int FloatAnchor;
+
+enum {
+ kFloatAnchorEast = 1,
+ kFloatAnchorSouth = 2,
+};
- kFloatAnchorNW = 0,
- kFloatAnchorNE = 1,
- kFloatAnchorSW = 2,
- kFloatAnchorSE = 3,
-} FloatAnchor;
+// NW -> 0
+// NE -> kFloatAnchorEast
+// SW -> kFloatAnchorSouth
+// SE -> kFloatAnchorSouth | kFloatAnchorEast
+EXTERN const char *const float_anchor_str[] INIT(= { "NW", "NE", "SW", "SE" });
typedef enum {
- kFloatRelativeEditor = 0,
- kFloatRelativeWindow = 1,
- kFloatRelativeCursor = 2,
+ kFloatRelativeEditor = 0,
+ kFloatRelativeWindow = 1,
+ kFloatRelativeCursor = 2,
} FloatRelative;
typedef struct {
diff --git a/src/nvim/window.c b/src/nvim/window.c
index edb5b06a2e..a4d2189ac1 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -614,12 +614,6 @@ static void ui_ext_win_position(win_T *wp)
wp->w_wincol, wp->w_width, wp->w_height);
return;
}
- const char *const anchor_str[] = {
- "NW",
- "NE",
- "SW",
- "SE"
- };
FloatConfig c = wp->w_float_config;
if (!c.external) {
@@ -635,7 +629,7 @@ static void ui_ext_win_position(win_T *wp)
api_clear_error(&dummy);
}
if (ui_has(kUIMultigrid)) {
- String anchor = cstr_to_string(anchor_str[c.anchor]);
+ String anchor = cstr_to_string(float_anchor_str[c.anchor]);
ui_call_win_float_pos(wp->w_grid.handle, wp->handle, anchor, grid->handle,
row, col, c.focusable);
} else {
@@ -672,14 +666,14 @@ static bool parse_float_anchor(String anchor, FloatAnchor *out)
*out = (FloatAnchor)0;
}
char *str = anchor.data;
- if (!STRICMP(str, "NW")) {
- *out = kFloatAnchorNW;
- } else if (!STRICMP(str, "NE")) {
- *out = kFloatAnchorNE;
- } else if (!STRICMP(str, "SW")) {
- *out = kFloatAnchorSW;
- } else if (!STRICMP(str, "SE")) {
- *out = kFloatAnchorSE;
+ if (striequal(str, "NW")) {
+ *out = 0; // NW is the default
+ } else if (striequal(str, "NE")) {
+ *out = kFloatAnchorEast;
+ } else if (striequal(str, "SW")) {
+ *out = kFloatAnchorSouth;
+ } else if (striequal(str, "SE")) {
+ *out = kFloatAnchorSouth | kFloatAnchorEast;
} else {
return false;
}