Relative cursor movement
This commit is contained in:
parent
7ad1a56627
commit
c9c0bcbc51
@ -48,9 +48,13 @@ class Command_prompt(Label):
|
||||
self.insert=False
|
||||
self.set_text("")
|
||||
elif keycode[1]=="left":
|
||||
self.move_cursor(-1)
|
||||
self.move_cursor_relative(-1)
|
||||
elif keycode[1]=="right":
|
||||
self.move_cursor_relative(1)
|
||||
elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="a":
|
||||
self.move_cursor(1)
|
||||
elif len(modifiers)==1 and modifiers[0]=="ctrl" and text=="e":
|
||||
self.move_cursor(len(self.raw_text))
|
||||
|
||||
def on_textinput(self,window,text):
|
||||
print(text)
|
||||
@ -76,8 +80,13 @@ class Command_prompt(Label):
|
||||
self.draw()
|
||||
|
||||
# move cursor n steps to right (left if negative)
|
||||
def move_cursor(self,n):
|
||||
def move_cursor_relative(self,n):
|
||||
if n==0 or (n>0 and self.cursor==len(self.raw_text)) or (n<0 and self.cursor==0):
|
||||
return
|
||||
self.cursor=max(0,min(len(self.raw_text),self.cursor+n))
|
||||
self.cursor=max(1,min(len(self.raw_text),self.cursor+n))
|
||||
self.draw()
|
||||
|
||||
# move cursor to absolute position
|
||||
def move_cursor(self,n):
|
||||
self.cursor=max(1,min(len(self.raw_text),n))
|
||||
self.draw()
|
||||
|
Loading…
Reference in New Issue
Block a user