Skip to content

Commit

Permalink
optionally include trailing space with selection (~#800, ~~#768)
Browse files Browse the repository at this point in the history
  • Loading branch information
mintty committed Oct 3, 2018
1 parent defbb38 commit e8be9bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/mintty.1
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,12 @@ options, which means they can only be set in config files or using the
\fBClear selection highlighting on input\fP (ClearSelectionOnInput=true)
When this is disabled, keyboard input or pasting does not clear selection highlighting.

.TP
\fBTrim trailing space from selection on copy\fP (TrimSelection=true)
When this is disabled, trailing space that was written to the terminal
in a line is included in the selection buffer.
(Corresponds to the xterm resource \fBtrimSelection\fP.)

.TP
\fBSelection size indication\fP (SelectionShowSize=0)
The current selection size can optionally been indicated with a popup,
Expand Down
9 changes: 7 additions & 2 deletions src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const cattr CATTR_DEFAULT =
termchar basic_erase_char =
{.cc_next = 0, .chr = ' ',
/* CATTR_DEFAULT */
.attr = {.attr = ATTR_DEFAULT,
.attr = {.attr = ATTR_DEFAULT | TATTR_CLEAR,
.truefg = 0, .truebg = 0, .ulcolr = (colour)-1}
};

Expand Down Expand Up @@ -1217,8 +1217,13 @@ term_erase(bool selective, bool line_only, bool from_begin, bool to_end)
else
line->lattr = LATTR_NORM;
}
else if (!selective || !(line->chars[start.x].attr.attr & ATTR_PROTECTED))
else if (!selective ||
!(line->chars[start.x].attr.attr & ATTR_PROTECTED)
)
{
line->chars[start.x] = term.erase_char;
line->chars[start.x].attr.attr |= TATTR_CLEAR;
}
if (inclpos(start, cols) && start.y < term.rows)
line = term.lines[start.y];
}
Expand Down
2 changes: 1 addition & 1 deletion src/term.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ enum {
TATTR_CURMARKED = 0x0800000000000000u, /* current scroll marker */

TATTR_SELECTED = 0x2000000000000000u, /* highlighted */
TATTR_CLEAR = 0x4000000000000000u, /* erased / unwritten */

DATTR_STARTRUN = 0x8000000000000000u, /* start of redraw run */
DATTR_MASK = TATTR_RIGHTCURS | TATTR_PASCURS | TATTR_ACTCURS
| DATTR_STARTRUN
// unassigned bits:
// 0x0040000000000000u
// 0x0080000000000000u
// 0x4000000000000000u
};

/* Line attributes.
Expand Down
4 changes: 4 additions & 0 deletions src/termclip.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ get_selection(pos start, pos end, bool rect, bool allinline)
else if (!(line->lattr & LATTR_WRAPPED)) {
//printf("pos %d\n", nlpos.x);
while (nlpos.x && line->chars[nlpos.x - 1].chr == ' ' &&
(cfg.trim_selection ||
(line->chars[nlpos.x - 1].attr.attr & TATTR_CLEAR)) &&
!line->chars[nlpos.x - 1].cc_next && poslt(start, nlpos))
decpos(nlpos);
if (poslt(nlpos, end))
Expand All @@ -91,6 +93,8 @@ get_selection(pos start, pos end, bool rect, bool allinline)
//printf("wr x %d w %d\n", nlpos.x, line->wrappos);
while (nlpos.x > line->wrappos + !(line->lattr & LATTR_WRAPPED2) &&
line->chars[nlpos.x - 1].chr == ' ' &&
(cfg.trim_selection ||
(line->chars[nlpos.x - 1].attr.attr & TATTR_CLEAR)) &&
!line->chars[nlpos.x - 1].cc_next && poslt(start, nlpos))
decpos(nlpos);
//printf("-> x %d w %d\n", nlpos.x, line->wrappos);
Expand Down

0 comments on commit e8be9bd

Please sign in to comment.