Skip to content
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

add sidebar search #3913

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

add sidebar search #3913

wants to merge 3 commits into from

Conversation

lucilanga
Copy link
Contributor

  • What does this PR do?

As title states it will add search option for sidebar mailboxes

A couple of comments here:

Right of the bat I had to drag sidebar/private.h into enter/window.c. I know this is bad, but being new at this I don't know how to properly lookup sidebar window to pass it to the sb_function_diapatcher(). I've tried several ways to look for it, but with no success, so I dropped the include, passed d->win to the function and called it done.

I had a miserable time adding SidebarDefaultBindings, not because the API wasn't clear or so but because of several
(mtype != MENU_EDITOR) like instances in the code that prevented it from working - we really should get rid of those, I had to put mtype == or mtype != MENU_SIDEBAR in five places, I'm not even sure every instance is required.

search operation is called OP_SIDEBAR_START_SEARCH as in the matcher, I figured out I keep this name because I might later do the search/limit thing that I initially wanted, so keep the namespace open for OP_SIDEBAR_SEARCH OP_SIDEBAR_LIMIT.

I've cheated on the MENU_SIDEBAR ops, I do handle OP_EDITOR_BACKSPACE on MENU_SIDEBAR only to pass it to the enter_function_dispatcher(). The only thing I need there is the callback support for delete buffer operation so I didn't feel like doing editor_backspace code all over again in the sidebar. Perhaps I should put a comment there before anyone thinks that's a typo.

@lucilanga lucilanga requested a review from a team as a code owner July 2, 2023 22:20
sidebar/functions.c Fixed Show fixed Hide fixed
sidebar/functions.c Fixed Show fixed Hide fixed
enter/window.c Fixed Show fixed Hide fixed
sidebar/functions.c Fixed Show fixed Hide fixed
@flatcap flatcap added the type:enhancement Feature Request label Jul 2, 2023
@flatcap flatcap marked this pull request as draft July 2, 2023 22:43
Copy link
Member

@flatcap flatcap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

I've pushed a few fixes, 7a46b60, so that all the automated tests build and run correctly.

The only significant change was to pass the Sidebar's Window to the callback, rather than its Private Data.
This means we avoid a big dependency problem.

I'll have a closer look through the code in the morning.

@flatcap
Copy link
Member

flatcap commented Jul 4, 2023

I've had a good look at the PR and I see the problem (with the existing code).

The code that reads the keyboard is also doing the lookup from, say, d to OP_DELETE.
That sort of logic should be done at a much higher level -- something I've considered before, but not got around to.

The rough idea, for the Index, would be:

  • mutt_getch() returns <Ctrl-O>
  • Try: index_function_dispatcher()
    • Lookup <Ctrl-O> -- No Match
  • Try: sidebar_function_dispacher()
    • Lookup <Ctrl-O> -- Match: OP_SIDEBAR_OPEN, op_sidebar_open()
    • Execute function
  • Repeat

I'm still investigating how much work it is to fix properly; I'll post my findings when I'm done.

@flatcap
Copy link
Member

flatcap commented Jul 4, 2023

Years ago, I created some diagrams in the gfx repo.
Diagrams 1 and 5 show some of my ideas about the "current" and the "ideal" behaviour.

@flatcap
Copy link
Member

flatcap commented Jul 5, 2023

#3916 - What I understand about key bindings.
I need to kill some of the business logic in km_dokey_event(), possibly starting with the lookup:

struct Keymap *map = STAILQ_FIRST(&Keymaps[mtype]);

@lucilanga
Copy link
Contributor Author

lucilanga commented Jul 6, 2023

So I've been working on the paging thing I've mentioned earlier in the bug report.
As we type in the pattern, the overlay gets sorter but paging/framing remains the same.
and it messes UP/DOWN scrolling.

It seems I cannot use top_index or bot_index because sb_recalc() rewrites them anyway.
So what I could do instead is add a new flag on SidebarWindowData to ask sb_recalc() to scan for the whole framing interval. We do exactly the same thing if sidebar_new_mail_only or sidebar_non_empty_mailbox variables are set.

I suppose I could do a separate recalc() function just for the overlay. We might need something similar in the future, if we decide to do more this quick/overlay stuff.
But I think an overlay recalc would be overlay overkill :) so obviously I prefer the former for now.

@flatcap
Copy link
Member

flatcap commented Jul 7, 2023

As we type in the pattern, the overlay gets shorter but paging/framing remains
the same. and it messes UP/DOWN scrolling.

When I refactored the Menu code, I drew a diagram.
A long list of items with a view (window) superimposed.

I listed all the possible start conditions, from an empty list, to overflowing the view at both ends.

Next, I listed all the possible actions that could be performed on each of the lists and what I'd like the perfect result to be.
For the Menu there were ops that moved the selection and ops that moved the view.

I cannot use top_index or bot_index because sb_recalc() rewrites them
I could do instead is add a new flag on SidebarWindowData ...

OK
It may be more work to refactor the code, but I'm confident the result will be much simpler.

I think an overlay recalc would be overlay overkill :)
so obviously I prefer the former for now.

OK. I'm always around on IRC if you want to discuss ideas.

@flatcap
Copy link
Member

flatcap commented Jul 7, 2023

Meanwhile, I'm still investigating how buf_get_field() and km_dokey_event() interact.

km_dokey_event() has a lot of business logic that we don't need.
Most callers need to fall back to the Generic menu (retry_generic()).
Some of that macro code can probably go and all that Imap **** needs factoring out.

I'll probably end up with a parallel buf_get_field2() and km_dokey_event2().

@flatcap
Copy link
Member

flatcap commented Jul 8, 2023

I've been doing some renaming to the NeoMutt code.
I've rebased your commits over main and squashed my previous fixes into your commit.

The only change that affects you, is that I've renamed buf_get_field() to mw_get_field().
The interactive functions that use the Message Window are now prefixed with mw_.

@lucilanga
Copy link
Contributor Author

.. and dlg_change_folder() now index_change_folder() . And yes, I've seen your commits and I do like the changes!

@lucilanga
Copy link
Contributor Author

When I refactored the Menu code, I drew a diagram. A long list of items with a view (window) superimposed.

it didn't make it in the gfx repo, did it ?
I've tried searching bug reports but I'm terrible at finding things on GH.

I'll probably end up with a parallel buf_get_field2() and km_dokey_event2().

Perhaps you would like me to look into this. I know my 1000+ commits on main :) do not qualify. But I feel somehow
responsible for triggering this. I know it has been on your plate for some time but I'm the idiot who brought it up :)
Maybe I can take off some grunt work from you on this.

@flatcap
Copy link
Member

flatcap commented Jul 8, 2023

I drew a diagram

it didn't make it in the gfx repo, did it ?

Sorry, I think it may only have been on paper.

I'll probably end up with a parallel buf_get_field2() and km_dokey_event2().

Perhaps you would like me to look into this.
Maybe I can take off some grunt work from you on this.

Yes, PLEASE ❤️

I'm a programmer, not a manager, so I have a hard time delegating coding :-)


Some final thoughts...

Each Dialog has set of mappings that are stored in Keymaps[MENU_X].
Most Dialogs also fallback to Keymaps[MENU_GENERIC].

If we can pass multiple Keymap arrays into km_dokey_event(), then we can eliminate some of the logic (and retry_generic()).

The other MENU_EDITOR logic is to hide timeouts.
It's convenient, but we can probably move that out to mw_get_field()

@flatcap
Copy link
Member

flatcap commented Jul 30, 2023

Rebased over main

struct EnterWindowData wdata = { buf, 0, es, 0, NULL, NULL, prompt, ENTER_REDRAW_NONE, MUTT_COMP_NO_FLAGS, true, NULL, 0, &mbstate, 0, false, NULL, 0, 0 };
// clang-format on

win->wdata = &wdata;

Check warning

Code scanning / CodeQL

Local variable address stored in non-local memory Warning

A stack address (
source
) may be assigned to a non-local variable.
@flatcap flatcap force-pushed the devel/sidebar-search branch 2 times, most recently from f6b442a to 8cc65aa Compare October 29, 2023 16:23
@flatcap flatcap force-pushed the devel/sidebar-search branch 2 times, most recently from 6813d3a to 2e3bb35 Compare November 16, 2023 19:42
@flatcap flatcap force-pushed the devel/sidebar-search branch 3 times, most recently from daf191b to 7076f2f Compare March 29, 2024 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants