1
0
forked from aniani/vim

patch 8.2.0443: clipboard code is spread out

Problem:    Clipboard code is spread out.
Solution:   Move clipboard code to its own file. (Yegappan Lakshmanan,
            closes #5827)
This commit is contained in:
Bram Moolenaar
2020-03-24 21:42:01 +01:00
parent 71658f74ae
commit 45fffdf10b
17 changed files with 2297 additions and 2267 deletions

View File

@@ -29,6 +29,7 @@ SRC_ALL = \
src/channel.c \ src/channel.c \
src/charset.c \ src/charset.c \
src/cindent.c \ src/cindent.c \
src/clipboard.c \
src/cmdexpand.c \ src/cmdexpand.c \
src/cmdhist.c \ src/cmdhist.c \
src/crypt.c \ src/crypt.c \
@@ -200,6 +201,7 @@ SRC_ALL = \
src/proto/channel.pro \ src/proto/channel.pro \
src/proto/charset.pro \ src/proto/charset.pro \
src/proto/cindent.pro \ src/proto/cindent.pro \
src/proto/clipboard.pro \
src/proto/cmdexpand.pro \ src/proto/cmdexpand.pro \
src/proto/cmdhist.pro \ src/proto/cmdhist.pro \
src/proto/crypt.pro \ src/proto/crypt.pro \

View File

@@ -710,6 +710,7 @@ OBJ = \
$(OUTDIR)/change.o \ $(OUTDIR)/change.o \
$(OUTDIR)/charset.o \ $(OUTDIR)/charset.o \
$(OUTDIR)/cindent.o \ $(OUTDIR)/cindent.o \
$(OUTDIR)/clipboard.o \
$(OUTDIR)/cmdexpand.o \ $(OUTDIR)/cmdexpand.o \
$(OUTDIR)/cmdhist.o \ $(OUTDIR)/cmdhist.o \
$(OUTDIR)/crypt.o \ $(OUTDIR)/crypt.o \

View File

@@ -33,6 +33,7 @@ SRC = arabic.c \
change.c \ change.c \
charset.c \ charset.c \
cindent.c \ cindent.c \
clipboard.c \
cmdexpand.c \ cmdexpand.c \
cmdhist.c \ cmdhist.c \
crypt.c \ crypt.c \

View File

@@ -730,6 +730,7 @@ OBJ = \
$(OUTDIR)\change.obj \ $(OUTDIR)\change.obj \
$(OUTDIR)\charset.obj \ $(OUTDIR)\charset.obj \
$(OUTDIR)\cindent.obj \ $(OUTDIR)\cindent.obj \
$(OUTDIR)\clipboard.obj \
$(OUTDIR)\cmdexpand.obj \ $(OUTDIR)\cmdexpand.obj \
$(OUTDIR)\cmdhist.obj \ $(OUTDIR)\cmdhist.obj \
$(OUTDIR)\crypt.obj \ $(OUTDIR)\crypt.obj \
@@ -1515,6 +1516,8 @@ $(OUTDIR)/charset.obj: $(OUTDIR) charset.c $(INCL)
$(OUTDIR)/cindent.obj: $(OUTDIR) cindent.c $(INCL) $(OUTDIR)/cindent.obj: $(OUTDIR) cindent.c $(INCL)
$(OUTDIR)/clipboard.obj: $(OUTDIR) clipboard.c $(INCL)
$(OUTDIR)/cmdexpand.obj: $(OUTDIR) cmdexpand.c $(INCL) $(OUTDIR)/cmdexpand.obj: $(OUTDIR) cmdexpand.c $(INCL)
$(OUTDIR)/cmdhist.obj: $(OUTDIR) cmdhist.c $(INCL) $(OUTDIR)/cmdhist.obj: $(OUTDIR) cmdhist.c $(INCL)
@@ -1862,6 +1865,7 @@ proto.h: \
proto/change.pro \ proto/change.pro \
proto/charset.pro \ proto/charset.pro \
proto/cindent.pro \ proto/cindent.pro \
proto/clipboard.pro \
proto/cmdexpand.pro \ proto/cmdexpand.pro \
proto/cmdhist.pro \ proto/cmdhist.pro \
proto/crypt.pro \ proto/crypt.pro \

View File

@@ -306,6 +306,7 @@ SRC = \
change.c \ change.c \
charset.c \ charset.c \
cindent.c \ cindent.c \
clipboard.c \
cmdexpand.c \ cmdexpand.c \
cmdhist.c \ cmdhist.c \
crypt.c \ crypt.c \
@@ -412,6 +413,7 @@ OBJ = \
change.obj \ change.obj \
charset.obj \ charset.obj \
cindent.obj \ cindent.obj \
clipboard.obj \
cmdexpand.obj \ cmdexpand.obj \
cmdhist.obj \ cmdhist.obj \
crypt.obj \ crypt.obj \
@@ -700,6 +702,10 @@ cindent.obj : cindent.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h globals.h
clipboard.obj : clipboard.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h
cmdexpand.obj : cmdexpand.c vim.h [.auto]config.h feature.h os_unix.h \ cmdexpand.obj : cmdexpand.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \

View File

@@ -1599,6 +1599,7 @@ BASIC_SRC = \
change.c \ change.c \
charset.c \ charset.c \
cindent.c \ cindent.c \
clipboard.c \
cmdexpand.c \ cmdexpand.c \
cmdhist.c \ cmdhist.c \
crypt.c \ crypt.c \
@@ -1743,6 +1744,7 @@ OBJ_COMMON = \
objects/blob.o \ objects/blob.o \
objects/blowfish.o \ objects/blowfish.o \
objects/cindent.o \ objects/cindent.o \
objects/clipboard.o \
objects/cmdexpand.o \ objects/cmdexpand.o \
objects/cmdhist.o \ objects/cmdhist.o \
objects/crypt.o \ objects/crypt.o \
@@ -1903,6 +1905,7 @@ PRO_AUTO = \
channel.pro \ channel.pro \
charset.pro \ charset.pro \
cindent.pro \ cindent.pro \
clipboard.pro \
cmdexpand.pro \ cmdexpand.pro \
cmdhist.pro \ cmdhist.pro \
crypt.pro \ crypt.pro \
@@ -3117,6 +3120,9 @@ objects/charset.o: charset.c
objects/cindent.o: cindent.c objects/cindent.o: cindent.c
$(CCC) -o $@ cindent.c $(CCC) -o $@ cindent.c
objects/clipboard.o: clipboard.c
$(CCC) -o $@ clipboard.c
objects/cmdexpand.o: cmdexpand.c objects/cmdexpand.o: cmdexpand.c
$(CCC) -o $@ cmdexpand.c $(CCC) -o $@ cmdexpand.c
@@ -3734,6 +3740,10 @@ objects/cindent.o: cindent.c vim.h protodef.h auto/config.h feature.h os_unix.h
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h proto.h globals.h
objects/clipboard.o: clipboard.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h
objects/cmdexpand.o: cmdexpand.c vim.h protodef.h auto/config.h feature.h \ objects/cmdexpand.o: cmdexpand.c vim.h protodef.h auto/config.h feature.h \
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \

View File

@@ -30,6 +30,7 @@ buffer.c | manipulating buffers (loaded files)
bufwrite.c | writing a buffer to file bufwrite.c | writing a buffer to file
change.c | handling changes to text change.c | handling changes to text
cindent.c | C and Lisp indentation cindent.c | C and Lisp indentation
clipboard.c | handling the clipboard
cmdexpand.c | command-line completion cmdexpand.c | command-line completion
cmdhist.c | command-line history cmdhist.c | command-line history
debugger.c | vim script debugger debugger.c | vim script debugger

2212
src/clipboard.c Normal file

File diff suppressed because it is too large Load Diff

107
src/ops.c
View File

@@ -3409,113 +3409,6 @@ theend:
return did_change; return did_change;
} }
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
/*
* SELECTION / PRIMARY ('*')
*
* Text selection stuff that uses the GUI selection register '*'. When using a
* GUI this may be text from another window, otherwise it is the last text we
* had highlighted with VIsual mode. With mouse support, clicking the middle
* button performs the paste, otherwise you will need to do <"*p>. "
* If not under X, it is synonymous with the clipboard register '+'.
*
* X CLIPBOARD ('+')
*
* Text selection stuff that uses the GUI clipboard register '+'.
* Under X, this matches the standard cut/paste buffer CLIPBOARD selection.
* It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed",
* otherwise you will need to do <"+p>. "
* If not under X, it is synonymous with the selection register '*'.
*/
/*
* Routine to export any final X selection we had to the environment
* so that the text is still available after Vim has exited. X selections
* only exist while the owning application exists, so we write to the
* permanent (while X runs) store CUT_BUFFER0.
* Dump the CLIPBOARD selection if we own it (it's logically the more
* 'permanent' of the two), otherwise the PRIMARY one.
* For now, use a hard-coded sanity limit of 1Mb of data.
*/
#if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
void
x11_export_final_selection(void)
{
Display *dpy;
char_u *str = NULL;
long_u len = 0;
int motion_type = -1;
# ifdef FEAT_GUI
if (gui.in_use)
dpy = X_DISPLAY;
else
# endif
# ifdef FEAT_XCLIPBOARD
dpy = xterm_dpy;
# else
return;
# endif
// Get selection to export
if (clip_plus.owned)
motion_type = clip_convert_selection(&str, &len, &clip_plus);
else if (clip_star.owned)
motion_type = clip_convert_selection(&str, &len, &clip_star);
// Check it's OK
if (dpy != NULL && str != NULL && motion_type >= 0
&& len < 1024*1024 && len > 0)
{
int ok = TRUE;
// The CUT_BUFFER0 is supposed to always contain latin1. Convert from
// 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit
// encoding conversion usually doesn't work, so keep the text as-is.
if (has_mbyte)
{
vimconv_T vc;
vc.vc_type = CONV_NONE;
if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
{
int intlen = len;
char_u *conv_str;
vc.vc_fail = TRUE;
conv_str = string_convert(&vc, str, &intlen);
len = intlen;
if (conv_str != NULL)
{
vim_free(str);
str = conv_str;
}
else
{
ok = FALSE;
}
convert_setup(&vc, NULL, NULL);
}
else
{
ok = FALSE;
}
}
// Do not store the string if conversion failed. Better to use any
// other selection than garbled text.
if (ok)
{
XStoreBuffer(dpy, (char *)str, (int)len, 0);
XFlush(dpy);
}
}
vim_free(str);
}
#endif
#endif // FEAT_CLIPBOARD || PROTO
void void
clear_oparg(oparg_T *oap) clear_oparg(oparg_T *oap)
{ {

View File

@@ -68,6 +68,7 @@ extern int _stricoll(char *a, char *b);
# include "change.pro" # include "change.pro"
# include "charset.pro" # include "charset.pro"
# include "cindent.pro" # include "cindent.pro"
# include "clipboard.pro"
# include "cmdexpand.pro" # include "cmdexpand.pro"
# include "cmdhist.pro" # include "cmdhist.pro"
# include "if_cscope.pro" # include "if_cscope.pro"

38
src/proto/clipboard.pro Normal file
View File

@@ -0,0 +1,38 @@
/* clipboard.c */
void clip_init(int can_use);
void clip_update_selection(Clipboard_T *clip);
void clip_own_selection(Clipboard_T *cbd);
void clip_lose_selection(Clipboard_T *cbd);
void start_global_changes(void);
void end_global_changes(void);
void clip_auto_select(void);
int clip_isautosel_star(void);
int clip_isautosel_plus(void);
void clip_modeless(int button, int is_click, int is_drag);
void clip_start_selection(int col, int row, int repeated_click);
void clip_process_selection(int button, int col, int row, int_u repeated_click);
void clip_may_redraw_selection(int row, int col, int len);
void clip_clear_selection(Clipboard_T *cbd);
void clip_may_clear_selection(int row1, int row2);
void clip_scroll_selection(int rows);
void clip_copy_modeless_selection(int both);
void clip_gen_set_selection(Clipboard_T *cbd);
int clip_gen_owner_exists(Clipboard_T *cbd);
char *check_clipboard_option(void);
void open_app_context(void);
void x11_setup_atoms(Display *dpy);
void x11_setup_selection(Widget w);
void clip_x11_request_selection(Widget myShell, Display *dpy, Clipboard_T *cbd);
void clip_x11_lose_selection(Widget myShell, Clipboard_T *cbd);
int clip_x11_own_selection(Widget myShell, Clipboard_T *cbd);
void clip_x11_set_selection(Clipboard_T *cbd);
void yank_cut_buffer0(Display *dpy, Clipboard_T *cbd);
void x11_export_final_selection(void);
void clip_free_selection(Clipboard_T *cbd);
void clip_get_selection(Clipboard_T *cbd);
void clip_yank_selection(int type, char_u *str, long len, Clipboard_T *cbd);
int clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd);
int may_get_selection(int regname);
void may_set_selection(void);
void adjust_clip_reg(int *rp);
/* vim: set ft=c : */

View File

@@ -19,7 +19,6 @@ void format_lines(linenr_T line_count, int avoid_fex);
int paragraph_start(linenr_T lnum); int paragraph_start(linenr_T lnum);
void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int is_del); void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, int is_del);
void op_addsub(oparg_T *oap, linenr_T Prenum1, int g_cmd); void op_addsub(oparg_T *oap, linenr_T Prenum1, int g_cmd);
void x11_export_final_selection(void);
void clear_oparg(oparg_T *oap); void clear_oparg(oparg_T *oap);
void cursor_pos_info(dict_T *dict); void cursor_pos_info(dict_T *dict);
void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank); void do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank);

View File

@@ -1,14 +1,15 @@
/* register.c */ /* register.c */
yankreg_T *get_y_regs(void); yankreg_T *get_y_regs(void);
yankreg_T *get_y_register(int reg);
yankreg_T *get_y_current(void); yankreg_T *get_y_current(void);
yankreg_T *get_y_previous(void); yankreg_T *get_y_previous(void);
void set_y_current(yankreg_T *yreg);
void set_y_previous(yankreg_T *yreg); void set_y_previous(yankreg_T *yreg);
int get_expr_register(void); int get_expr_register(void);
void set_expr_line(char_u *new_line); void set_expr_line(char_u *new_line);
char_u *get_expr_line(void); char_u *get_expr_line(void);
int valid_yank_reg(int regname, int writing); int valid_yank_reg(int regname, int writing);
int get_yank_register(int regname, int writing); int get_yank_register(int regname, int writing);
int may_get_selection(int regname);
void *get_register(int name, int copy); void *get_register(int name, int copy);
void put_register(int name, void *reg); void put_register(int name, void *reg);
void free_register(void *reg); void free_register(void *reg);
@@ -20,23 +21,20 @@ int do_execreg(int regname, int colon, int addcr, int silent);
int insert_reg(int regname, int literally_arg); int insert_reg(int regname, int literally_arg);
int get_spec_reg(int regname, char_u **argp, int *allocated, int errmsg); int get_spec_reg(int regname, char_u **argp, int *allocated, int errmsg);
int cmdline_paste_reg(int regname, int literally_arg, int remcr); int cmdline_paste_reg(int regname, int literally_arg, int remcr);
void adjust_clip_reg(int *rp);
void shift_delete_registers(void); void shift_delete_registers(void);
void yank_do_autocmd(oparg_T *oap, yankreg_T *reg); void yank_do_autocmd(oparg_T *oap, yankreg_T *reg);
void init_yank(void); void init_yank(void);
void clear_registers(void); void clear_registers(void);
void free_yank_all(void);
int op_yank(oparg_T *oap, int deleting, int mess); int op_yank(oparg_T *oap, int deleting, int mess);
void do_put(int regname, int dir, long count, int flags); void do_put(int regname, int dir, long count, int flags);
int get_register_name(int num); int get_register_name(int num);
void ex_display(exarg_T *eap); void ex_display(exarg_T *eap);
void clip_free_selection(Clipboard_T *cbd);
void clip_get_selection(Clipboard_T *cbd);
void clip_yank_selection(int type, char_u *str, long len, Clipboard_T *cbd);
int clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd);
void dnd_yank_drag_data(char_u *str, long len); void dnd_yank_drag_data(char_u *str, long len);
char_u get_reg_type(int regname, long *reglen); char_u get_reg_type(int regname, long *reglen);
char_u *get_reg_contents(int regname, int flags); char_u *get_reg_contents(int regname, int flags);
void write_reg_contents(int name, char_u *str, int maxlen, int must_append); void write_reg_contents(int name, char_u *str, int maxlen, int must_append);
void write_reg_contents_lst(int name, char_u **strings, int maxlen, int must_append, int yank_type, long block_len); void write_reg_contents_lst(int name, char_u **strings, int maxlen, int must_append, int yank_type, long block_len);
void write_reg_contents_ex(int name, char_u *str, int maxlen, int must_append, int yank_type, long block_len); void write_reg_contents_ex(int name, char_u *str, int maxlen, int must_append, int yank_type, long block_len);
void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -14,28 +14,6 @@ void ui_new_shellsize(void);
int ui_get_winpos(int *x, int *y, varnumber_T timeout); int ui_get_winpos(int *x, int *y, varnumber_T timeout);
void ui_breakcheck(void); void ui_breakcheck(void);
void ui_breakcheck_force(int force); void ui_breakcheck_force(int force);
void clip_init(int can_use);
void clip_update_selection(Clipboard_T *clip);
void clip_own_selection(Clipboard_T *cbd);
void clip_lose_selection(Clipboard_T *cbd);
void start_global_changes(void);
int is_clipboard_needs_update(void);
void end_global_changes(void);
void clip_auto_select(void);
int clip_isautosel_star(void);
int clip_isautosel_plus(void);
void clip_modeless(int button, int is_click, int is_drag);
void clip_start_selection(int col, int row, int repeated_click);
void clip_process_selection(int button, int col, int row, int_u repeated_click);
void clip_may_redraw_selection(int row, int col, int len);
void clip_clear_selection(Clipboard_T *cbd);
void clip_may_clear_selection(int row1, int row2);
void clip_scroll_selection(int rows);
void clip_copy_modeless_selection(int both);
void clip_gen_set_selection(Clipboard_T *cbd);
void clip_gen_request_selection(Clipboard_T *cbd);
int clip_gen_owner_exists(Clipboard_T *cbd);
char *check_clipboard_option(void);
int vim_is_input_buf_full(void); int vim_is_input_buf_full(void);
int vim_is_input_buf_empty(void); int vim_is_input_buf_empty(void);
int vim_free_in_input_buf(void); int vim_free_in_input_buf(void);
@@ -52,14 +30,6 @@ void ui_cursor_shape_forced(int forced);
void ui_cursor_shape(void); void ui_cursor_shape(void);
int check_col(int col); int check_col(int col);
int check_row(int row); int check_row(int row);
void open_app_context(void);
void x11_setup_atoms(Display *dpy);
void x11_setup_selection(Widget w);
void clip_x11_request_selection(Widget myShell, Display *dpy, Clipboard_T *cbd);
void clip_x11_lose_selection(Widget myShell, Clipboard_T *cbd);
int clip_x11_own_selection(Widget myShell, Clipboard_T *cbd);
void clip_x11_set_selection(Clipboard_T *cbd);
void yank_cut_buffer0(Display *dpy, Clipboard_T *cbd);
void ui_focus_change(int in_focus); void ui_focus_change(int in_focus);
void im_save_status(long *psave); void im_save_status(long *psave);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -32,16 +32,11 @@ static int stuff_yank(int, char_u *);
static void put_reedit_in_typebuf(int silent); static void put_reedit_in_typebuf(int silent);
static int put_in_typebuf(char_u *s, int esc, int colon, static int put_in_typebuf(char_u *s, int esc, int colon,
int silent); int silent);
static void free_yank_all(void);
static int yank_copy_line(struct block_def *bd, long y_idx); static int yank_copy_line(struct block_def *bd, long y_idx);
#ifdef FEAT_CLIPBOARD #ifdef FEAT_CLIPBOARD
static void copy_yank_reg(yankreg_T *reg); static void copy_yank_reg(yankreg_T *reg);
static void may_set_selection(void);
#endif #endif
static void dis_msg(char_u *p, int skip_esc); static void dis_msg(char_u *p, int skip_esc);
#if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL)
static void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list);
#endif
yankreg_T * yankreg_T *
get_y_regs(void) get_y_regs(void)
@@ -49,6 +44,12 @@ get_y_regs(void)
return y_regs; return y_regs;
} }
yankreg_T *
get_y_register(int reg)
{
return &y_regs[reg];
}
yankreg_T * yankreg_T *
get_y_current(void) get_y_current(void)
{ {
@@ -61,6 +62,12 @@ get_y_previous(void)
return y_previous; return y_previous;
} }
void
set_y_current(yankreg_T *yreg)
{
y_current = yreg;
}
void void
set_y_previous(yankreg_T *yreg) set_y_previous(yankreg_T *yreg)
{ {
@@ -241,32 +248,6 @@ get_yank_register(int regname, int writing)
return ret; return ret;
} }
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
/*
* When "regname" is a clipboard register, obtain the selection. If it's not
* available return zero, otherwise return "regname".
*/
int
may_get_selection(int regname)
{
if (regname == '*')
{
if (!clip_star.available)
regname = 0;
else
clip_get_selection(&clip_star);
}
else if (regname == '+')
{
if (!clip_plus.available)
regname = 0;
else
clip_get_selection(&clip_plus);
}
return regname;
}
#endif
/* /*
* Obtain the contents of a "normal" register. The register is made empty. * Obtain the contents of a "normal" register. The register is made empty.
* The returned pointer has allocated memory, use put_register() later. * The returned pointer has allocated memory, use put_register() later.
@@ -883,32 +864,6 @@ cmdline_paste_reg(
return OK; return OK;
} }
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
/*
* Adjust the register name pointed to with "rp" for the clipboard being
* used always and the clipboard being available.
*/
void
adjust_clip_reg(int *rp)
{
// If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard',
// use '*' or '+' reg, respectively. "unnamedplus" prevails.
if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0))
{
if (clip_unnamed != 0)
*rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available)
? '+' : '*';
else
*rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS)
&& clip_plus.available) ? '+' : '*';
}
if (!clip_star.available && *rp == '*')
*rp = 0;
if (!clip_plus.available && *rp == '+')
*rp = 0;
}
#endif
/* /*
* Shift the delete registers: "9 is cleared, "8 becomes "9, etc. * Shift the delete registers: "9 is cleared, "8 becomes "9, etc.
*/ */
@@ -1050,7 +1005,7 @@ free_yank(long n)
} }
} }
static void void
free_yank_all(void) free_yank_all(void)
{ {
free_yank(y_current->y_size); free_yank(y_current->y_size);
@@ -2348,186 +2303,6 @@ dis_msg(
ui_breakcheck(); ui_breakcheck();
} }
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
void
clip_free_selection(Clipboard_T *cbd)
{
yankreg_T *y_ptr = y_current;
if (cbd == &clip_plus)
y_current = &y_regs[PLUS_REGISTER];
else
y_current = &y_regs[STAR_REGISTER];
free_yank_all();
y_current->y_size = 0;
y_current = y_ptr;
}
/*
* Get the selected text and put it in register '*' or '+'.
*/
void
clip_get_selection(Clipboard_T *cbd)
{
yankreg_T *old_y_previous, *old_y_current;
pos_T old_cursor;
pos_T old_visual;
int old_visual_mode;
colnr_T old_curswant;
int old_set_curswant;
pos_T old_op_start, old_op_end;
oparg_T oa;
cmdarg_T ca;
if (cbd->owned)
{
if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL)
|| (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL))
return;
// Get the text between clip_star.start & clip_star.end
old_y_previous = y_previous;
old_y_current = y_current;
old_cursor = curwin->w_cursor;
old_curswant = curwin->w_curswant;
old_set_curswant = curwin->w_set_curswant;
old_op_start = curbuf->b_op_start;
old_op_end = curbuf->b_op_end;
old_visual = VIsual;
old_visual_mode = VIsual_mode;
clear_oparg(&oa);
oa.regname = (cbd == &clip_plus ? '+' : '*');
oa.op_type = OP_YANK;
vim_memset(&ca, 0, sizeof(ca));
ca.oap = &oa;
ca.cmdchar = 'y';
ca.count1 = 1;
ca.retval = CA_NO_ADJ_OP_END;
do_pending_operator(&ca, 0, TRUE);
y_previous = old_y_previous;
y_current = old_y_current;
curwin->w_cursor = old_cursor;
changed_cline_bef_curs(); // need to update w_virtcol et al
curwin->w_curswant = old_curswant;
curwin->w_set_curswant = old_set_curswant;
curbuf->b_op_start = old_op_start;
curbuf->b_op_end = old_op_end;
VIsual = old_visual;
VIsual_mode = old_visual_mode;
}
else if (!is_clipboard_needs_update())
{
clip_free_selection(cbd);
// Try to get selected text from another window
clip_gen_request_selection(cbd);
}
}
/*
* Convert from the GUI selection string into the '*'/'+' register.
*/
void
clip_yank_selection(
int type,
char_u *str,
long len,
Clipboard_T *cbd)
{
yankreg_T *y_ptr;
if (cbd == &clip_plus)
y_ptr = &y_regs[PLUS_REGISTER];
else
y_ptr = &y_regs[STAR_REGISTER];
clip_free_selection(cbd);
str_to_reg(y_ptr, type, str, len, 0L, FALSE);
}
/*
* Convert the '*'/'+' register into a GUI selection string returned in *str
* with length *len.
* Returns the motion type, or -1 for failure.
*/
int
clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd)
{
char_u *p;
int lnum;
int i, j;
int_u eolsize;
yankreg_T *y_ptr;
if (cbd == &clip_plus)
y_ptr = &y_regs[PLUS_REGISTER];
else
y_ptr = &y_regs[STAR_REGISTER];
# ifdef USE_CRNL
eolsize = 2;
# else
eolsize = 1;
# endif
*str = NULL;
*len = 0;
if (y_ptr->y_array == NULL)
return -1;
for (i = 0; i < y_ptr->y_size; i++)
*len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize;
// Don't want newline character at end of last line if we're in MCHAR mode.
if (y_ptr->y_type == MCHAR && *len >= eolsize)
*len -= eolsize;
p = *str = alloc(*len + 1); // add one to avoid zero
if (p == NULL)
return -1;
lnum = 0;
for (i = 0, j = 0; i < (int)*len; i++, j++)
{
if (y_ptr->y_array[lnum][j] == '\n')
p[i] = NUL;
else if (y_ptr->y_array[lnum][j] == NUL)
{
# ifdef USE_CRNL
p[i++] = '\r';
# endif
p[i] = '\n';
lnum++;
j = -1;
}
else
p[i] = y_ptr->y_array[lnum][j];
}
return y_ptr->y_type;
}
/*
* If we have written to a clipboard register, send the text to the clipboard.
*/
static void
may_set_selection(void)
{
if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available)
{
clip_own_selection(&clip_star);
clip_gen_set_selection(&clip_star);
}
else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available)
{
clip_own_selection(&clip_plus);
clip_gen_set_selection(&clip_plus);
}
}
#endif // FEAT_CLIPBOARD || PROTO
#if defined(FEAT_DND) || defined(PROTO) #if defined(FEAT_DND) || defined(PROTO)
/* /*
* Replace the contents of the '~' register with str. * Replace the contents of the '~' register with str.
@@ -2900,7 +2675,7 @@ write_reg_contents_ex(
* Put a string into a register. When the register is not empty, the string * Put a string into a register. When the register is not empty, the string
* is appended. * is appended.
*/ */
static void void
str_to_reg( str_to_reg(
yankreg_T *y_ptr, // pointer to yank register yankreg_T *y_ptr, // pointer to yank register
int yank_type, // MCHAR, MLINE, MBLOCK, MAUTO int yank_type, // MCHAR, MLINE, MBLOCK, MAUTO

1885
src/ui.c

File diff suppressed because it is too large Load Diff

View File

@@ -738,6 +738,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
443,
/**/ /**/
442, 442,
/**/ /**/