From 25988dfa3bd77c16eb29bdb8087d286c66c4cd7a Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 16 Dec 2023 14:40:41 +0100 Subject: 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. --- src/local/container.nim | 18 +++++++++++------- 1 file 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 ) -- cgit 1.4.1-2-gfad0