comparison src/eval.c @ 30755:b7efd41d43b8 v9.0.0712

patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum Commit: https://github.com/vim/vim/commit/79f234499b6692cc16970b7455bc9b002242632f Author: Bram Moolenaar <Bram@vim.org> Date: Mon Oct 10 12:42:57 2022 +0100 patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnum Problem: Wrong column when calling setcursorcharpos() with zero lnum. Solution: Set the line number before calling buf_charidx_to_byteidx(). (closes #11329)
author Bram Moolenaar <Bram@vim.org>
date Mon, 10 Oct 2022 13:45:03 +0200
parents d914a3812d5b
children 5bc99d85f773
comparison
equal deleted inserted replaced
30754:12f55dde9050 30755:b7efd41d43b8
6021 semsg(_(e_invalid_value_for_line_number_str), name); 6021 semsg(_(e_invalid_value_for_line_number_str), name);
6022 return NULL; 6022 return NULL;
6023 } 6023 }
6024 6024
6025 /* 6025 /*
6026 * Convert list in "arg" into a position and optional file number. 6026 * Convert list in "arg" into position "psop" and optional file number "fnump".
6027 * When "fnump" is NULL there is no file number, only 3 items. 6027 * When "fnump" is NULL there is no file number, only 3 items: [lnum, col, off]
6028 * Note that the column is passed on as-is, the caller may want to decrement 6028 * Note that the column is passed on as-is, the caller may want to decrement
6029 * it to use 1 for the first column. 6029 * it to use 1 for the first column.
6030 * If "charcol" is TRUE use the column as the character index instead of the
6031 * byte index.
6030 * Return FAIL when conversion is not possible, doesn't check the position for 6032 * Return FAIL when conversion is not possible, doesn't check the position for
6031 * validity. 6033 * validity.
6032 */ 6034 */
6033 int 6035 int
6034 list2fpos( 6036 list2fpos(
6067 6069
6068 n = list_find_nr(l, i++, NULL); // col 6070 n = list_find_nr(l, i++, NULL); // col
6069 if (n < 0) 6071 if (n < 0)
6070 return FAIL; 6072 return FAIL;
6071 // If character position is specified, then convert to byte position 6073 // If character position is specified, then convert to byte position
6074 // If the line number is zero use the cursor line.
6072 if (charcol) 6075 if (charcol)
6073 { 6076 {
6074 buf_T *buf; 6077 buf_T *buf;
6075 6078
6076 // Get the text for the specified line in a loaded buffer 6079 // Get the text for the specified line in a loaded buffer
6077 buf = buflist_findnr(fnump == NULL ? curbuf->b_fnum : *fnump); 6080 buf = buflist_findnr(fnump == NULL ? curbuf->b_fnum : *fnump);
6078 if (buf == NULL || buf->b_ml.ml_mfp == NULL) 6081 if (buf == NULL || buf->b_ml.ml_mfp == NULL)
6079 return FAIL; 6082 return FAIL;
6080 6083
6081 n = buf_charidx_to_byteidx(buf, posp->lnum, n) + 1; 6084 n = buf_charidx_to_byteidx(buf,
6085 posp->lnum == 0 ? curwin->w_cursor.lnum : posp->lnum, n) + 1;
6082 } 6086 }
6083 posp->col = n; 6087 posp->col = n;
6084 6088
6085 n = list_find_nr(l, i, NULL); // off 6089 n = list_find_nr(l, i, NULL); // off
6086 if (n < 0) 6090 if (n < 0)