From ca866a5e14135a7ee731552d280c3e8db86545fa Mon Sep 17 00:00:00 2001 From: picobyte Date: Wed, 15 Nov 2017 21:39:37 +0100 Subject: [PATCH] add word selection on double mouse click Signed-off-by: picobyte --- game/edit_button.rpy | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/game/edit_button.rpy b/game/edit_button.rpy index 938c115..ba15386 100644 --- a/game/edit_button.rpy +++ b/game/edit_button.rpy @@ -12,6 +12,7 @@ init -1500 python in _editor: import re import codecs import textwrap + import time import math @@ -404,6 +405,7 @@ init -1500 python in _editor: self.fl = {} self.fname = None self.view = None + self.timer = time.time() self.is_mouse_pressed = False self.exit() # sets is_visible and cursor coords to default @@ -450,7 +452,17 @@ init -1500 python in _editor: import pygame if ev.type == pygame.MOUSEBUTTONDOWN: self.cx, self.cy = self._screen_to_cursor_coordinates(x, y) - self.CX, self.CY = self.cx, self.cy + if time.time() - self.timer < 0.5: + bx, by = self.view.wrap2buf[self.cy] + m = re.compile(r'\w*$').search(self.view.data[self.view.lnr+by][:bx+self.cx]) + if m: + self.cx -= len(m.group(0)) + m = re.compile(r'^\w*').match(self.view.data[self.view.lnr+by][bx+self.cx:]) + if m: + self.max = self.CX = min(self.cx+len(m.group(0)), len(self.view.line)) + else: + self.timer = time.time() + self.CX, self.CY = self.cx, self.cy renpy.redraw(self, 0) self.is_mouse_pressed = True if self.is_mouse_pressed and (ev.type == pygame.MOUSEMOTION or ev.type == pygame.MOUSEBUTTONUP):