Delete text in command box
This commit is contained in:
parent
c04d2c62f2
commit
b8390bfac8
@ -45,12 +45,15 @@ class Command_prompt(Label):
|
|||||||
self.text=self.raw_text
|
self.text=self.raw_text
|
||||||
|
|
||||||
def on_key_down(self, keyboard, keycode, text, modifiers):
|
def on_key_down(self, keyboard, keycode, text, modifiers):
|
||||||
#print(keycode,text,modifiers)
|
print(keycode,text,modifiers)
|
||||||
if self.insert:
|
if self.insert:
|
||||||
|
# process command
|
||||||
if keycode[1]=="enter":
|
if keycode[1]=="enter":
|
||||||
self.insert=False
|
self.insert=False
|
||||||
self.parse_command()
|
self.parse_command()
|
||||||
self.set_text("")
|
self.set_text("")
|
||||||
|
|
||||||
|
# move
|
||||||
elif keycode[1]=="left":
|
elif keycode[1]=="left":
|
||||||
self.move_cursor_relative(-1)
|
self.move_cursor_relative(-1)
|
||||||
elif keycode[1]=="right":
|
elif keycode[1]=="right":
|
||||||
@ -60,6 +63,14 @@ class Command_prompt(Label):
|
|||||||
elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="e":
|
elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="e":
|
||||||
self.move_cursor(len(self.raw_text))
|
self.move_cursor(len(self.raw_text))
|
||||||
|
|
||||||
|
# delete
|
||||||
|
elif keycode[1]=="backspace":
|
||||||
|
self.backspace()
|
||||||
|
elif keycode[1]=="delete":
|
||||||
|
self.delete_forward()
|
||||||
|
elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="k":
|
||||||
|
self.delete_all_forward()
|
||||||
|
|
||||||
def on_textinput(self,window,text):
|
def on_textinput(self,window,text):
|
||||||
#print(text)
|
#print(text)
|
||||||
if self.insert:
|
if self.insert:
|
||||||
@ -77,6 +88,33 @@ class Command_prompt(Label):
|
|||||||
self.cursor+=len(text)
|
self.cursor+=len(text)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
# delete before cursor
|
||||||
|
def backspace(self):
|
||||||
|
# do not delete leading ':'
|
||||||
|
if self.cursor==1:
|
||||||
|
return
|
||||||
|
if self.cursor==len(self.raw_text):
|
||||||
|
self.raw_text=self.raw_text[:self.cursor-1]
|
||||||
|
else:
|
||||||
|
self.raw_text=self.raw_text[:self.cursor-1]+self.raw_text[self.cursor:]
|
||||||
|
self.cursor-=1
|
||||||
|
self.draw()
|
||||||
|
# delete after cursor
|
||||||
|
def delete_forward(self):
|
||||||
|
if self.cursor==len(self.raw_text):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.raw_text=self.raw_text[:self.cursor]+self.raw_text[self.cursor+1:]
|
||||||
|
self.draw()
|
||||||
|
# delete until end of line(self):
|
||||||
|
def delete_all_forward(self):
|
||||||
|
if self.cursor==len(self.raw_text):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.raw_text=self.raw_text[:self.cursor]
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
|
||||||
# set text in prompt
|
# set text in prompt
|
||||||
def set_text(self,text):
|
def set_text(self,text):
|
||||||
self.raw_text=text
|
self.raw_text=text
|
||||||
|
Loading…
Reference in New Issue
Block a user