Skip to content

Commit

Permalink
fix(sidebar): use abbreviated path if possible (#2304)
Browse files Browse the repository at this point in the history
* fix(sidebar): use abbreviated path if possible

After the refactor in commit d77c704,
the sidebar only displays a mailbox's full path/URI except in the case
of 'sidebar_short_path'. The full path/URI is not preferable for end
users.

What broke during the refactor is how the variable 'display' is updated.
It's initialized to a mailbox's full path/URI and only updated if using
'sidebar_short_path'. However, after initialization, an abbreviation is
calculated to remove the 'folder' or protocol.

To resolve this issue, if there's an abbreviation, store it in the
'display' variable.

Fixes #2293

* fix(sidebar): don't indent full mailbox paths

If the sidebar is displaying a full mailbox path while using
'sidebar_short_path=yes', it will indent the entry based on the number
of delimiters in the path. Since '/' is a default delimiter, there is
significant indentation for local folders.

To resolve this, if the sidebar displays the full path, ignore the
'sidebar_short_path' for that entry. While full paths aren't
particularly user friendly, indented full paths are worse.

* fix(sidebar): record abbr state before short path

Record if there's been an abbreviation before updating 'display' with
the shortpath. Otherwise, we'll lose track of if we had one, which is
crucial to indentation. Indentation shouldn't happen on a full path
mailbox, even if it's only showing the last part.
  • Loading branch information
Austin-Ray committed May 1, 2020
1 parent 43e328d commit f073a70
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions sidebar.c
Expand Up @@ -1091,25 +1091,37 @@ static void draw_sidebar(struct MuttWindow *win, int num_rows, int num_cols, int
m->msg_flagged = Context->mailbox->msg_flagged;
}

const char *full_path = mailbox_path(m);
display = m->name;
if (!display)
display = mailbox_path(m);
display = full_path;

const char *abbr = m->name;
if (!abbr)
abbr = abbrev_folder(display, C_Folder, m->type);
if (!abbr)
abbr = abbrev_url(display, m->type);

// Use the abbreviation if we have one. The full path is not preferable.
if (abbr)
display = abbr;

const char *last_part = abbr;
int depth = calc_path_depth(abbr, C_SidebarDelimChars, &last_part);

// At this point, we don't have an abbreviation so let's keep track
// before using short path.
bool no_abbr = mutt_str_strncmp(display, full_path, sizeof(display));
if (C_SidebarShortPath)
{
display = last_part;
}

mutt_buffer_reset(&result);

if (C_SidebarFolderIndent)
// Don't indent if we were unable to create an abbreviation.
// Otherwise, the full path will be indent, and it looks unusual.
if (C_SidebarFolderIndent && no_abbr)
{
if (C_SidebarComponentDepth > 0)
depth -= C_SidebarComponentDepth;
Expand Down

0 comments on commit f073a70

Please sign in to comment.