Skip to content

Instantly share code, notes, and snippets.

@silenvx
Created October 15, 2012 21:00
Show Gist options
  • Save silenvx/3895438 to your computer and use it in GitHub Desktop.
Save silenvx/3895438 to your computer and use it in GitHub Desktop.
tmuxのコピーモードで全角を扱うためのpatch
diff -Narup tmux-1.7.orig/window-copy.c tmux-1.7/window-copy.c
--- tmux-1.7.orig/window-copy.c 2012-10-17 06:43:34.108054101 +0900
+++ tmux-1.7/window-copy.c 2012-10-17 06:55:02.797455680 +0900
@@ -75,6 +75,7 @@ void window_copy_cursor_previous_word(st
void window_copy_scroll_up(struct window_pane *, u_int);
void window_copy_scroll_down(struct window_pane *, u_int);
void window_copy_rectangle_toggle(struct window_pane *);
+u_int window_copy_position_fix_x(struct window_pane *, u_int);
const struct window_mode window_copy_mode = {
window_copy_init,
@@ -1209,7 +1210,7 @@ window_copy_start_selection(struct windo
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen;
- data->selx = data->cx;
+ data->selx = window_copy_position_fix_x(wp, data->cx);
data->sely = screen_hsize(data->backing) + data->cy - data->oy;
s->sel.flag = 1;
@@ -1293,7 +1294,7 @@ window_copy_copy_selection(struct window
*/
/* Find start and end. */
- xx = data->cx;
+ xx = window_copy_position_fix_x(wp, data->cx);
yy = screen_hsize(data->backing) + data->cy - data->oy;
if (yy < data->sely || (yy == data->sely && xx < data->selx)) {
sx = xx; sy = yy;
@@ -1585,7 +1586,7 @@ window_copy_cursor_left(struct window_pa
window_copy_cursor_up(wp, 0);
window_copy_cursor_end_of_line(wp);
} else {
- window_copy_update_cursor(wp, data->cx - 1, data->cy);
+ window_copy_update_cursor(wp, window_copy_position_fix_x(wp, window_copy_position_fix_x(wp, data->cx) - 1), data->cy);
if (window_copy_update_selection(wp))
window_copy_redraw_lines(wp, data->cy, 1);
}
@@ -1595,7 +1596,10 @@ void
window_copy_cursor_right(struct window_pane *wp)
{
struct window_copy_mode_data *data = wp->modedata;
- u_int px, py;
+ struct grid *gd = data->backing->grid;
+ const struct grid_cell *gc;
+ const struct grid_utf8 *gu;
+ u_int px, py, xx;
if (data->screen.sel.flag && data->rectflag)
px = screen_size_x(&data->screen);
@@ -1608,7 +1612,15 @@ window_copy_cursor_right(struct window_p
window_copy_cursor_start_of_line(wp);
window_copy_cursor_down(wp, 0);
} else {
- window_copy_update_cursor(wp, data->cx + 1, data->cy);
+ xx = window_copy_position_fix_x(wp, data->cx);
+ gc = grid_peek_cell(gd, xx, screen_hsize(data->backing) + data->cy - data->oy);
+ if (!(gc->flags & GRID_FLAG_UTF8))
+ xx++;
+ else {
+ gu = grid_peek_utf8(gd, xx, screen_hsize(data->backing) + data->cy - data->oy);
+ xx+=gu->width;
+ }
+ window_copy_update_cursor(wp, xx, data->cy);
if (window_copy_update_selection(wp))
window_copy_redraw_lines(wp, data->cy, 1);
}
@@ -2001,3 +2013,31 @@ window_copy_rectangle_toggle(struct wind
window_copy_update_selection(wp);
window_copy_redraw_screen(wp);
}
+
+u_int
+window_copy_position_fix_x(struct window_pane *wp, u_int xx)
+{
+ struct window_copy_mode_data *data = wp->modedata;
+ struct grid *gd = data->backing->grid;
+ const struct grid_cell *gc, grid_default_cell = { 0, 0, 8, 8, ' ' };
+ const struct grid_utf8 *gu;
+ u_int i, yy;
+
+ yy = screen_hsize(data->backing) + data->cy - data->oy;
+ gc = grid_peek_cell(gd, xx, yy);
+ if (!(gc->flags & GRID_FLAG_UTF8) && memcmp(gc, &grid_default_cell, sizeof gc) != 0){
+ for (i = 1;xx - i >= 0;i++){
+ gc = grid_peek_cell(gd, xx - i, yy);
+ if (gc->flags & GRID_FLAG_UTF8) {
+ gu = grid_peek_utf8(gd, xx - i, yy);
+ if (gu->width > i) {
+ return (xx - i);
+ }
+ } else
+ break;
+ if (memcmp(gc, &grid_default_cell, sizeof gc) != 0)
+ break;
+ }
+ }
+ return xx;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment