diff options
| author | Björn Linse <bjorn.linse@gmail.com> | 2021-01-22 09:55:00 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-22 09:55:00 +0100 | 
| commit | b803bfa5aab1a2f8c74984fbf1176d1ff57d8540 (patch) | |
| tree | f155fe3a7c5afd6457e3e726ea868a41b2bcd3a3 /src/nvim/api/buffer.c | |
| parent | 1607dd071fe1685cf42b0182b8d1d72152af2c40 (diff) | |
| parent | 2ac0ca2025746c39d10aad0e32749174b4222448 (diff) | |
| download | rneovim-b803bfa5aab1a2f8c74984fbf1176d1ff57d8540.tar.gz rneovim-b803bfa5aab1a2f8c74984fbf1176d1ff57d8540.tar.bz2 rneovim-b803bfa5aab1a2f8c74984fbf1176d1ff57d8540.zip | |
Merge pull request #13679 from chentau/gravity
Extmarks api: allow for gravity
Diffstat (limited to 'src/nvim/api/buffer.c')
| -rw-r--r-- | src/nvim/api/buffer.c | 42 | 
1 files changed, 39 insertions, 3 deletions
| diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 8d82d22040..2890d89bc0 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -1400,6 +1400,13 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id,  ///                   callbacks. The mark will only be used for the current  ///                   redraw cycle, and not be permantently stored in the  ///                   buffer. +///               - right_gravity : boolean that indicates the direction +///                   the extmark will be shifted in when new text is inserted +///                   (true for right, false for left).  defaults to true. +///               - end_right_gravity : boolean that indicates the direction +///                   the extmark end position (if it exists) will be shifted +///                   in when new text is inserted (true for right, false +///                   for left). Defaults to false.  /// @param[out]  err   Error details, if any  /// @return Id of the created/updated extmark  Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, @@ -1440,6 +1447,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,    DecorPriority priority = DECOR_PRIORITY_BASE;    colnr_T col2 = 0;    VirtText virt_text = KV_INITIAL_VALUE; +  bool right_gravity = true; +  bool end_right_gravity = false; +  bool end_gravity_set = false; +    for (size_t i = 0; i < opts.size; i++) {      String k = opts.items[i].key;      Object *v = &opts.items[i].value; @@ -1522,12 +1533,35 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,          goto error;        }        priority = (DecorPriority)v->data.integer; +    } else if (strequal("right_gravity", k.data)) { +      if (v->type != kObjectTypeBoolean) { +        api_set_error(err, kErrorTypeValidation, +                      "right_gravity must be a boolean"); +        goto error; +      } +      right_gravity = v->data.boolean; +    } else if (strequal("end_right_gravity", k.data)) { +      if (v->type != kObjectTypeBoolean) { +        api_set_error(err, kErrorTypeValidation, +                      "end_right_gravity must be a boolean"); +        goto error; +      } +      end_right_gravity = v->data.boolean; +      end_gravity_set = true;      } else {        api_set_error(err, kErrorTypeValidation, "unexpected key: %s", k.data);        goto error;      }    } +  // Only error out if they try to set end_right_gravity without +  // setting end_col or end_line +  if (line2 == -1 && col2 == 0 && end_gravity_set) { +    api_set_error(err, kErrorTypeValidation, +                  "cannot set end_right_gravity " +                  "without setting end_line or end_col"); +  } +    if (col2 >= 0) {      if (line2 >= 0 && line2 < buf->b_ml.ml_line_count) {        len = STRLEN(ml_get_buf(buf, (linenr_T)line2 + 1, false)); @@ -1572,7 +1606,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,      }      id = extmark_set(buf, (uint64_t)ns_id, id, (int)line, (colnr_T)col, -                     line2, col2, decor, kExtmarkNoUndo); +                     line2, col2, decor, right_gravity, +                     end_right_gravity, kExtmarkNoUndo);    }    return (Integer)id; @@ -1687,7 +1722,7 @@ Integer nvim_buf_add_highlight(Buffer buffer,    extmark_set(buf, ns_id, 0,                (int)line, (colnr_T)col_start,                end_line, (colnr_T)col_end, -              decor_hl(hl_id), kExtmarkNoUndo); +              decor_hl(hl_id), true, false, kExtmarkNoUndo);    return src_id;  } @@ -1796,7 +1831,8 @@ Integer nvim_buf_set_virtual_text(Buffer buffer,    Decoration *decor = xcalloc(1, sizeof(*decor));    decor->virt_text = virt_text; -  extmark_set(buf, ns_id, 0, (int)line, 0, -1, -1, decor, kExtmarkNoUndo); +  extmark_set(buf, ns_id, 0, (int)line, 0, -1, -1, decor, true, +              false, kExtmarkNoUndo);    return src_id;  } | 
