From 6d67fd47ef83745f623b74b5a681cd85ace154b2 Mon Sep 17 00:00:00 2001 From: picobyte Date: Tue, 14 Nov 2017 22:31:36 +0100 Subject: [PATCH] Position cursor correctly after paste. Insert, rewrap and move cursor along the inserted entries to get to the end. Line wraps have to be taken into account. Signed-off-by: picobyte --- game/edit_button.rpy | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/game/edit_button.rpy b/game/edit_button.rpy index dc43ca5..a435982 100644 --- a/game/edit_button.rpy +++ b/game/edit_button.rpy @@ -348,10 +348,25 @@ init -1500 python in _editor: ey += 1 self.data.insert(ey, l) self.data[ey] += end + self.parse() + # Move cursor to end of insertion. This is tricky. + i = 0 + cx += len(entries[-1]) + while cy + 1 != self.nolines: + bx, by = self.wrap2buf[cy+1] + if i == len(entries) - 1 and (bx == 0 or bx >= len(entries[i])): + if i == 0: + cx -= self.wrap2buf[cy][0] + elif cx == 0: + cx = len(entries[i]) - self.wrap2buf[cy][0] + break + cy += 1 + if self.wrap2buf[cy][0] == 0: + i += 1 + cx = 0 self.console.cy = self.console.CY = cy self.console.max = self.console.cx = self.console.CX = cx renpy.redraw(self.console, 0) - self.parse() def handlekey(self, keystr): """ repeat keys are handled as normal keys; unless shift is provided selection is discarded and cursor is redrawn """