ttkwidgets icon indicating copy to clipboard operation
ttkwidgets copied to clipboard

Autocomplete Feature Not Working for Cyrillic Characters

Open Amgarak opened this issue 4 months ago • 0 comments

Description:

In the AutocompleteCombobox class, the handle_keyrelease method currently checks for the length of event.keysym to determine if autocomplete should be triggered. This check fails for Cyrillic characters, as their keysym has a length of 2, resulting in the autocomplete feature not functioning for these characters.

Current Implementation:

def handle_keyrelease(self, event):
    if len(event.keysym) == 1:
        self.autocomplete()

Example:

  • For the Cyrillic character "г", len(event.keysym) = 2
  • For the Latin character "g", len(event.keysym) = 1

Proposed Solution:

Update the handle_keyrelease method to allow for the autocomplete feature to be triggered for all character inputs, not just those with a keysym length of 1. The following implementation has been suggested:

import tkinter as tk
from ttkwidgets.autocomplete import AutocompleteCombobox 

class CustomAutocompleteCombobox(AutocompleteCombobox):
    def handle_keyrelease(self, event):
        if event.keysym == "BackSpace":
            self.delete(self.index(tk.INSERT), tk.END)
            self.position = self.index(tk.END)
        
        elif event.keysym == "Left":
            if self.position < self.index(tk.END):  
                self.delete(self.position, tk.END)
            else:
                self.position -= 1  
                self.delete(self.position, tk.END)
            
        elif event.keysym == "Right":
            self.position = self.index(tk.END)  
    
        elif event.keysym == "Return":
            self.handle_return(event)  
            return
        else:
            # Call autocomplete for all other keys
            self.autocomplete()

Expected Outcome:

With this change, the autocomplete feature should work correctly for both Cyrillic and Latin characters, providing a more user-friendly experience.

Amgarak avatar Oct 08 '24 15:10 Amgarak