I've been fiddling around with this, but still have had no luck.
If I start a search (using the UI) I can navigate around the results using:
import editor t = editor._get_editor_tab() v = t.editorView() v.selectFirstSearchResult() # moves forward v.highlightPrevSearchResult() # moves back
But if I try to set the search term with:
v.setSearchTerm_("text") v.applySearchTerm() v.highlightNextSearchResult()
It just moves through the original search term results.
Any thoughts or ideas would be appreciated.
@enceladus thanks for that. I actually use that API already (for results of a style check, where line granularity is good enough).
For the word frequency I need to see the individual words in context (just like the native highlighted search results), to assess whether they need replacing.
I have a python script that finds the most used words in a text file.
I have a working algorithm for finding the most used words. From this I create a listview of the words and phrases which I can click on.
I currently have a text view (which shows the markdown file) and use attributed text to highlight the clicked on word.
However, this reimplements the wheel, that is Pythonista's editor.
So, I would love to be able to click on the items and highlight the occurrences (case-insensitive) in a Pythonista editor tab (so that I can quickly edit some of the frequently used words with alternatives)
Does anyone have an example of how to highlight search results in the editor? I've experimented with editorView, but end up in a mess either setting up NSRegularExpression or getting the results to highlight.