aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/buffer.c34
-rw-r--r--src/nvim/screen.c5
-rw-r--r--src/nvim/testdir/test_number.vim25
3 files changed, 46 insertions, 18 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index f84e8c99a4..b371c08d2a 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -1489,21 +1489,6 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
return 0;
}
- size_t len = 0;
- if (line < 0 || line > buf->b_ml.ml_line_count) {
- api_set_error(err, kErrorTypeValidation, "line value outside range");
- return 0;
- } else if (line < buf->b_ml.ml_line_count) {
- len = STRLEN(ml_get_buf(buf, (linenr_T)line+1, false));
- }
-
- if (col == -1) {
- col = (Integer)len;
- } else if (col < -1 || col > (Integer)len) {
- api_set_error(err, kErrorTypeValidation, "col value outside range");
- return 0;
- }
-
bool ephemeral = false;
uint64_t id = 0;
@@ -1674,6 +1659,22 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
}
}
+ size_t len = 0;
+ if (line < 0 || line > buf->b_ml.ml_line_count) {
+ api_set_error(err, kErrorTypeValidation, "line value outside range");
+ return 0;
+ } else if (line < buf->b_ml.ml_line_count) {
+ len = ephemeral ? MAXCOL : STRLEN(ml_get_buf(buf, (linenr_T)line+1, false));
+ }
+
+ if (col == -1) {
+ col = (Integer)len;
+ } else if (col < -1 || col > (Integer)len) {
+ api_set_error(err, kErrorTypeValidation, "col value outside range");
+ return 0;
+ }
+
+
// Only error out if they try to set end_right_gravity without
// setting end_col or end_line
if (line2 == -1 && col2 == -1 && end_gravity_set) {
@@ -1684,7 +1685,8 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id,
if (col2 >= 0) {
if (line2 >= 0 && line2 < buf->b_ml.ml_line_count) {
- len = STRLEN(ml_get_buf(buf, (linenr_T)line2 + 1, false));
+ len = ephemeral ? MAXCOL : STRLEN(
+ ml_get_buf(buf, (linenr_T)line2 + 1, false));
} else if (line2 == buf->b_ml.ml_line_count) {
// We are trying to add an extmark past final newline
len = 0;
diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 5c494d5066..04157a0154 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -2757,8 +2757,9 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow,
}
if (wp->w_p_rl) { // reverse line numbers
// like rl_mirror(), but keep the space at the end
- char_u *p2 = skiptowhite(extra) - 1;
- for (char_u *p1 = extra; p1 < p2; p1++, p2--) {
+ char_u *p2 = skipwhite(extra);
+ p2 = skiptowhite(p2) - 1;
+ for (char_u *p1 = skipwhite(extra); p1 < p2; p1++, p2--) {
const int t = *p1;
*p1 = *p2;
*p2 = t;
diff --git a/src/nvim/testdir/test_number.vim b/src/nvim/testdir/test_number.vim
index 81326bce14..eaabe3f67e 100644
--- a/src/nvim/testdir/test_number.vim
+++ b/src/nvim/testdir/test_number.vim
@@ -1,5 +1,6 @@
" Test for 'number' and 'relativenumber'
+source check.vim
source view_util.vim
func s:screen_lines(start, end) abort
@@ -263,3 +264,27 @@ func Test_relativenumber_uninitialised()
redraw
bwipe!
endfunc
+
+" Test for displaying line numbers with 'rightleft'
+func Test_number_rightleft()
+ CheckFeature rightleft
+ new
+ setlocal number
+ setlocal rightleft
+ call setline(1, range(1, 1000))
+ normal! 9Gzt
+ redraw!
+ call assert_match('^\s\+9 9$', Screenline(1))
+ normal! 10Gzt
+ redraw!
+ call assert_match('^\s\+01 10$', Screenline(1))
+ normal! 100Gzt
+ redraw!
+ call assert_match('^\s\+001 100$', Screenline(1))
+ normal! 1000Gzt
+ redraw!
+ call assert_match('^\s\+0001 1000$', Screenline(1))
+ bw!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab