mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
clipboard: clean up unnamedclip logic
This commit is contained in:
parent
63efb9b1f1
commit
61aaf815db
@ -915,14 +915,7 @@ getcount:
|
|||||||
&& !oap->op_type
|
&& !oap->op_type
|
||||||
&& (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) {
|
&& (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG))) {
|
||||||
clearop(oap);
|
clearop(oap);
|
||||||
{
|
set_reg_var(0);
|
||||||
int regname = 0;
|
|
||||||
|
|
||||||
/* Adjust the register according to 'clipboard', so that when
|
|
||||||
* "unnamed" is present it becomes '*' or '+' instead of '"'. */
|
|
||||||
adjust_clipboard_register(®name);
|
|
||||||
set_reg_var(regname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the length of mapped chars again after typing a count, second
|
/* Get the length of mapped chars again after typing a count, second
|
||||||
@ -5105,7 +5098,6 @@ static void nv_brackets(cmdarg_T *cap)
|
|||||||
end = equalpos(start, VIsual) ? curwin->w_cursor : VIsual;
|
end = equalpos(start, VIsual) ? curwin->w_cursor : VIsual;
|
||||||
curwin->w_cursor = (dir == BACKWARD ? start : end);
|
curwin->w_cursor = (dir == BACKWARD ? start : end);
|
||||||
}
|
}
|
||||||
adjust_clipboard_register(®name);
|
|
||||||
prep_redo_cmd(cap);
|
prep_redo_cmd(cap);
|
||||||
do_put(regname, dir, cap->count1, PUT_FIXINDENT);
|
do_put(regname, dir, cap->count1, PUT_FIXINDENT);
|
||||||
if (was_visual) {
|
if (was_visual) {
|
||||||
@ -7272,10 +7264,8 @@ static void nv_put(cmdarg_T *cap)
|
|||||||
*/
|
*/
|
||||||
was_visual = true;
|
was_visual = true;
|
||||||
regname = cap->oap->regname;
|
regname = cap->oap->regname;
|
||||||
bool adjusted = adjust_clipboard_register(®name);
|
|
||||||
if (regname == 0 || regname == '"'
|
if (regname == 0 || regname == '"'
|
||||||
|| VIM_ISDIGIT(regname) || regname == '-'
|
|| VIM_ISDIGIT(regname) || regname == '-'
|
||||||
|| adjusted
|
|
||||||
) {
|
) {
|
||||||
/* The delete is going to overwrite the register we want to
|
/* The delete is going to overwrite the register we want to
|
||||||
* put, save it first. */
|
* put, save it first. */
|
||||||
|
@ -751,7 +751,7 @@ void get_yank_register(int regname, int writing)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
y_append = FALSE;
|
y_append = FALSE;
|
||||||
if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) {
|
if ((regname == 0 || regname == '"') && !p_unc && !writing && y_previous != NULL) {
|
||||||
y_current = y_previous;
|
y_current = y_previous;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1302,18 +1302,6 @@ cmdline_paste_reg (
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool adjust_clipboard_register(int *rp)
|
|
||||||
{
|
|
||||||
// If no reg. specified and 'unnamedclip' is set, use the
|
|
||||||
// clipboard register.
|
|
||||||
if (*rp == 0 && p_unc && eval_has_provider("clipboard")) {
|
|
||||||
*rp = '+';
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle a delete operation.
|
* Handle a delete operation.
|
||||||
*
|
*
|
||||||
@ -1328,7 +1316,6 @@ int op_delete(oparg_T *oap)
|
|||||||
struct block_def bd;
|
struct block_def bd;
|
||||||
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
|
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
|
||||||
int did_yank = FALSE;
|
int did_yank = FALSE;
|
||||||
int orig_regname = oap->regname;
|
|
||||||
|
|
||||||
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */
|
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */
|
||||||
return OK;
|
return OK;
|
||||||
@ -1342,8 +1329,6 @@ int op_delete(oparg_T *oap)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool adjusted = adjust_clipboard_register(&oap->regname);
|
|
||||||
|
|
||||||
if (has_mbyte)
|
if (has_mbyte)
|
||||||
mb_adjust_opend(oap);
|
mb_adjust_opend(oap);
|
||||||
|
|
||||||
@ -1393,9 +1378,9 @@ int op_delete(oparg_T *oap)
|
|||||||
* register. For the black hole register '_' don't yank anything.
|
* register. For the black hole register '_' don't yank anything.
|
||||||
*/
|
*/
|
||||||
if (oap->regname != '_') {
|
if (oap->regname != '_') {
|
||||||
if (oap->regname != 0) {
|
if (oap->regname != 0 || p_unc) {
|
||||||
/* check for read-only register */
|
/* check for read-only register */
|
||||||
if (!valid_yank_reg(oap->regname, TRUE)) {
|
if (!( valid_yank_reg(oap->regname, TRUE) || (p_unc && oap->regname == 0) )) {
|
||||||
beep_flush();
|
beep_flush();
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -1407,10 +1392,8 @@ int op_delete(oparg_T *oap)
|
|||||||
/*
|
/*
|
||||||
* Put deleted text into register 1 and shift number registers if the
|
* Put deleted text into register 1 and shift number registers if the
|
||||||
* delete contains a line break, or when a regname has been specified.
|
* delete contains a line break, or when a regname has been specified.
|
||||||
* Use the register name from before adjust_clip_reg() may have
|
|
||||||
* changed it.
|
|
||||||
*/
|
*/
|
||||||
if (orig_regname != 0 || oap->motion_type == MLINE
|
if (oap->regname != 0 || oap->motion_type == MLINE
|
||||||
|| oap->line_count > 1 || oap->use_reg_one) {
|
|| oap->line_count > 1 || oap->use_reg_one) {
|
||||||
y_current = &y_regs[9];
|
y_current = &y_regs[9];
|
||||||
free_yank_all(); /* free register nine */
|
free_yank_all(); /* free register nine */
|
||||||
@ -1424,9 +1407,7 @@ int op_delete(oparg_T *oap)
|
|||||||
|
|
||||||
/* Yank into small delete register when no named register specified
|
/* Yank into small delete register when no named register specified
|
||||||
* and the delete is within one line. */
|
* and the delete is within one line. */
|
||||||
if ((
|
if (oap->regname == 0 && oap->motion_type != MLINE
|
||||||
adjusted ||
|
|
||||||
oap->regname == 0) && oap->motion_type != MLINE
|
|
||||||
&& oap->line_count == 1) {
|
&& oap->line_count == 1) {
|
||||||
oap->regname = '-';
|
oap->regname = '-';
|
||||||
get_yank_register(oap->regname, TRUE);
|
get_yank_register(oap->regname, TRUE);
|
||||||
@ -2623,7 +2604,6 @@ do_put (
|
|||||||
int allocated = FALSE;
|
int allocated = FALSE;
|
||||||
long cnt;
|
long cnt;
|
||||||
|
|
||||||
adjust_clipboard_register(®name);
|
|
||||||
get_clipboard(regname);
|
get_clipboard(regname);
|
||||||
|
|
||||||
if (flags & PUT_FIXINDENT)
|
if (flags & PUT_FIXINDENT)
|
||||||
@ -3215,7 +3195,6 @@ void ex_display(exarg_T *eap)
|
|||||||
)
|
)
|
||||||
continue; /* did not ask for this register */
|
continue; /* did not ask for this register */
|
||||||
|
|
||||||
adjust_clipboard_register(&name);
|
|
||||||
get_clipboard(name);
|
get_clipboard(name);
|
||||||
|
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
@ -5225,28 +5204,30 @@ static void free_register(struct yankreg *reg)
|
|||||||
y_current = curr;
|
y_current = curr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_register(struct yankreg *dest, struct yankreg *src)
|
static int check_clipboard_name(int *name) {
|
||||||
{
|
if (*name == '*' || *name == '+') {
|
||||||
free_register(dest);
|
return CLIP_REGISTER;
|
||||||
*dest = *src;
|
} else if (p_unc && *name == NUL && eval_has_provider("clipboard")) {
|
||||||
dest->y_array = xcalloc(src->y_size, sizeof(uint8_t *));
|
*name = '+';
|
||||||
for (int j = 0; j < src->y_size; ++j) {
|
return 0; //unnamed register
|
||||||
dest->y_array[j] = (uint8_t *)xstrdup((char *)src->y_array[j]);
|
} else {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void get_clipboard(int name)
|
static void get_clipboard(int name)
|
||||||
{
|
{
|
||||||
if (!(name == '*' || name == '+'
|
int ireg = check_clipboard_name(&name);
|
||||||
|| (p_unc && !name && eval_has_provider("clipboard")))) {
|
if (ireg < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct yankreg *reg = &y_regs[CLIP_REGISTER];
|
struct yankreg *reg = &y_regs[ireg];
|
||||||
free_register(reg);
|
free_register(reg);
|
||||||
|
|
||||||
list_T *args = list_alloc();
|
list_T *args = list_alloc();
|
||||||
char_u regname = (char_u)name;
|
char_u regname = name;
|
||||||
list_append_string(args, ®name, 1);
|
list_append_string(args, ®name, 1);
|
||||||
|
|
||||||
typval_T result = eval_call_provider("clipboard", "get", args);
|
typval_T result = eval_call_provider("clipboard", "get", args);
|
||||||
@ -5314,11 +5295,6 @@ static void get_clipboard(int name)
|
|||||||
reg->y_width = maxlen-1;
|
reg->y_width = maxlen-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!name && p_unc) {
|
|
||||||
// copy to the unnamed register
|
|
||||||
copy_register(&y_regs[0], reg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
@ -5335,18 +5311,12 @@ err:
|
|||||||
|
|
||||||
static void set_clipboard(int name)
|
static void set_clipboard(int name)
|
||||||
{
|
{
|
||||||
if (!(name == '*' || name == '+'
|
int ireg = check_clipboard_name(&name);
|
||||||
|| (p_unc && !name && eval_has_provider("clipboard")))) {
|
if (ireg < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct yankreg *reg = &y_regs[CLIP_REGISTER];
|
struct yankreg *reg = &y_regs[ireg];
|
||||||
|
|
||||||
if (!name && p_unc) {
|
|
||||||
// copy from the unnamed register
|
|
||||||
copy_register(reg, &y_regs[0]);
|
|
||||||
name = '+';
|
|
||||||
}
|
|
||||||
|
|
||||||
list_T *lines = list_alloc();
|
list_T *lines = list_alloc();
|
||||||
|
|
||||||
@ -5372,7 +5342,7 @@ static void set_clipboard(int name)
|
|||||||
}
|
}
|
||||||
list_append_string(args, ®type, 1);
|
list_append_string(args, ®type, 1);
|
||||||
|
|
||||||
char_u regname = (char_u)name;
|
char_u regname = name;
|
||||||
list_append_string(args, ®name, 1);
|
list_append_string(args, ®name, 1);
|
||||||
|
|
||||||
(void)eval_call_provider("clipboard", "set", args);
|
(void)eval_call_provider("clipboard", "set", args);
|
||||||
|
Loading…
Reference in New Issue
Block a user