diff options
author | bptato <nincsnevem662@gmail.com> | 2023-12-16 14:40:41 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-16 14:40:41 +0100 |
commit | 25988dfa3bd77c16eb29bdb8087d286c66c4cd7a (patch) | |
tree | a63823f3bce3b19366447d47912cde0009f46807 /src | |
parent | 089d974b245734042b0a01a28b1cca74de765b3b (diff) | |
download | chawan-25988dfa3bd77c16eb29bdb8087d286c66c4cd7a.tar.gz |
container: fix multi-byte selections, do not append newline
We need to select (first byte of first char)..(last byte of last char). Also, in line/block mode we no longer add the final newline to selections.
Diffstat (limited to 'src')
-rw-r--r-- | src/local/container.nim | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index c2edcf43..74011a53 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -1116,23 +1116,27 @@ proc getSelectionText(container: Container, hl: Highlight = nil): of SEL_NORMAL: if starty == endy: let si = res.lines[0].str.findColBytes(startx) - let ei = res.lines[0].str.findColBytes(endx, startx, si) + let ei = res.lines[0].str.findColBytes(endx + 1, startx, si) - 1 s = res.lines[0].str.substr(si, ei) else: let si = res.lines[0].str.findColBytes(startx) s &= res.lines[0].str.substr(si) & '\n' for i in 1 .. res.lines.high - 1: s &= res.lines[i].str & '\n' - let ei = res.lines[^1].str.findColBytes(endx) + let ei = res.lines[^1].str.findColBytes(endx + 1) - 1 s &= res.lines[^1].str.substr(0, ei) of SEL_BLOCK: - for line in res.lines: + for i, line in res.lines: let si = line.str.findColBytes(startx) - let ei = line.str.findColBytes(endx, startx, si) - s &= line.str.substr(si, ei) & '\n' + let ei = line.str.findColBytes(endx + 1, startx, si) - 1 + if i > 0: + s &= '\n' + s &= line.str.substr(si, ei) of SEL_LINE: - for line in res.lines: - s &= line.str & '\n' + for i, line in res.lines: + if i > 0: + s &= '\n' + s &= line.str return s ) |