Skip to content

Commit

Permalink
add word selection on double mouse click
Browse files Browse the repository at this point in the history
Signed-off-by: picobyte <[email protected]>
  • Loading branch information
picobyte authored and picobyte committed Nov 15, 2017
1 parent ec81c7c commit ca866a5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion game/edit_button.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ init -1500 python in _editor:
import re
import codecs
import textwrap
import time

import math

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ca866a5

Please sign in to comment.