-
-
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
adding tabModeSearch to search in page #240
base: master
Are you sure you want to change the base?
Conversation
Hello, thanks for your contribution and interest in Amfora!
Unfortunately it's pretty important to me that no page content gets messed up during searching. Regular expressions are needed because the content of the rendered version of the page can contain cview color tags like This is why searching for "#" causes issues, because a lot of the tags in your page look like The solution to this is to use regexes to detect what's a tag and what's not, and skip over highlighting the things that are. This is all explained in #36. The steps needed to be implemented and the regex to use are all there. If you'd like to update this PR to do that, I can leave it open, otherwise I'll close it. I appreciate you taking a stab at this, unfortunately it's trickier than any of us would like it to be. |
Hi @makeworld-the-better-one, thanks for your reply and suggestions.
It's already some time ago that I looked into that, but I think that Please leave this PR open, so I can continue to work on this, and maybe others could also jump in. I think that I would have profited from the previous efforts that have been made in this direction, if the code had been visible here. |
Good to hear, thanks!
Ah, you're right. Adding numbered region IDs will conflict with the link region IDs though, which are just numbers right now. Maybe for this the IDs could be like |
@makeworld-the-better-one thanks again ;) I tried to implement all your suggestions; it seems to work well. The only flaw I currently see is that no search results are found inside of brackets that are no tags. Maybe that's an easy fix in the |
Thanks for updating. I will review this PR in full soon. For now I came up with a new tags regex to try: \[[a-zA-Z0-9_,;: \-\."#]+[^\[]*\] Let me know how that works, and if it solves the issue or creates new ones.
The raw view is stored inside each page struct. Not sure if you meant displaying the raw text, which would require escaping it then displaying it. There's no simple way to switch to displaying it built-in, but if you want to look at the raw page contents from the network, that's available in the struct. Also there are some linter errors to look at. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for adding this! Super cool to see it in action. Please take a look at my comments above and below.
- Scroll position isn't saved after exiting search, so if I go back and go forward again it won't be in the right place
- Making two full copies of the page content feels very inefficient. I can't really think of a better way though, let me know if you have any ideas.
- Please replace
ScrollToHighlight
witht.scrollToHighlight
. This was just added tomaster
so you'll have to update your branch here first.
config/config.go
Outdated
viper.SetDefault("keybindings.bind_search", "/") | ||
viper.SetDefault("keybindings.bind_next_match", "n") | ||
viper.SetDefault("keybindings.bind_prev_match", "p") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These keybindings need to be added to default-config.toml and to help.go. Don't forget to run make gen
after doing that as well.
Also please change these keybindings to match Vim/less. See this comment.
display/display.go
Outdated
@@ -28,6 +28,12 @@ var termH int | |||
// The user input and URL display bar at the bottom | |||
var bottomBar = cview.NewInputField() | |||
|
|||
var originalText []byte | |||
var searchBar = cview.NewInputField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a separate bar instead of using the existing one? Also this primitive would need to be themed like the bottom bar is. But I think just keeping one bar is better.
display/display.go
Outdated
searchIdx := searchRegex.FindAllIndex(originalText, -1) | ||
|
||
// find all positions of tags | ||
tagsRegex := regexp.MustCompile(`\[.*?[^\[]\]`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex should be changed as I noted in my previous comment, and also it can be compiled once globally, instead of in this function.
display/display.go
Outdated
// with the actual search strings replaced by tagged regions | ||
// to highlight. | ||
for i, match := range searchIdx { | ||
isMatch = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this variable unnecessary? You already break out of the loop if it's false, so the check on 313 isn't needed either.
display/display.go
Outdated
tagsRegex := regexp.MustCompile(`\[.*?[^\[]\]`) | ||
tagsIdx := tagsRegex.FindAllIndex(originalText, -1) | ||
|
||
text := []byte("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text := []byte("") | |
text := make([]byte, 0) |
display/display.go
Outdated
if isMatch { | ||
matches++ | ||
text = append(text, originalText[lastMatch:match[0]]...) | ||
replacement := []byte(fmt.Sprint("[\"search-", i, "\"]", searchString, "[\"\"]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replacement := []byte(fmt.Sprint("[\"search-", i, "\"]", searchString, "[\"\"]")) | |
replacement := []byte(fmt.Sprint(`["search-`, i, `"]`, searchString, `[""]`)) |
Using raw strings makes this much more readable.
case config.CmdInvalid: | ||
if event.Key() == tcell.KeyEsc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can ignore this case and just check the key with an if statement outside the switch.
can we have this as experimental feature? would be helpful even it is bugs |
@hisacro thanks, I completely forgot about this PR, but it's nice to you're interested ;) @makew0rld my apologies for not following up on this earlier, and thank you so much for your thorough review. I think I have addressed all the points you mentioned, and tried to make small and clear commits for most of them. Please let me know if anything else is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be fine this way, not sure about official review workflow in github. I guess I hit the "Submit review" button now. Please let me know if I can make any further improvements!
@@ -33,4 +33,5 @@ Thank you to the following contributors, who have helped make Amfora great. FOSS | |||
* Maxime Bouillot (@Arkaeriit) | |||
* Emily (@emily-is-my-username) | |||
* Autumn! (@autumnull) | |||
* William Rehwinkel (@FiskFan1999) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not sure why this addition is listed here, it happened during merge of the master branch, I think
Thanks. The diff on this doesn't look too bad, but in the near term I don't have time to test and add new features to Amfora. If you keep this PR open I might get to it eventually. You can see the readme for details. |
Addressing #36 I tried to follow up on that matter, because I really would love to have the 'search in page' feature implemented. I couldn't find the code that @lachrimae already worked on and I never really wrote a line of go before, so I expect that some of my edits can easily be improved. I'm thankful for any suggestions to make this PR better.
Instead of adding a "search" region tag, I add numbered tags to the matching strings, to make use of
cview
'sScrollToHighlight
function. I added a new tabMode to block other keypresses like follow links, as suggested in #36.The way this is implemented, a search can potentially mess up other regions (e.g. if searched for special characters like
#
or>
). I'm currently not sure how to address this best. I have not used regular expressions, not because I don't know how, but because I don't know how they can solve this problem. However, with anEsc
keypress, the original buffer will be restored.