aboutsummaryrefslogtreecommitdiff
path: root/selection.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-30 19:57:48 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-30 19:57:48 +0000
commitb82dc02505ec2836b7d3fa1488d9a26367cdf5a8 (patch)
tree8896d56b16f3612e7eef6d181693a9e0f8f1d644 /selection.c
parentlog: syslog: tag unused function arguments as unused (diff)
selection: add a couple of word-breaking characters
When "auto-selecting" a word, we used to only break on space characters. Now we break on a number of other characters as well.
Diffstat (limited to 'selection.c')
-rw-r--r--selection.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/selection.c b/selection.c
index 468d400a..4c8ab0ca 100644
--- a/selection.c
+++ b/selection.c
@@ -213,6 +213,24 @@ selection_cancel(struct terminal *term)
}
}
+static bool
+isword(int c)
+{
+ switch (c) {
+ default: return !isspace(c);
+
+ case '{': case '}':
+ case '[': case ']':
+ case '(': case ')':
+ case '`':
+ case '\'':
+ case '"':
+ case ',': case '.':
+ case ':': case ';':
+ return false;
+ }
+}
+
void
selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
{
@@ -227,7 +245,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
const struct row *r = grid_row_in_view(term->grid, start.row);
unsigned char c = r->cells[start.col].c[0];
- if (!(c == '\0' || isspace(c))) {
+ if (!(c == '\0' || !isword(c))) {
while (true) {
int next_col = start.col - 1;
int next_row = start.row;
@@ -242,7 +260,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
const struct row *row = grid_row_in_view(term->grid, next_row);
unsigned char c = row->cells[next_col].c[0];
- if (c == '\0' || isspace(c))
+ if (c == '\0' || !isword(c))
break;
start.col = next_col;
@@ -253,7 +271,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
r = grid_row_in_view(term->grid, end.row);
c = r->cells[end.col].c[0];
- if (!(c == '\0' || isspace(c))) {
+ if (!(c == '\0' || !isword(c))) {
while (true) {
int next_col = end.col + 1;
int next_row = end.row;
@@ -268,7 +286,7 @@ selection_mark_word(struct terminal *term, int col, int row, uint32_t serial)
const struct row *row = grid_row_in_view(term->grid, next_row);
unsigned char c = row->cells[next_col].c[0];
- if (c == '\0' || isspace(c))
+ if (c == '\0' || !isword(c))
break;
end.col = next_col;