Offload selection manipulation of TextInput to backend
This commit is contained in:
		
							parent
							
								
									b87f32eac9
								
							
						
					
					
						commit
						6ea1679112
					
				
							
								
								
									
										58
									
								
								textinput.go
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								textinput.go
									
									
									
									
									
								
							@ -66,57 +66,57 @@ func (this *TextInput) handleKeyDown (key input.Key, numpad bool) bool {
 | 
				
			|||||||
	dot       := this.Dot()
 | 
						dot       := this.Dot()
 | 
				
			||||||
	modifiers := this.Window().Modifiers()
 | 
						modifiers := this.Window().Modifiers()
 | 
				
			||||||
	word      := modifiers.Control
 | 
						word      := modifiers.Control
 | 
				
			||||||
	sel       := modifiers.Shift
 | 
					 | 
				
			||||||
	changed   := false
 | 
						changed   := false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO all dot control (movement, selection, etc) should be done in the
 | 
						defer func () {
 | 
				
			||||||
	// backend. (editing should be done here, though)
 | 
							this.Select(dot)
 | 
				
			||||||
 | 
							if changed {
 | 
				
			||||||
 | 
								this.SetText(string(this.text))
 | 
				
			||||||
 | 
								this.on.valueChange.Broadcast()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} ()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch {
 | 
						switch {
 | 
				
			||||||
	case key == input.KeyEnter:
 | 
						case key == input.KeyEnter:
 | 
				
			||||||
		this.on.confirm.Broadcast()
 | 
							this.on.confirm.Broadcast()
 | 
				
			||||||
	case key == input.KeyHome || (modifiers.Alt && key == input.KeyLeft):
 | 
							return true
 | 
				
			||||||
		dot.End = 0
 | 
					 | 
				
			||||||
		if !sel { dot.Start = dot.End }
 | 
					 | 
				
			||||||
	case key == input.KeyEnd || (modifiers.Alt && key == input.KeyRight):
 | 
					 | 
				
			||||||
		dot.End = len(this.text)
 | 
					 | 
				
			||||||
		if !sel { dot.Start = dot.End }
 | 
					 | 
				
			||||||
	case key == input.KeyLeft:
 | 
					 | 
				
			||||||
		if sel {
 | 
					 | 
				
			||||||
			dot = text.SelectLeft(this.text, dot, word)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			dot = text.MoveLeft(this.text, dot, word)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case key == input.KeyRight:
 | 
					 | 
				
			||||||
		if sel {
 | 
					 | 
				
			||||||
			dot = text.SelectRight(this.text, dot, word)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			dot = text.MoveRight(this.text, dot, word)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	case key == input.KeyBackspace:
 | 
						case key == input.KeyBackspace:
 | 
				
			||||||
		this.text, dot = text.Backspace(this.text, dot, word)
 | 
							this.text, dot = text.Backspace(this.text, dot, word)
 | 
				
			||||||
		changed = true
 | 
							changed = true
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
	case key == input.KeyDelete:
 | 
						case key == input.KeyDelete:
 | 
				
			||||||
		this.text, dot = text.Delete(this.text, dot, word)
 | 
							this.text, dot = text.Delete(this.text, dot, word)
 | 
				
			||||||
		changed = true
 | 
							changed = true
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
	case key == input.Key('a') && modifiers.Control:
 | 
						case key == input.Key('a') && modifiers.Control:
 | 
				
			||||||
		dot.Start = 0
 | 
							dot.Start = 0
 | 
				
			||||||
		dot.End   = len(this.text)
 | 
							dot.End   = len(this.text)
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
	case key.Printable():
 | 
						case key.Printable():
 | 
				
			||||||
		this.text, dot = text.Type(this.text, dot, rune(key))
 | 
							this.text, dot = text.Type(this.text, dot, rune(key))
 | 
				
			||||||
		changed = true
 | 
							changed = true
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	this.Select(dot)
 | 
					 | 
				
			||||||
	if changed {
 | 
					 | 
				
			||||||
		this.SetText(string(this.text))
 | 
					 | 
				
			||||||
		this.on.valueChange.Broadcast()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return true
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
 | 
					func (this *TextInput) handleKeyUp (key input.Key, numpad bool) bool {
 | 
				
			||||||
	return true
 | 
						modifiers := this.Window().Modifiers()
 | 
				
			||||||
 | 
						switch {
 | 
				
			||||||
 | 
						case key == input.KeyEnter:
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						case key == input.KeyBackspace:
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						case key == input.KeyDelete:
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						case key == input.Key('a') && modifiers.Control:
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						case key.Printable():
 | 
				
			||||||
 | 
							return true
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return false
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (this *TextInput) handleScroll (x, y float64) bool {
 | 
					func (this *TextInput) handleScroll (x, y float64) bool {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user