comparison src/memline.c @ 34487:67674e379c26 v9.1.0151

patch 9.1.0151: ml_get_buf_len() does not consider text properties Commit: https://github.com/vim/vim/commit/a72d1be5a9984709fc66f460b443ad4a38506113 Author: Christian Brabandt <cb@256bit.org> Date: Tue Mar 5 20:43:25 2024 +0100 patch 9.1.0151: ml_get_buf_len() does not consider text properties Problem: ml_get_buf_len() does not consider text properties (zeertzj) Solution: Store text length excluding text properties length in addition in the memline related #14123 closes: #14133 Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 05 Mar 2024 21:00:02 +0100
parents 89f9a7925fff
children 80991201ed38
comparison
equal deleted inserted replaced
34486:0290a9a4c0e7 34487:67674e379c26
2701 ml_get_buf_len(buf_T *buf, linenr_T lnum) 2701 ml_get_buf_len(buf_T *buf, linenr_T lnum)
2702 { 2702 {
2703 if (*ml_get_buf(buf, lnum, FALSE) == NUL) 2703 if (*ml_get_buf(buf, lnum, FALSE) == NUL)
2704 return 0; 2704 return 0;
2705 2705
2706 return buf->b_ml.ml_line_len - 1; 2706 return buf->b_ml.ml_line_textlen - 1;
2707 } 2707 }
2708 2708
2709 /* 2709 /*
2710 * Return a pointer to a line in a specific buffer 2710 * Return a pointer to a line in a specific buffer
2711 * 2711 *
2735 } 2735 }
2736 ml_flush_line(buf); 2736 ml_flush_line(buf);
2737 errorret: 2737 errorret:
2738 STRCPY(questions, "???"); 2738 STRCPY(questions, "???");
2739 buf->b_ml.ml_line_len = 4; 2739 buf->b_ml.ml_line_len = 4;
2740 buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
2740 buf->b_ml.ml_line_lnum = lnum; 2741 buf->b_ml.ml_line_lnum = lnum;
2741 return questions; 2742 return questions;
2742 } 2743 }
2743 if (lnum <= 0) // pretend line 0 is line 1 2744 if (lnum <= 0) // pretend line 0 is line 1
2744 lnum = 1; 2745 lnum = 1;
2745 2746
2746 if (buf->b_ml.ml_mfp == NULL) // there are no lines 2747 if (buf->b_ml.ml_mfp == NULL) // there are no lines
2747 { 2748 {
2748 buf->b_ml.ml_line_len = 1; 2749 buf->b_ml.ml_line_len = 1;
2750 buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
2749 return (char_u *)""; 2751 return (char_u *)"";
2750 } 2752 }
2751 2753
2752 /* 2754 /*
2753 * See if it is the same line as requested last time. 2755 * See if it is the same line as requested last time.
2794 else 2796 else
2795 end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK); 2797 end = ((dp->db_index[idx - 1]) & DB_INDEX_MASK);
2796 2798
2797 buf->b_ml.ml_line_ptr = (char_u *)dp + start; 2799 buf->b_ml.ml_line_ptr = (char_u *)dp + start;
2798 buf->b_ml.ml_line_len = end - start; 2800 buf->b_ml.ml_line_len = end - start;
2801 #if defined(FEAT_BYTEOFF) && defined(FEAT_PROP_POPUP)
2802 if (buf->b_has_textprop)
2803 buf->b_ml.ml_line_textlen = (int)STRLEN(buf->b_ml.ml_line_ptr) + 1;
2804 else
2805 #endif
2806 buf->b_ml.ml_line_textlen = buf->b_ml.ml_line_len;
2799 buf->b_ml.ml_line_lnum = lnum; 2807 buf->b_ml.ml_line_lnum = lnum;
2800 buf->b_ml.ml_flags &= ~(ML_LINE_DIRTY | ML_ALLOCATED); 2808 buf->b_ml.ml_flags &= ~(ML_LINE_DIRTY | ML_ALLOCATED);
2801 } 2809 }
2802 if (will_change) 2810 if (will_change)
2803 { 2811 {
3644 if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED)) 3652 if (curbuf->b_ml.ml_flags & (ML_LINE_DIRTY | ML_ALLOCATED))
3645 vim_free(curbuf->b_ml.ml_line_ptr); // free allocated line 3653 vim_free(curbuf->b_ml.ml_line_ptr); // free allocated line
3646 3654
3647 curbuf->b_ml.ml_line_ptr = line; 3655 curbuf->b_ml.ml_line_ptr = line;
3648 curbuf->b_ml.ml_line_len = len; 3656 curbuf->b_ml.ml_line_len = len;
3657 curbuf->b_ml.ml_line_textlen = len_arg + 1;
3649 curbuf->b_ml.ml_line_lnum = lnum; 3658 curbuf->b_ml.ml_line_lnum = lnum;
3650 curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY; 3659 curbuf->b_ml.ml_flags = (curbuf->b_ml.ml_flags | ML_LINE_DIRTY) & ~ML_EMPTY;
3651 3660
3652 return OK; 3661 return OK;
3653 } 3662 }