mirror of
				https://codeberg.org/1414codeforge/yui.git
				synced 2025-06-05 22:19:11 +02:00 
			
		
		
		
	[input] Invoke onChange() on text change.
This commit is contained in:
		
							
								
								
									
										13
									
								
								input.lua
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								input.lua
									
									
									
									
									
								
							@@ -85,6 +85,8 @@ function Input:textinput(text)
 | 
			
		||||
 | 
			
		||||
        self.text = table.concat {a, text, b}
 | 
			
		||||
        self.cursor = self.cursor + utf8.len(text)
 | 
			
		||||
 | 
			
		||||
        self:onChange(self.text)
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@@ -100,21 +102,22 @@ function Input:keypressed(key, code, isrepeat)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if self.candidate.length == 0 then
 | 
			
		||||
        if key == 'backspace' then
 | 
			
		||||
        if key == 'backspace' and self.cursor > 1 then
 | 
			
		||||
            local a,b = split(self.text, self.cursor)
 | 
			
		||||
 | 
			
		||||
            self.text = table.concat { split(a, utf8.len(a)), b }
 | 
			
		||||
            self.cursor = math.max(1, self.cursor-1)
 | 
			
		||||
            self.cursor = self.cursor-1
 | 
			
		||||
 | 
			
		||||
        elseif key == 'delete' then
 | 
			
		||||
            self:onChange(self.text)
 | 
			
		||||
        elseif key == 'delete' and self.cursor ~= utf8.len(self.text)+1 then
 | 
			
		||||
            local a,b = split(self.text, self.cursor)
 | 
			
		||||
            local _,b = split(b, 2)
 | 
			
		||||
 | 
			
		||||
            self.text = table.concat { a, b }
 | 
			
		||||
 | 
			
		||||
            self:onChange(self.text)
 | 
			
		||||
        elseif key == 'left' then
 | 
			
		||||
            self.cursor = math.max(0, self.cursor-1)
 | 
			
		||||
 | 
			
		||||
            self.cursor = math.max(1, self.cursor-1)
 | 
			
		||||
        elseif key == 'right' then
 | 
			
		||||
            self.cursor = math.min(utf8.len(self.text)+1, self.cursor+1)
 | 
			
		||||
        end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user