Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/tsm/libtsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ void tsm_screen_selection_start(struct tsm_screen *con,
void tsm_screen_selection_target(struct tsm_screen *con,
unsigned int posx,
unsigned int posy);
void tsm_screen_selection_word(struct tsm_screen *con,
unsigned int posx,
unsigned int posy);
int tsm_screen_selection_copy(struct tsm_screen *con, char **out);

tsm_age_t tsm_screen_draw(struct tsm_screen *con, tsm_screen_draw_cb draw_cb,
Expand Down
5 changes: 5 additions & 0 deletions src/tsm/libtsm.sym
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ global:
tsm_screen_sb_get_line_count;
tsm_screen_sb_get_line_pos;
} LIBTSM_4;

LIBTSM_4_3 {
global:
tsm_screen_selection_word;
} LIBTSM_4_1;
53 changes: 53 additions & 0 deletions src/tsm/tsm-selection.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,44 @@ static void selection_set(struct tsm_screen *con, struct selection_pos *sel,
sel->y = y;
}

static void word_select(struct tsm_screen *con,
unsigned int posx,
unsigned int posy)
{
int start, end;
struct line *line;

selection_set(con, &con->sel_start, posx, posy);

if (con->sel_start.line)
line = con->sel_start.line;
else
line = con->lines[con->sel_start.y];

if (!line || line->cells[posx].ch == ' ')
return;

for (start = posx; start >= 0; start--) {
if (line->cells[start].ch == ' ') {
start++;
break;
}
}
if (start < 0)
start = 0;

for (end = posx; end < line->size; end++) {
if (line->cells[end].ch == ' ' || line->cells[end].ch == '\n' ||
line->cells[end].ch == '\0') {
end--;
break;
}
}
con->sel_start.x = start;
selection_set(con, &con->sel_end, end, posy);
con->sel_active = true;
}

SHL_EXPORT
void tsm_screen_selection_reset(struct tsm_screen *con)
{
Expand Down Expand Up @@ -126,6 +164,21 @@ void tsm_screen_selection_target(struct tsm_screen *con,
selection_set(con, &con->sel_end, posx, posy);
}

SHL_EXPORT
void tsm_screen_selection_word(struct tsm_screen *con,
unsigned int posx,
unsigned int posy)
{
if (!con)
return;

screen_inc_age(con);
/* TODO: more sophisticated ageing */
con->age = con->age_cnt;

word_select(con, posx, posy);
}

/* calculates the line length from the beginning to the last non zero character */
static unsigned int calc_line_len(struct line *line)
{
Expand Down
Loading