Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions data/gtk/ui/Preferences.blp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ template $LexiPreferences : Adw.PreferencesDialog {
title: _("Use Debug logging profile");
}
}


Adw.PreferencesGroup {
title: _("Search");

Adw.SwitchRow use_accent_insensitive_search_row {
title: _("Ignore accents when searching for words");
}
}
}

Adw.PreferencesPage {
Expand Down
3 changes: 3 additions & 0 deletions data/io.github.dzheremi2.lexi.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<key name="save-on-exit" type="b">
<default>false</default>
</key>
<key name="accent-insensitive-search" type="b">
<default>true</default>
</key>
</schema>

<schema id="@APP_ID@.State" path="@PREFIX@/State/">
Expand Down
7 changes: 7 additions & 0 deletions lexi/ui/Preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LexiPreferences(Adw.PreferencesDialog):
available_word_types_scrolled_window: Gtk.ScrolledWindow = gtc()
available_word_types_list_box: Gtk.ListBox = gtc()
use_debug_log_switch_row: Adw.SwitchRow = gtc()
use_accent_insensitive_search_switch_row: Adw.SwitchRow = gtc()

opened: bool = False

Expand All @@ -41,6 +42,12 @@ def __init__(self) -> None:
"active",
Gio.SettingsBindFlags.DEFAULT,
)
shared.schema.bind(
"accent-insensitive-search",
self.use_accent_insensitive_search_switch_row,
"active",
Gio.SettingsBindFlags.DEFAULT,
)

self.use_debug_log_switch_row.connect(
"notify::active", self.__set_use_debug_log
Expand Down
20 changes: 13 additions & 7 deletions lexi/utils/sort_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from lexi.logging.logger import logger
from lexi.ui.WordRow import WordRow

import unicodedata

# pylint: disable=no-else-return
def sort_words(row1: WordRow, row2: WordRow) -> int:
Expand Down Expand Up @@ -60,6 +61,11 @@ def sort_words(row1: WordRow, row2: WordRow) -> int:
else:
return 0

def remove_accents(text: str) -> str:
if shared.schema.get_boolean("accent-insensitive-search"):
text = unicodedata.normalize("NFD", text)
return ''.join(character for character in text if not unicodedata.combining(character))
return text

def filter_words(row: WordRow) -> bool:
"""
Expand All @@ -75,19 +81,19 @@ def filter_words(row: WordRow) -> bool:
bool
True if the word matches both the text and type filters, False otherwise
"""
text: str = shared.win.lexicon_search_entry.get_text().lower()
text: str = remove_accents(shared.win.lexicon_search_entry.get_text().lower().strip())
fits_in_filter = set(shared.config["enabled-types"]).issubset(set(row.word.types))
if not text.startswith("#"):
try:
matches_text = (
text == ""
or text in row.word.word.lower().replace("&rtl", "")
or (
text in row.word.translations[0].lower().replace("&rtl", "")
if row.word.translations
else ""
)
or text in remove_accents(row.word.word.lower().replace("&rtl", ""))
)
if not matches_text and row.word.translations:
for translation in row.word.translations:
if text in remove_accents(translation.lower().replace("&rtl", "")):
matches_text = True
break
logger.debug(
"Word “%s”, is shown: %s",
row.word.word,
Expand Down