To: vim_dev@googlegroups.com Subject: Patch 8.2.2429 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2429 Problem: :goto does not work correctly with text properties. (Sam McCall) Solution: Add a test. (Andrew Radev) Also use the text property size when computing the remaining offset. (closes #5930) Files: src/memline.c, src/testdir/test_textprop.vim *** ../vim-8.2.2428/src/memline.c 2020-12-18 19:49:52.341571870 +0100 --- src/memline.c 2021-01-30 17:08:20.381671004 +0100 *************** *** 5701,5706 **** --- 5701,5710 ---- while ((lnum != 0 && curline < lnum) || (offset != 0 && size < offset)) { + #ifdef FEAT_PROP_POPUP + size_t textprop_total = 0; + #endif + if (curline > buf->b_ml.ml_line_count || (hp = ml_find_line(buf, curline, ML_FIND)) == NULL) return -1; *************** *** 5722,5739 **** } else { - #ifdef FEAT_PROP_POPUP - size_t textprop_total = 0; - size_t textprop_size = 0; - char_u *l1, *l2; - #endif - extra = 0; for (;;) { #ifdef FEAT_PROP_POPUP if (buf->b_has_textprop) { // compensate for the extra bytes taken by textprops l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK); l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end --- 5726,5741 ---- } else { extra = 0; for (;;) { #ifdef FEAT_PROP_POPUP + size_t textprop_size = 0; + if (buf->b_has_textprop) { + char_u *l1, *l2; + // compensate for the extra bytes taken by textprops l1 = (char_u *)dp + ((dp->db_index[idx]) & DB_INDEX_MASK); l2 = (char_u *)dp + (idx == 0 ? dp->db_txt_end *************** *** 5763,5769 **** } } #ifdef FEAT_PROP_POPUP ! if (buf->b_has_textprop) { int i; --- 5765,5771 ---- } } #ifdef FEAT_PROP_POPUP ! if (buf->b_has_textprop && lnum != 0) { int i; *************** *** 5771,5782 **** // lengths. len = 0; for (i = start_idx; i <= idx; ++i) ! len += (int)STRLEN((char_u *)dp ! + ((dp->db_index[i]) & DB_INDEX_MASK)) + 1; } else #endif ! len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK); size += len; if (offset != 0 && size >= offset) { --- 5773,5790 ---- // lengths. len = 0; for (i = start_idx; i <= idx; ++i) ! { ! char_u *p = (char_u *)dp + ((dp->db_index[i]) & DB_INDEX_MASK); ! len += (int)STRLEN(p) + 1; ! } } else #endif ! len = text_end - ((dp->db_index[idx]) & DB_INDEX_MASK) ! #ifdef FEAT_PROP_POPUP ! - (long)textprop_total ! #endif ! ; size += len; if (offset != 0 && size >= offset) { *************** *** 5786,5792 **** *offp = offset - size + len; else *offp = offset - size + len ! - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)); curline += idx - start_idx + extra; if (curline > buf->b_ml.ml_line_count) return -1; // exactly one byte beyond the end --- 5794,5804 ---- *offp = offset - size + len; else *offp = offset - size + len ! - (text_end - ((dp->db_index[idx - 1]) & DB_INDEX_MASK)) ! #ifdef FEAT_PROP_POPUP ! + (long)textprop_total ! #endif ! ; curline += idx - start_idx + extra; if (curline > buf->b_ml.ml_line_count) return -1; // exactly one byte beyond the end *** ../vim-8.2.2428/src/testdir/test_textprop.vim 2020-12-23 14:35:56.963016983 +0100 --- src/testdir/test_textprop.vim 2021-01-30 17:12:31.236832941 +0100 *************** *** 771,776 **** --- 771,806 ---- call prop_type_delete('prop') endfunc + func Test_prop_goto_byte() + new + call setline(1, '') + call setline(2, 'two three') + call setline(3, '') + call setline(4, 'four five') + + call prop_type_add('testprop', {'highlight': 'Directory'}) + call search('^two') + call prop_add(line('.'), col('.'), { + \ 'length': len('two'), + \ 'type': 'testprop' + \ }) + + call search('two \zsthree') + let expected_pos = line2byte(line('.')) + col('.') - 1 + exe expected_pos .. 'goto' + let actual_pos = line2byte(line('.')) + col('.') - 1 + eval actual_pos->assert_equal(expected_pos) + + call search('four \zsfive') + let expected_pos = line2byte(line('.')) + col('.') - 1 + exe expected_pos .. 'goto' + let actual_pos = line2byte(line('.')) + col('.') - 1 + eval actual_pos->assert_equal(expected_pos) + + call prop_type_delete('testprop') + bwipe! + endfunc + func Test_prop_undo() new call prop_type_add('comment', {'highlight': 'Directory'}) *** ../vim-8.2.2428/src/version.c 2021-01-30 15:39:44.312670945 +0100 --- src/version.c 2021-01-30 17:15:08.956299760 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2429, /**/ -- Edison's greatest achievement came in 1879, when he invented the electric company. Edison's design was a brilliant adaptation of the simple electrical circuit: the electric company sends electricity through a wire to a customer, then immediately gets the electricity back through another wire /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///