-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search in pages #36
Comments
The searching for the bit of text should ignore any style or region tags, so that may require a regex as well. This is a example where having access to the raw content, as discussed in #33, would be useful. It might be worth waiting for that before implementing this. If the raw content is available, maybe a search term could be part of the render process, as an arg passed to |
Having to add a per-tab mode setting is last straw of the code being somewhat disorganized. Using a |
The |
That work was completed. |
I'm investigating how to implement search in pages at the moment. Most of the difficulty seems to me to lie in the fact that it's difficult to reason about the state of the application in the relevant blocks of code. You can see, for instance, with this tool, that the number of The point of this refactor is to make the organization of the code correspond to the state of the application. Code that should run under different application state should be in separate functions. When someone presses In particular, I propose to
After doing this refactor, it'll be easier to keep track of application state, with the bonus that display.go will be more organized and readable. At that point, writing the search functionality will involve much less cognitive overhead. How does that sound to you? |
Most of my difficulty with implementing this was due to the fact that cview color tags would need to be used to highlight the search results, and they would need to changed every time the user asks for the next match. These changes would either require a complete re-render of the page content, or some sort of error-prone substitution regex. Furthermore, inserting the search term color tags but not matching any text already in the tags seemed like a difficult problem to me, that could potentially be solved with a complicated regex. Here is a simplified example of what the rendered text looks like before it's outputted to the screen:
Now, if the user searches for the string With all that said, I see how that part of the code is complicated and large. If a refactor helps you, go for it! Your suggestions seem good, I would have to see them worked out before I can commit to approving anything of course. Thank you for your interest! |
Thank you for starting the project! And I appreciate you laying out the situation for me like this. I'll go ahead with the refactor because it'll help me put in the UI work, but I understand that you have to wait and see to approve or not. I'll take a look at the regex stuff. I suspect there'll be a problem removing the cview tags using just regex, since regex is technically just for regular languages, whereas it's my understanding that languages involving open/close brackets (or open/close tags...) are never regular. This problem may require a proper parser. |
I'd be surprised if modern regex can't do this, but we'll see. Really hoping to not need a parser. Let me know if you have any questions! |
I've been looking into the regex approach, and I have mixed news.
However, the standard library implementation of regex for go does not support lookabouts. If you read between the lines of the first couple of paragraphs here, it sounds like they left those out in order to have an O(n) complexity guarantee. The link they have there suggests that many of the popular implementations are exponential in bad cases. In any case, I don't think I can solve this with just the standard library regex. So I'm trying to find alternatives to the standard regex library. Does this PCRE library look good to you?. I also found a parser generator |
Thanks for looking into this. I think trying to enumerate all the possible content of the tags is the wrong way to go. I just figured out a regex that seems to capture all valid tags and exclude escaped ones. It seems to pass all the tests listed here. \[.*[^\[]\] You can try it out here. Am I missing something? |
You're right that your expression matches valid tags and excludes escaped ones. I was trying to figure out the structure of valid tags (with strictly valid colour settings) with the idea that the final regex will likely look very different from that one. Your regex may well be superior for the final code. I take it that what want to do is to be able to input With your expression, we would be able to transform cview tags into other kinds of things. But without lookabouts, it seems to me that we can't do the search+replace we want. We could do something wacky like
But that seems like reinventing the wheel... |
Ah I see now, the lookabouts allow for tag detection while also searching for a substring. I am reluctant to bring in another regex engine or write a full parser. And so, I think your wacky solution might be the best one. Let me restate the steps below to ensure we're on the same page:
Step 1 could be cached whenever a page is loaded, for performance purposes. Does that align with what you wrote above, am I understanding correctly?
Unfortunately it does not, as it is not pure Go. I am using only Go deps for this project, as it keeps cross-compiling simple. |
Yes, I think we're on the same page about the "wacky solution" 😄. I'll start working in that direction. There's one complication for step 3, though, assuming I understand the desired behaviour correctly. Supposing
which means we'll have to backtrack to see what the most recent tag was. Since their indices were cached from step 1, it's not a big problem, though. Avoiding an external regex engine and keeping everything in Go makes sense to me. Regarding the parser, |
Good catch, yes that will be required.
Yep, should just be able to copy those bytes.
Exactly, it seems like a lot of code, which isn't quite worth it to me. Thanks for starting your work, feel free to give me updates or ask questions here! |
@lachrimae Have you been able to make any progress on this? No worries if not. |
Hey @makeworld-the-better-one I have made some progress. I suddenly had more paperwork to do so completing this feature fell by the wayside for me. Some of that is behind me now so I'm going to get back on the wagon. |
All good, happy to hear that! No worries if you don't complete it either, I'd just like to know. |
@lachrimae Are you still planning on adding this? No worries if not. Edit on 2020-12-09: I've removed you from the assignees for this issue, and will accept PRs from others on this now. Would be happy to hear back from you at any point, though. Thanks for hashing stuff out with me in thread, it was valuable. |
Note: Vim/less keybindings should also be added. Forward slash to start query, n (forward) and Shift-N (backward) for iterating through results, Esc-u to stop highlighting, etc. |
Ctrl-F should bring up a bottom bar prompt to enter a search term. On Enter a
["search"]
region will be prepended to any bit of text that matches the search, with a[""]
after it. Link selecting will have to be disabled, maybe with someglobalper-tab mode setting that switches between link, off, and search. Tab and Backtab can be used to navigate through all the found text fragments. Esc should switch theglobalper-tab mode back to off, and maybe use a regex to remove all the region open and close tags for the search.The text was updated successfully, but these errors were encountered: