Skip to content

Commit

Permalink
ui: add select-last-message option
Browse files Browse the repository at this point in the history
Add a [ui].select-last-message option to position the cursor at the
bottom of the message list view.

Fixes: https://todo.sr.ht/~rjarry/aerc/254
Changelog-added: Add `[ui].select-last-message` option to position
 cursor at the bottom of the view.
Suggested-by: Bence Ferdinandy <[email protected]>
Requested-by: Tomasz Kramkowski <[email protected]>
Signed-off-by: Koni Marti <[email protected]>
Tested-by: Tomasz Kramkowski <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
konimarti authored and rjarry committed May 28, 2024
1 parent 9f97c69 commit 2276a79
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (acct *AccountView) newStore(name string) *lib.MessageStore {
uiConf.ThreadingEnabled,
uiConf.ForceClientThreads,
uiConf.ClientThreadsDelay,
uiConf.SelectLast,
uiConf.ReverseOrder,
uiConf.ReverseThreadOrder,
uiConf.SortThreadSiblings,
Expand Down
6 changes: 6 additions & 0 deletions config/aerc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@
# Default: false
#reverse-thread-order=false

# Positions the cursor on the last message in the message list (at the
# bottom of the view) when opening a new folder.
#
# Default: false
#select-last-message=false

# Sort the thread siblings according to the sort criteria for the messages. If
# sort-thread-siblings is false, the thread siblings will be sorted based on
# the message UID in ascending order. This option is only applicable for
Expand Down
1 change: 1 addition & 0 deletions config/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type UIConfig struct {
BorderCharVertical rune `ini:"border-char-vertical" default:"│" type:"rune"`
BorderCharHorizontal rune `ini:"border-char-horizontal" default:"─" type:"rune"`

SelectLast bool `ini:"select-last-message" default:"false"`
ReverseOrder bool `ini:"reverse-msglist-order"`
ReverseThreadOrder bool `ini:"reverse-thread-order"`
SortThreadSiblings bool `ini:"sort-thread-siblings"`
Expand Down
6 changes: 6 additions & 0 deletions doc/aerc-config.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ These options are configured in the *[ui]* section of _aerc.conf_.

Default: _false_

*select-last-message* = _true_|_false_
Positions the cursor on the last message in the message list (at the
bottom of the view) when opening a new folder.

Default: _false_

*sort-thread-siblings* = _true_|_false_
Sort the thread siblings according to the sort criteria for the messages. If
sort-thread-siblings is false, the thread siblings will be sorted based on
Expand Down
9 changes: 8 additions & 1 deletion lib/msgstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type MessageStore struct {
sortDefault []*types.SortCriterion

threadedView bool
selectLast bool
reverseThreadOrder bool
threadContext bool
sortThreadSiblings bool
Expand Down Expand Up @@ -89,6 +90,7 @@ const MagicUid = 0xFFFFFFFF
func NewMessageStore(worker *types.Worker,
defaultSortCriteria []*types.SortCriterion,
thread bool, clientThreads bool, clientThreadsDelay time.Duration,
selectLast bool,
reverseOrder bool, reverseThreadOrder bool, sortThreadSiblings bool,
triggerNewEmail func(*models.MessageInfo),
triggerDirectoryChange func(), triggerMailDeleted func(),
Expand Down Expand Up @@ -116,6 +118,7 @@ func NewMessageStore(worker *types.Worker,
threadedView: thread,
buildThreads: clientThreads,
threadContext: threadContext,
selectLast: selectLast,
reverseThreadOrder: reverseThreadOrder,
sortThreadSiblings: sortThreadSiblings,

Expand Down Expand Up @@ -745,7 +748,11 @@ func (store *MessageStore) Selected() *models.MessageInfo {
func (store *MessageStore) SelectedUid() uint32 {
if store.selectedUid == MagicUid && len(store.Uids()) > 0 {
iter := store.UidsIterator()
store.Select(store.Uids()[iter.StartIndex()])
idx := iter.StartIndex()
if store.selectLast {
idx = iter.EndIndex()
}
store.Select(store.Uids()[idx])
}
return store.selectedUid
}
Expand Down

0 comments on commit 2276a79

Please sign in to comment.