I would like for my cursor to automatically go to the search result after I stop typing. For example, I type “thing”, after 100ms (or whatever the debounce/delay is), I’d like the cursor to automatically go to the first match (if it exists) rather than me having to constantly hit ‘enter’, which gets a bit sore having to press ‘enter’ 100 times per day
I mean I want to show my search result in Anki browser when user start typing in search input field.
I’ve searched and tried a lot and am still looking for a Python script or Anki Add-ons that makes me show the search result instantly when typing without hitting enter button or search button in Anki browse. For ex, I type “thing”, after 100ms (or whatever the debounce/delay is), I’d like to automatically show the search result (if it exists) rather than me having to constantly hit ‘enter’, which gets a bit sore having to press ‘enter’ 100 times per day.
I mean I want to show my search result in Anki browser instantly when I start typing in search input field without press enter button or search button in Anki browse.
I’ve got this Python script, it’s almost about to solve the problem :
Create a new folder named incremental_searchor something in the addons21folder in Anki’s data folder 1.
Create a new file named init.pyin that folder, and enter the following code:
from typing import cast
from aqt.browser import Browser
from aqt.gui_hooks import browser_will_show
from aqt.qt import QLineEdit, QTimer
def on_browser_will_show(browser: Browser) -> None:
def on_text_changed() -> None:
if line_edit.text():
timer.start(300)
else:
timer.stop()
def on_timeout() -> None:
browser.onSearchActivated()
timer = QTimer(browser)
timer.timeout.connect(on_timeout)
line_edit = cast(QLineEdit, browser.form.searchEdit.lineEdit())
line_edit.textChanged.connect(on_text_changed)
browser_will_show.append(on_browser_will_show)
Please help! I appreciate your time and effort. Thanks in advance.
I’ve searched and tried a lot and am still looking for an AHK script or Anki Add-ons that makes the cursor to automatically go to the search instantly when typing without hitting enter button or search button in Anki browse. For ex, I type “thing”, after 100ms (or whatever the debounce/delay is), I’d like the cursor to automatically go to the first match (if it exists) rather than me having to constantly hit ‘enter’, which gets a bit sore having to press ‘enter’ 100 times per day.
I mean I want to show my search result in Anki browser instantly when user start typing in search input field without press enter button or search button in Anki browse.
I’ve got this script, it’s almost about to solve the problem.
this script (send, enter) after each character I enter in any input location in the browse, So if I type in the field designated to stock something (front, back), it does a line break after each character I enter.
could someone makes this process (send, enter) “after delay” works only in the search field knowing that its coordinates for the browse window are X431, Y76.
Please help! I appreciate your time and effort. Thanks in advance.
It works, When I type in the search field it does
what I want, But it has some problems :
1- When I’m typing in the search field and I want
to select all the words in it or (with 2
clicks or Ctrl+A) or move the cursor back, The
cursor automatically and quickly returns to the
front after doing that.
2 - The same problem (1) when I type in the field
designed to stock or edit somthing in the
browse (Front,Back).
3 - when I scroll down by Mouse wheel, the scroll bar returns to the place where it was the first time.
4 - Sometimes Anki stops working (I think that’s because of the previous problems).
Thanks for the feedback and sorry for the late reply. I’ve been a little busy the past few days and haven’t had time to look into the issues. I have fixed them now, so give it a try.
from typing import cast
from aqt.browser import Browser
from aqt.gui_hooks import browser_will_show
from aqt.qt import QLineEdit, QTimer
def on_browser_will_show(browser: Browser) -> None:
def on_text_changed(text: str) -> None:
if text:
timer.start(300)
else:
timer.stop()
def on_timeout() -> None:
browser.onSearchActivated()
timer = QTimer(browser)
timer.setSingleShot(True)
timer.timeout.connect(on_timeout)
line_edit = cast(QLineEdit, browser.form.searchEdit.lineEdit())
line_edit.textEdited.connect(on_text_changed)
browser_will_show.append(on_browser_will_show)
By the way, whether or not this add-on will work comfortably depends on the specs of your computer and the number of notes in your collection. I tested it with a collection of 10,000 notes on a high spec machine and it worked comfortably, but when I tested it with 300,000 notes on a low spec machine, it froze a bit every time I typed a single character, so it was not practical at all.
Thank you very much.
Now, The process had become work almost without any problem, But there is still only one problem :
For example, when I want to search for a word (“something”) and type the word in the search field and I misspelled some letters of the word (inside or at the beginning of the word), or I forgot to write some letters (inside or at the beginning of the word), or if I want to delete some letters from it (inside or at the beginning of the word) for ex: (“Sonting”) , (“omting”).
When I move the caret to where I want to replace or add or delete some characters (inside or at the beginning of the word), as soon as I type just one character or delete one, the caret automatically and quickly returns to the end of the word after I type or delete just one.
Can you make the caret not return automatically to the end of the word after typing or deleting inside or at the beginning of the word.