Skip to content

Commit

Permalink
Fixes TextInputCutCopyPaste
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 committed Jun 21, 2022
1 parent 37292f0 commit b79397c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
37 changes: 19 additions & 18 deletions kivy/data/style.kv
Expand Up @@ -46,8 +46,6 @@
background_disabled_normal: 'atlas://data/images/defaulttheme/bubble_btn'
background_disabled_down: 'atlas://data/images/defaulttheme/bubble_btn_pressed'
border: (0, 0, 0, 0)
size_hint_y: None
height: dp(30)

<Slider>:
canvas:
Expand Down Expand Up @@ -201,29 +199,32 @@
rgba: self.disabled_foreground_color if self.disabled else (self.hint_text_color if not self.text else self.foreground_color)

<TextInputCutCopyPaste>:
content: content.__self__
but_cut: cut.__self__
but_copy: copy.__self__
but_paste: paste.__self__
but_selectall: selectall.__self__

size_hint: None, None
size: '150sp', '50sp'
BubbleButton:
id: cut
text: 'Cut'
on_release: root.do('cut')
BubbleButton:
id: copy
text: 'Copy'
on_release: root.do('copy')
BubbleButton:
id: paste
text: 'Paste'
on_release: root.do('paste')
BubbleButton:
id: selectall
text: 'Select All'
on_release: root.do('selectall')
BubbleContent:
id: content
BubbleButton:
id: cut
text: 'Cut'
on_release: root.do('cut')
BubbleButton:
id: copy
text: 'Copy'
on_release: root.do('copy')
BubbleButton:
id: paste
text: 'Paste'
on_release: root.do('paste')
BubbleButton:
id: selectall
text: 'Select All'
on_release: root.do('selectall')

<CodeInput>:
font_name: 'data/fonts/RobotoMono-Regular.ttf'
Expand Down
10 changes: 8 additions & 2 deletions kivy/tests/test_uix_textinput.py
Expand Up @@ -8,13 +8,12 @@

from kivy.core.window import Window
from kivy.tests.common import GraphicUnitTest, UTMotionEvent
from kivy.uix.textinput import TextInput
from kivy.uix.textinput import TextInput, TextInputCutCopyPaste
from kivy.uix.widget import Widget
from kivy.clock import Clock

touch_id = count()


class TextInputTest(unittest.TestCase):

def test_focusable_when_disabled(self):
Expand Down Expand Up @@ -546,6 +545,13 @@ def make_scrollable_text_input(self, num_of_lines=30, n_lines_to_show=10):
self.advance_frames(1)
return ti

def test_cutcopypastebubble_content(self):
tibubble = TextInputCutCopyPaste(textinput=TextInput())
assert tibubble.but_copy.parent == tibubble.content
assert tibubble.but_cut.parent == tibubble.content
assert tibubble.but_paste.parent == tibubble.content
assert tibubble.but_selectall.parent == tibubble.content


def ti_height_for_x_lines(ti, x):
"""Calculate TextInput height required to display x lines in viewport.
Expand Down
8 changes: 3 additions & 5 deletions kivy/uix/textinput.py
Expand Up @@ -164,7 +164,7 @@ def insert_text(self, substring, from_undo=False):
from kivy.graphics.texture import Texture

from kivy.uix.widget import Widget
from kivy.uix.bubble import Bubble, BubbleContent
from kivy.uix.bubble import Bubble
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image

Expand Down Expand Up @@ -306,8 +306,6 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self._check_parent_ev = Clock.schedule_interval(self._check_parent, .5)
self.matrix = self.textinput.get_window_matrix()
self.bubble_content = BubbleContent
self.add_widget(self.bubble_content)

with self.canvas.before:
Callback(self.update_transform)
Expand Down Expand Up @@ -374,7 +372,7 @@ def on_parent(self, instance, value):
mode = self.mode

if parent:
self.bubble_content.clear_widgets()
self.content.clear_widgets()
if mode == 'paste':
# show only paste on long touch
self.but_selectall.opacity = 1
Expand All @@ -389,7 +387,7 @@ def on_parent(self, instance, value):
widget_list = (self.but_cut, self.but_copy, self.but_paste)

for widget in widget_list:
self.bubble_content.add_widget(widget)
self.content.add_widget(widget)

def do(self, action):
textinput = self.textinput
Expand Down

0 comments on commit b79397c

Please sign in to comment.