Hi, While working on st I found three bugs(?) related with selection.
1. Logic for selclear in tputc() is incorrect. It looks whether cursor is between ob.y and oe.y which works if we select text up to bottom, but doesn't work if we select text bottom up. It should use normalized (nb.y, ne.y) coordinates instead of the original ones. Or even better simply use selected() funcion. 2. IMO getsel() incorrectly adds (or actually doesn't add) newline characters when selection type is SEL_RECTANGULAR. IMO if we select text in rectangular mode we should ignore ATTR_WRAP. For example combining lines when we select just right half of the lines doesn't make sense. VTE based terminals (gnome-terminal, termite) work the way I would expect - they do not combine lines in rectangular mode selection. 3. selscroll() logic is weird and incorrect. 3.1. selscroll() should be symmetrical: whether you select text up to bottom or bottom up it should behave the same way. Currently this is not the case, when selection moves outside <term.top, term.bot> range in one case it calls selclear(), in other case it moves ob.y or oe.y. 3.2. If ob.y or oe.y is outside <orig, term.bot> range then it means it should not move. Currently the logic is that whenever just one of those is inside the range both ob and oe move. IMO this is incorrect. There are three cases: 3.2.1. Both ob, oe are outside of <orig, term.bot> range - do not move selection - correctly handled now 3.2.2. Both ob, oe are inside range - move both, check whether they stay inside <term.top, term.bot> range afterwards, and if not then selclear(). Curent code moves both ob,oe correctly but incorrectly handles after move check (look 3.1). 3.2.3. Only one of ob, oe is inside range - selection would move just partially and change so code should call selclear() - this is incorrectly handled (look 3.1). 3.3. selscroll() should not check whether ob, oe are inside <orig, term.bot> range, it should check whether nb, ne are inside the range because of the selection snapping. Br, Jakub Leszczak
