diff src/textprop.c @ 17863:08f1dd29550e v8.1.1928

patch 8.1.1928: popup windows don't move with the text when making changes Commit: https://github.com/vim/vim/commit/12034e22dd80cf533ac1c681be521ab299383f63 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 25 22:25:02 2019 +0200 patch 8.1.1928: popup windows don't move with the text when making changes Problem: Popup windows don't move with the text when making changes. Solution: Add the 'textprop" property to the popup window options, position the popup relative to a text property. (closes #4560) No tests yet.
author Bram Moolenaar <Bram@vim.org>
date Sun, 25 Aug 2019 22:30:03 +0200
parents 0f7ae8010787
children eaf8b21d80e7
line wrap: on
line diff
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -91,6 +91,20 @@ find_prop(char_u *name, buf_T *buf)
 }
 
 /*
+ * Get the prop type ID of "name".
+ * When not found return zero.
+ */
+    int
+find_prop_type_id(char_u *name, buf_T *buf)
+{
+    proptype_T *pt = find_prop(name, buf);
+
+    if (pt == NULL)
+	return 0;
+    return pt->pt_id;
+}
+
+/*
  * Lookup a property type by name.  First in "buf" and when not found in the
  * global types.
  * When not found gives an error message and returns NULL.
@@ -368,6 +382,40 @@ get_text_props(buf_T *buf, linenr_T lnum
 }
 
 /*
+ * Find text property "type_id" in the visible lines of window "wp".
+ * Match "id" when it is > 0.
+ * Returns FAIL when not found.
+ */
+    int
+find_visible_prop(win_T *wp, int type_id, int id, textprop_T *prop,
+							  linenr_T *found_lnum)
+{
+    linenr_T		lnum;
+    char_u		*props;
+    int			count;
+    int			i;
+
+    // w_botline may not have been updated yet.
+    if (wp->w_botline > wp->w_buffer->b_ml.ml_line_count)
+	wp->w_botline = wp->w_buffer->b_ml.ml_line_count + 1;
+    for (lnum = wp->w_topline; lnum < wp->w_botline; ++lnum)
+    {
+	count = get_text_props(wp->w_buffer, lnum, &props, FALSE);
+	for (i = 0; i < count; ++i)
+	{
+	    mch_memmove(prop, props + i * sizeof(textprop_T),
+							   sizeof(textprop_T));
+	    if (prop->tp_type == type_id && (id <= 0 || prop->tp_id == id))
+	    {
+		*found_lnum = lnum;
+		return OK;
+	    }
+	}
+    }
+    return FAIL;
+}
+
+/*
  * Set the text properties for line "lnum" to "props" with length "len".
  * If "len" is zero text properties are removed, "props" is not used.
  * Any existing text properties are dropped.