use the real cursor, instead of the selection hack

This commit is contained in:
Daniel Micay 2012-08-30 04:27:01 -04:00
parent ae2d567052
commit 1e19755049
2 changed files with 101 additions and 46 deletions

View File

@ -1,6 +1,6 @@
diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
--- vte-0.32.2-old/src/vte.c 2012-07-13 21:09:04.003969877 -0400
+++ vte-0.32.2/src/vte.c 2012-08-30 00:53:52.874582449 -0400
+++ vte-0.32.2/src/vte.c 2012-08-30 04:11:30.827265668 -0400
@@ -129,7 +129,6 @@
gpointer data,
GArray *attributes,
@ -51,7 +51,36 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
argv,
flags);
g_free(shell);
@@ -6676,7 +6675,7 @@
@@ -6545,6 +6544,28 @@
}
}
+/**
+ * vte_terminal_set_cursor_position:
+ * @terminal: a #VteTerminal
+ * @column: the new cursor column
+ * @row: the new cursor row
+ *
+ * Set the location of the cursor.
+ */
+void
+vte_terminal_set_cursor_position(VteTerminal *terminal,
+ long column, long row)
+{
+ g_return_if_fail(VTE_IS_TERMINAL(terminal));
+
+ _vte_invalidate_cursor_once(terminal, FALSE);
+ terminal->pvt->screen->cursor_current.col = column;
+ terminal->pvt->screen->cursor_current.row = row;
+ _vte_invalidate_cursor_once(terminal, FALSE);
+ _vte_check_cursor_blink(terminal);
+ vte_terminal_queue_cursor_moved(terminal);
+}
+
static GtkClipboard *
vte_terminal_clipboard_get(VteTerminal *terminal, GdkAtom board)
{
@@ -6676,7 +6697,7 @@
terminal->pvt->selection_start.row);
/* Temporarily stop caring about input from the child. */
@ -60,7 +89,7 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
}
static gboolean
@@ -6693,7 +6692,7 @@
@@ -6693,7 +6714,7 @@
terminal->pvt->selecting = FALSE;
/* Reconnect to input from the child if we paused it. */
@ -69,7 +98,7 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
return TRUE;
}
@@ -8994,7 +8993,7 @@
@@ -8994,7 +9015,7 @@
#endif
kill(terminal->pvt->pty_pid, SIGHUP);
}
@ -78,7 +107,7 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
_vte_terminal_disconnect_pty_write(terminal);
if (terminal->pvt->pty_channel != NULL) {
g_io_channel_unref (terminal->pvt->pty_channel);
@@ -13641,6 +13640,12 @@
@@ -13641,6 +13662,12 @@
g_object_notify(G_OBJECT(terminal), "cursor-blink-mode");
}
@ -91,7 +120,7 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
/**
* vte_terminal_get_cursor_blink_mode:
* @terminal: a #VteTerminal
@@ -14384,7 +14389,7 @@
@@ -14384,7 +14411,7 @@
g_object_freeze_notify(object);
if (pvt->pty != NULL) {
@ -100,7 +129,7 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
_vte_terminal_disconnect_pty_write(terminal);
if (terminal->pvt->pty_channel != NULL) {
@@ -14440,7 +14445,7 @@
@@ -14440,7 +14467,7 @@
_vte_terminal_setup_utf8 (terminal);
/* Open channels to listen for input on. */
@ -109,7 +138,7 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
g_object_notify(object, "pty");
g_object_notify(object, "pty-object");
@@ -14567,6 +14572,51 @@
@@ -14567,6 +14594,50 @@
}
}
@ -156,14 +185,13 @@ diff -aur vte-0.32.2-old/src/vte.c vte-0.32.2/src/vte.c
+ long end_col, long end_row) {
+ _vte_terminal_select_text(terminal, start_col, start_row, end_col, end_row, 0, 0);
+}
+
+
void
_vte_terminal_select_text(VteTerminal *terminal,
long start_col, long start_row,
diff -aur vte-0.32.2-old/src/vte.h vte-0.32.2/src/vte.h
--- vte-0.32.2-old/src/vte.h 2012-07-13 21:09:04.003969877 -0400
+++ vte-0.32.2/src/vte.h 2012-08-30 00:54:19.738281795 -0400
+++ vte-0.32.2/src/vte.h 2012-08-30 04:06:04.192768680 -0400
@@ -296,6 +296,15 @@
/* simple manipulation of selection */
void vte_terminal_select_all(VteTerminal *terminal);
@ -190,7 +218,16 @@ diff -aur vte-0.32.2-old/src/vte.h vte-0.32.2/src/vte.h
/* Set whether or not the cursor blinks. */
void vte_terminal_set_cursor_blink_mode(VteTerminal *terminal,
VteTerminalCursorBlinkMode mode);
@@ -484,6 +496,7 @@
@@ -435,6 +447,8 @@
GArray *attributes);
void vte_terminal_get_cursor_position(VteTerminal *terminal,
glong *column, glong *row);
+void vte_terminal_set_cursor_position(VteTerminal *terminal,
+ long column, long row);
/* Display string matching: clear all matching expressions. */
void vte_terminal_match_clear_all(VteTerminal *terminal);
@@ -484,6 +498,7 @@
VtePty *vte_terminal_get_pty_object(VteTerminal *terminal);
char *vte_get_user_shell (void);

View File

@ -29,8 +29,8 @@ struct select_info {
vi_mode mode;
long begin_col;
long begin_row;
long cursor_col;
long cursor_row;
long cursor_col_save;
long cursor_row_save;
};
struct search_panel_info {
@ -79,12 +79,13 @@ void launch_browser(char *url) {
static void update_selection(VteTerminal *vte, const select_info *select) {
if (select->mode == vi_mode::command) {
// a hack to use the selection as a cursor until a real one is implemented
vte_terminal_select_text(vte, select->cursor_col, select->cursor_row,
select->cursor_col, select->cursor_row);
vte_terminal_select_none(vte);
return; // not in visual mode
}
long cursor_col, cursor_row;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
vte_terminal_select_none(vte);
vte_terminal_set_selection_block_mode(vte, select->mode == vi_mode::visual_block);
@ -92,40 +93,39 @@ static void update_selection(VteTerminal *vte, const select_info *select) {
if (select->mode == vi_mode::visual) {
const long begin = select->begin_row * n_columns + select->begin_col;
const long end = select->cursor_row * n_columns + select->cursor_col;
const long end = cursor_row * n_columns + cursor_col;
if (begin < end) {
vte_terminal_select_text(vte, select->begin_col, select->begin_row,
select->cursor_col, select->cursor_row);
cursor_col, cursor_row);
} else {
vte_terminal_select_text(vte, select->cursor_col, select->cursor_row,
vte_terminal_select_text(vte, cursor_col, cursor_row,
select->begin_col, select->begin_row);
}
} else if (select->mode == vi_mode::visual_line) {
vte_terminal_select_text(vte, 0,
std::min(select->begin_row, select->cursor_row),
std::min(select->begin_row, cursor_row),
n_columns - 1,
std::max(select->begin_row, select->cursor_row));
std::max(select->begin_row, cursor_row));
} else if (select->mode == vi_mode::visual_block) {
vte_terminal_select_text(vte,
std::min(select->begin_col, select->cursor_col),
std::min(select->begin_row, select->cursor_row),
std::max(select->begin_col, select->cursor_col),
std::max(select->begin_row, select->cursor_row));
std::min(select->begin_col, cursor_col),
std::min(select->begin_row, cursor_row),
std::max(select->begin_col, cursor_col),
std::max(select->begin_row, cursor_row));
}
vte_terminal_copy_primary(vte);
}
static void start_selection(VteTerminal *vte, select_info *select) {
vte_terminal_set_cursor_visible(vte, FALSE);
vte_terminal_disconnect_pty_read(vte);
select->mode = vi_mode::command;
vte_terminal_get_cursor_position(vte, &select->cursor_col, &select->cursor_row);
vte_terminal_get_cursor_position(vte, &select->cursor_col_save, &select->cursor_row_save);
update_selection(vte, select);
}
static void end_selection(VteTerminal *vte, select_info *select) {
vte_terminal_set_cursor_visible(vte, TRUE);
vte_terminal_set_cursor_position(vte, select->cursor_col_save, select->cursor_row_save);
vte_terminal_connect_pty_read(vte);
vte_terminal_select_none(vte);
select->mode = vi_mode::insert;
@ -136,8 +136,7 @@ static void toggle_visual(VteTerminal *vte, select_info *select, vi_mode mode) {
select->mode = vi_mode::command;
} else {
if (select->mode == vi_mode::command) {
select->begin_col = select->cursor_col;
select->begin_row = select->cursor_row;
vte_terminal_get_cursor_position(vte, &select->begin_col, &select->begin_row);
}
select->mode = mode;
}
@ -158,27 +157,32 @@ static void update_scroll(VteTerminal *vte, const select_info *select) {
GtkAdjustment *adjust = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(vte));
const double scroll_row = gtk_adjustment_get_value(adjust);
const long n_rows = vte_terminal_get_row_count(vte);
long cursor_col, cursor_row;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
if (select->cursor_row < scroll_row) {
gtk_adjustment_set_value(adjust, (double)select->cursor_row);
} else if (select->cursor_row - n_rows >= (long)scroll_row) {
gtk_adjustment_set_value(adjust, (double)(select->cursor_row - n_rows + 1));
if (cursor_row < scroll_row) {
gtk_adjustment_set_value(adjust, (double)cursor_row);
} else if (cursor_row - n_rows >= (long)scroll_row) {
gtk_adjustment_set_value(adjust, (double)(cursor_row - n_rows + 1));
}
}
static void move(VteTerminal *vte, select_info *select, long col, long row) {
const long end_col = vte_terminal_get_column_count(vte) - 1;
select->cursor_col = CLAMP(select->cursor_col + col, 0, end_col);
select->cursor_row = CLAMP(select->cursor_row + row, first_row(vte), last_row(vte));
long cursor_col, cursor_row;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
vte_terminal_set_cursor_position(vte,
CLAMP(cursor_col + col, 0, end_col),
CLAMP(cursor_row + row, first_row(vte), last_row(vte)));
update_scroll(vte, select);
update_selection(vte, select);
}
static void move_to_row_start(VteTerminal *vte, select_info *select, long row) {
select->cursor_col = 0;
select->cursor_row = row;
vte_terminal_set_cursor_position(vte, 0, row);
update_scroll(vte, select);
update_selection(vte, select);
}
@ -197,8 +201,11 @@ static void open_selection(VteTerminal *vte) {
}
static void move_backward_word(VteTerminal *vte, select_info *select) {
char *content = vte_terminal_get_text_range(vte, select->cursor_row, 0,
select->cursor_row, select->cursor_col,
long cursor_col, cursor_row;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
char *content = vte_terminal_get_text_range(vte, cursor_row, 0,
cursor_row, cursor_col,
NULL, NULL, NULL);
if (!content) {
@ -222,8 +229,9 @@ static void move_backward_word(VteTerminal *vte, select_info *select) {
} else {
in_word = true;
}
select->cursor_col--;
cursor_col--;
}
vte_terminal_set_cursor_position(vte, cursor_col, cursor_row);
update_selection(vte, select);
g_free(codepoints);
@ -231,10 +239,13 @@ static void move_backward_word(VteTerminal *vte, select_info *select) {
}
static void move_forward_word(VteTerminal *vte, select_info *select) {
long cursor_col, cursor_row;
vte_terminal_get_cursor_position(vte, &cursor_col, &cursor_row);
const long end_col = vte_terminal_get_column_count(vte) - 1;
char *content = vte_terminal_get_text_range(vte, select->cursor_row, select->cursor_col,
select->cursor_row, end_col,
char *content = vte_terminal_get_text_range(vte, cursor_row, cursor_col,
cursor_row, end_col,
NULL, NULL, NULL);
if (!content) {
@ -257,14 +268,21 @@ static void move_forward_word(VteTerminal *vte, select_info *select) {
} else {
end_of_word = true;
}
select->cursor_col++;
cursor_col++;
}
vte_terminal_set_cursor_position(vte, cursor_col, cursor_row);
update_selection(vte, select);
g_free(codepoints);
g_free(content);
}
static void set_cursor_column(VteTerminal *vte, long column) {
long cursor_row;
vte_terminal_get_cursor_position(vte, nullptr, &cursor_row);
vte_terminal_set_cursor_position(vte, column, cursor_row);
}
/* {{{ CALLBACKS */
void window_title_cb(VteTerminal *vte, gboolean *dynamic_title) {
const char * const title = *dynamic_title ? vte_terminal_get_window_title(vte) : NULL;
@ -305,11 +323,11 @@ gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, keybind_info *info)
move_forward_word(vte, &info->select);
break;
case GDK_KEY_asciicircum:
info->select.cursor_col = 0;
set_cursor_column(vte, 0);
update_selection(vte, &info->select);
break;
case GDK_KEY_dollar:
info->select.cursor_col = vte_terminal_get_column_count(vte) - 1;
set_cursor_column(vte, vte_terminal_get_column_count(vte) - 1);
update_selection(vte, &info->select);
break;
case GDK_KEY_g: