nyxt icon indicating copy to clipboard operation
nyxt copied to clipboard

Lispy search-buffer

Open aartaka opened this issue 2 years ago • 19 comments

Description

This changes our search functionality to depend on Plump and Lisp-side calculations. Pros:

  • More controllable and extensible (for example, for #2230 (CC @aadcg) and search-based annotations).
  • Stores most data on the Lisp side, thus saves lots of JavaScript calls.
  • Adds a neat set of changes to nyxt/dom that can be used for libraries and extensions.

Cons:

  • Highlighting is less exact, as it highlights the smallest element containing the search text, and this element may not be exactly small.
  • May be slower than JS-based search, but, given how fast we made our hints, this is a solvable problem.

This also includes quite some changes to the existing functions that make working with Plump DOM even easier!

Discussion

  • Is the element-level highlighting enough for text search? I feel like it adds more context, but I can foresee the opposing arguments too :)
  • Should we reuse the same nyxt/dom:get-unique-selector in hint mode? This way, we don't need to alter tha page structure anymore. But then, it may be not unique enough...

Checklist:

Everything in this checklist is required for each PR. Please do not approve a PR that does not have all of these items.

  • [X] I have pulled from master before submitting this PR
  • [X] My code follows the style guidelines for Common Lisp code
  • [X] I have performed a self-review of my own code
  • [ ] My code has been reviewed by at least one peer (the peer review to approve a PR counts. The reviewer must download and test the code)
  • [X] I have commented my code, particularly in hard-to-understand areas
  • [X] I have made corresponding changes to the documentation
  • [X] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [X] New and existing unit tests pass locally with my changes
  • [X] There are no merge conflicts

How does it look?

aartaka avatar Jul 01 '22 17:07 aartaka

I've tested it. Searching multiple times on a page led to a crash :-O. Additionally, highlighting the whole element is not particularly helpful! I also noticed that when searching large sections of the page would become blank! I can attach screenshots later if you like.

jmercouris avatar Jul 02 '22 20:07 jmercouris

In any case, let's not merge this before 3-pre-release-1.

Ambrevar avatar Jul 04 '22 09:07 Ambrevar

@aartaka exciting work! It's not there yet, but it's promising.

In terms of the design, I'm not convinced on the idea of highlighting elements. Say we you have multiple matches on one element.

aadcg avatar Jul 04 '22 21:07 aadcg

In any case, let's not merge this before 3-pre-release-1.

Sure!

aartaka avatar Jul 05 '22 08:07 aartaka

I've tested it. Searching multiple times on a page led to a crash :-O. Additionally, highlighting the whole element is not particularly helpful! I also noticed that when searching large sections of the page would become blank! I can attach screenshots later if you like.

Huh, that's interesting, I haven't see anything like that when testing 🤔 A reason to test more then :D

aartaka avatar Jul 05 '22 08:07 aartaka

In terms of the design, I'm not convinced on the idea of highlighting elements. Say we you have multiple matches on one element.

Neither am I. But I can see the benefit of highlighting the whole piece, as what we are usually looking for is the paragraph/mention/context of a certain word/phrase, not the exact phrase itself.

aartaka avatar Jul 05 '22 09:07 aartaka

@aadcg 's feedback on the call: maybe highlight both the context (the element) and the exact matches (user input) in different degrees of accent color.

EDIT: Clarify. EDIT: Right nickname.

aartaka avatar Jul 06 '22 14:07 aartaka

OK, I've contributed a more extensive character set to the CLSS, which should mitigate the biggest source of errors and crashes of lispy search that @jmercouris noticed (although I'd enjoy having more detailed reports). Search should work fine now. Things left to do:

  • Highlighting both elements and text matches, as per @aadcg's feedback.
  • Polish the element counting function to actually update the DOM when things change significantly. Right now it seems to stay outdated for long enough to invalidate the search.

aartaka avatar Jul 22 '22 12:07 aartaka

Element counting is fixed on master with e9e85bf1966961f293ea64cdc8078f9c61183f29 :D

aartaka avatar Jul 25 '22 09:07 aartaka

Note that to test this properly, you need the most recent CLSS!

aartaka avatar Jul 25 '22 12:07 aartaka

While I want this to be merged as an improvement over opaque JS-based search, I am demotivated trying to highlight both elements and exact matches inside them, as per @aadcg's suggestion. Can you try this on some familiar pages searching for something and evaluate whether the element-based highlighting is bearable? @jmercouris, @Ambrevar?

I would commit to making exact highlighting possible... but we all know that once a feature is merged, it's increasingly less probable that incomplete yet merged parts of the feature would ever be completed :P

aartaka avatar Jul 25 '22 13:07 aartaka

Oh, I found one more problem: unescaped unicode characters as parts of CSS selectors break CLSS, but there are no means in CLSS to read escaped characters either :thinking:

aartaka avatar Jul 25 '22 13:07 aartaka

The CSS escaping problem solved on the CLSS side now, Lispy search is fully functional. The last thing I'd add is listing the exact matching snippet in the prompt-buffer so that it's clearer from the prompt-buffer alone what the context of the word is.

aartaka avatar Jul 28 '22 10:07 aartaka

Text truncation to show the match in the prompt-buffer is there. Will be glad if anyone tests and expresses their opinion on how usable the element-level highlighting is!

aartaka avatar Jul 28 '22 14:07 aartaka

@Ambrevar's feedback: element-level highlighting is not enough, as one sometimes looks for the paragraph with the biggest word concentration, and not the context of word appearance -- context comes after.

aartaka avatar Jul 29 '22 13:07 aartaka

My first comment is that I ran into some compilation errors while (asdf:load-system :nyxt/gtk-application) on this branch. For example:

; caught ERROR:
;   READ error during COMPILE-FILE:
;   
;     The symbol "UI-DISPLAY" is not external in the NDEBUG package.
;   
;       Line: 27, Column: 28, File-Position: 868

aadcg avatar Aug 01 '22 08:08 aadcg

The issue reported above was my fault. I had to pull the latest ndebug.

aadcg avatar Aug 01 '22 11:08 aadcg

There seem to be issues with prompter:object-attributes from search-buffer. Recipe: go to potato on wikipedia, and search for potato. @aartaka, could you take a look?

I agree with @Ambrevar that context isn't enough.

I am demotivated trying to highlight both elements and exact matches inside them

Are you're saying you're tired of working on this, and you'd like me to jump in?

aadcg avatar Aug 01 '22 11:08 aadcg

There seem to be issues with prompter:object-attributes from search-buffer. Recipe: go to potato on wikipedia, and search for potato. @aartaka, could you take a look?

Fixed with ea3dfbd72391bc318bb5899fe52e7a61ea41e3a3.

I agree with @Ambrevar that context isn't enough.

I am demotivated trying to highlight both elements and exact matches inside them

Are you're saying you're tired of working on this, and you'd like me to jump in?

I'll be glad if you can try exploring it, yes!

aartaka avatar Aug 01 '22 13:08 aartaka

I'll be taking over this PR.

aadcg avatar Aug 22 '22 07:08 aadcg

@aartaka, could you explain commit 9935a6e6f?

aadcg avatar Aug 30 '22 08:08 aadcg

@aartaka, could you explain commit 9935a6e?

It basically replaces the <mark> node with its first child (which is the meaningful element highlighted by <mark>). Note that this design is already supereded by adding styles to the actual elements to highlight in 54f5aabf76291ebb785382729e5800428fda6bb5.

aartaka avatar Aug 30 '22 08:08 aartaka

Superseded by #2529. Commits by @aartaka preserved in the new PR.

aadcg avatar Aug 30 '22 12:08 aadcg