Cache buffer display name

This commit is contained in:
Maxime Coste 2015-09-01 13:59:40 +01:00
parent ae7dc3c576
commit e9d7d70e47
2 changed files with 10 additions and 9 deletions

View File

@ -20,7 +20,8 @@ namespace Kakoune
Buffer::Buffer(String name, Flags flags, BufferLines lines, Buffer::Buffer(String name, Flags flags, BufferLines lines,
time_t fs_timestamp) time_t fs_timestamp)
: Scope(GlobalScope::instance()), : Scope(GlobalScope::instance()),
m_name(flags & Flags::File ? real_path(parse_filename(name)) : std::move(name)), m_name((flags & Flags::File) ? real_path(parse_filename(name)) : std::move(name)),
m_display_name((flags & Flags::File) ? compact_path(m_name) : m_name),
m_flags(flags | Flags::NoUndo), m_flags(flags | Flags::NoUndo),
m_history(), m_history_cursor(m_history.begin()), m_history(), m_history_cursor(m_history.begin()),
m_last_save_undo_index(0), m_last_save_undo_index(0),
@ -71,22 +72,21 @@ Buffer::~Buffer()
m_values.clear(); m_values.clear();
} }
String Buffer::display_name() const
{
if (m_flags & Flags::File)
return compact_path(m_name);
return m_name;
}
bool Buffer::set_name(String name) bool Buffer::set_name(String name)
{ {
Buffer* other = BufferManager::instance().get_buffer_ifp(name); Buffer* other = BufferManager::instance().get_buffer_ifp(name);
if (other == nullptr or other == this) if (other == nullptr or other == this)
{ {
if (m_flags & Flags::File) if (m_flags & Flags::File)
{
m_name = real_path(name); m_name = real_path(name);
m_display_name = compact_path(m_name);
}
else else
{
m_name = std::move(name); m_name = std::move(name);
m_display_name = m_name;
}
return true; return true;
} }
return false; return false;

View File

@ -139,7 +139,7 @@ public:
ByteCoordAndTarget offset_coord(ByteCoordAndTarget coord, LineCount offset); ByteCoordAndTarget offset_coord(ByteCoordAndTarget coord, LineCount offset);
const String& name() const { return m_name; } const String& name() const { return m_name; }
String display_name() const; const String& display_name() const { return m_display_name; }
// returns true if the buffer is in a different state than // returns true if the buffer is in a different state than
// the last time it was saved // the last time it was saved
@ -199,6 +199,7 @@ private:
LineList m_lines; LineList m_lines;
String m_name; String m_name;
String m_display_name;
Flags m_flags; Flags m_flags;
using UndoGroup = Vector<Modification, MemoryDomain::BufferMeta>; using UndoGroup = Vector<Modification, MemoryDomain::BufferMeta>;