mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
move ins_str
This commit is contained in:
parent
c0f71ef826
commit
75598927f2
@ -644,8 +644,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
|
|||||||
* Note: Does NOT handle Replace mode.
|
* Note: Does NOT handle Replace mode.
|
||||||
* Caller must have prepared for undo.
|
* Caller must have prepared for undo.
|
||||||
*/
|
*/
|
||||||
void
|
void ins_str(char_u *s)
|
||||||
ins_str(char_u *s)
|
|
||||||
{
|
{
|
||||||
char_u *oldp, *newp;
|
char_u *oldp, *newp;
|
||||||
int newlen = (int)STRLEN(s);
|
int newlen = (int)STRLEN(s);
|
||||||
@ -660,15 +659,16 @@ ins_str(char_u *s)
|
|||||||
oldp = ml_get(lnum);
|
oldp = ml_get(lnum);
|
||||||
oldlen = (int)STRLEN(oldp);
|
oldlen = (int)STRLEN(oldp);
|
||||||
|
|
||||||
newp = alloc_check((unsigned)(oldlen + newlen + 1));
|
newp = (char_u *)xmalloc((size_t)oldlen + (size_t)newlen + 1);
|
||||||
if (newp == NULL)
|
if (col > 0) {
|
||||||
return;
|
memmove(newp, oldp, (size_t)col);
|
||||||
if (col > 0)
|
}
|
||||||
mch_memmove(newp, oldp, (size_t)col);
|
memmove(newp + col, s, (size_t)newlen);
|
||||||
mch_memmove(newp + col, s, (size_t)newlen);
|
int bytes = oldlen - col + 1;
|
||||||
mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
|
assert(bytes >= 0);
|
||||||
ml_replace(lnum, newp, FALSE);
|
memmove(newp + col + newlen, oldp + col, (size_t)bytes);
|
||||||
inserted_bytes(lnum, col, newlen);
|
ml_replace(lnum, newp, false);
|
||||||
|
changed_bytes(lnum, col);
|
||||||
curwin->w_cursor.col += newlen;
|
curwin->w_cursor.col += newlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1398,39 +1398,6 @@ void ins_char(int c)
|
|||||||
ins_char_bytes(buf, n);
|
ins_char_bytes(buf, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Insert a string at the cursor position.
|
|
||||||
* Note: Does NOT handle Replace mode.
|
|
||||||
* Caller must have prepared for undo.
|
|
||||||
*/
|
|
||||||
void ins_str(char_u *s)
|
|
||||||
{
|
|
||||||
char_u *oldp, *newp;
|
|
||||||
int newlen = (int)STRLEN(s);
|
|
||||||
int oldlen;
|
|
||||||
colnr_T col;
|
|
||||||
linenr_T lnum = curwin->w_cursor.lnum;
|
|
||||||
|
|
||||||
if (virtual_active() && curwin->w_cursor.coladd > 0)
|
|
||||||
coladvance_force(getviscol());
|
|
||||||
|
|
||||||
col = curwin->w_cursor.col;
|
|
||||||
oldp = ml_get(lnum);
|
|
||||||
oldlen = (int)STRLEN(oldp);
|
|
||||||
|
|
||||||
newp = (char_u *)xmalloc((size_t)oldlen + (size_t)newlen + 1);
|
|
||||||
if (col > 0) {
|
|
||||||
memmove(newp, oldp, (size_t)col);
|
|
||||||
}
|
|
||||||
memmove(newp + col, s, (size_t)newlen);
|
|
||||||
int bytes = oldlen - col + 1;
|
|
||||||
assert(bytes >= 0);
|
|
||||||
memmove(newp + col + newlen, oldp + col, (size_t)bytes);
|
|
||||||
ml_replace(lnum, newp, false);
|
|
||||||
changed_bytes(lnum, col);
|
|
||||||
curwin->w_cursor.col += newlen;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete one character under the cursor.
|
// Delete one character under the cursor.
|
||||||
// If "fixpos" is true, don't leave the cursor on the NUL after the line.
|
// If "fixpos" is true, don't leave the cursor on the NUL after the line.
|
||||||
// Caller must have prepared for undo.
|
// Caller must have prepared for undo.
|
||||||
|
Loading…
Reference in New Issue
Block a user