comparison src/ops.c @ 6826:bf3e6012dfbd v7.4.734

patch 7.4.734 Problem: ml_get error when using "p" in a Visual selection in the last line. Solution: Change the behavior at the last line. (Yukihiro Nakadaira)
author Bram Moolenaar <bram@vim.org>
date Tue, 09 Jun 2015 20:20:03 +0200
parents 399216850e36
children ac13f3533571
comparison
equal deleted inserted replaced
6825:e274ed6dd308 6826:bf3e6012dfbd
1957 /* When deleted a char in the line, reset coladd. */ 1957 /* When deleted a char in the line, reset coladd. */
1958 if (gchar_cursor() != NUL) 1958 if (gchar_cursor() != NUL)
1959 curwin->w_cursor.coladd = 0; 1959 curwin->w_cursor.coladd = 0;
1960 } 1960 }
1961 #endif 1961 #endif
1962 if (oap->op_type == OP_DELETE 1962 (void)del_bytes((long)n, !virtual_op,
1963 && oap->inclusive 1963 oap->op_type == OP_DELETE && !oap->is_VIsual);
1964 && oap->end.lnum == curbuf->b_ml.ml_line_count
1965 && n > (int)STRLEN(ml_get(oap->end.lnum)))
1966 {
1967 /* Special case: gH<Del> deletes the last line. */
1968 del_lines(1L, FALSE);
1969 }
1970 else
1971 {
1972 (void)del_bytes((long)n, !virtual_op,
1973 oap->op_type == OP_DELETE && !oap->is_VIsual);
1974 }
1975 } 1964 }
1976 else /* delete characters between lines */ 1965 else /* delete characters between lines */
1977 { 1966 {
1978 pos_T curpos; 1967 pos_T curpos;
1979 int delete_last_line;
1980 1968
1981 /* save deleted and changed lines for undo */ 1969 /* save deleted and changed lines for undo */
1982 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), 1970 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1),
1983 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) 1971 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL)
1984 return FAIL; 1972 return FAIL;
1985 1973
1986 delete_last_line = (oap->end.lnum == curbuf->b_ml.ml_line_count);
1987 truncate_line(TRUE); /* delete from cursor to end of line */ 1974 truncate_line(TRUE); /* delete from cursor to end of line */
1988 1975
1989 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ 1976 curpos = curwin->w_cursor; /* remember curwin->w_cursor */
1990 ++curwin->w_cursor.lnum; 1977 ++curwin->w_cursor.lnum;
1991 del_lines((long)(oap->line_count - 2), FALSE); 1978 del_lines((long)(oap->line_count - 2), FALSE);
1992 1979
1993 if (delete_last_line) 1980 /* delete from start of line until op_end */
1994 oap->end.lnum = curbuf->b_ml.ml_line_count;
1995
1996 n = (oap->end.col + 1 - !oap->inclusive); 1981 n = (oap->end.col + 1 - !oap->inclusive);
1997 if (oap->inclusive && delete_last_line 1982 curwin->w_cursor.col = 0;
1998 && n > (int)STRLEN(ml_get(oap->end.lnum))) 1983 (void)del_bytes((long)n, !virtual_op,
1999 { 1984 oap->op_type == OP_DELETE && !oap->is_VIsual);
2000 /* Special case: gH<Del> deletes the last line. */ 1985 curwin->w_cursor = curpos; /* restore curwin->w_cursor */
2001 del_lines(1L, FALSE); 1986 (void)do_join(2, FALSE, FALSE, FALSE, FALSE);
2002 curwin->w_cursor = curpos; /* restore curwin->w_cursor */
2003 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
2004 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
2005 }
2006 else
2007 {
2008 /* delete from start of line until op_end */
2009 curwin->w_cursor.col = 0;
2010 (void)del_bytes((long)n, !virtual_op,
2011 oap->op_type == OP_DELETE && !oap->is_VIsual);
2012 curwin->w_cursor = curpos; /* restore curwin->w_cursor */
2013 }
2014 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
2015 (void)do_join(2, FALSE, FALSE, FALSE, FALSE);
2016 } 1987 }
2017 } 1988 }
2018 1989
2019 msgmore(curbuf->b_ml.ml_line_count - old_lcount); 1990 msgmore(curbuf->b_ml.ml_line_count - old_lcount);
2020 1991