Provide a mechanism to customize the default message selection#128
Open
laarmen wants to merge 2 commits intoakissinger:masterfrom
Open
Provide a mechanism to customize the default message selection#128laarmen wants to merge 2 commits intoakissinger:masterfrom
laarmen wants to merge 2 commits intoakissinger:masterfrom
Conversation
f0c56bf to
5c70714
Compare
This needs to be done through a callback passed in the constructor, as the thread selection only happens after the model has been refreshed for the first time, which might be way after the creation of the panel itself. A real-life example of a need for this is someone wishing to open threads directly on the first unread message rather than the first search match, see akissinger#125 Note that open_current_thread needs to have its new argument marked as keyword-only as this method is connected to an event that provides positional argument that we just don't care about.
That makes the return value of this method suitable as a default_message
provider, otherwise we'd have an invalid index if a thread doesn't have
any matching unread messages. That would be awkward.
With that, you can now have a custom keybinding such as this:
dodo.keymap.search_keymap['Q'] = ('open unread', lambda p: p.open_current_thread(default_message=lambda m: m.next_unread(m.default_message())))
5c70714 to
6b066f2
Compare
Contributor
|
This works fine, with my “select last unread else last read” lambda becoming: and also requiring #129 not to crash. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is my solution for #125. Not as elegant as my first solution to just call next_unread() on the panel once created, but that one had some issues when the thread was entirely unread, plus maybe some race condition somewhere for @klement. I'm wagering this version doesn't have the same issue.
Example binding that this allows:
I played around with it and it has handled anything I've thrown at it without crashing on me nor behaving weirdly.