Set buffer filename if it has none and it is written with an explicit filename
This commit is contained in:
parent
8d158e4ed9
commit
d93953a929
@ -487,3 +487,8 @@ EncodedString Buffer::get_string()
|
||||
m_gap_buffer->compact();
|
||||
return EncodedString(m_gap_buffer->address(0u), m_gap_buffer->size(), m_encoding);
|
||||
}
|
||||
|
||||
void Buffer::set_filename(const std::string & filename)
|
||||
{
|
||||
m_filename = std::make_shared<std::string>(filename);
|
||||
}
|
||||
|
@ -183,6 +183,7 @@ public:
|
||||
void erase_code_point(const Buffer::Iterator & position);
|
||||
void erase_range(const Buffer::Range & range);
|
||||
std::shared_ptr<std::string> filename() const { return m_filename; }
|
||||
void set_filename(const std::string & filename);
|
||||
Iterator begin() const { return Iterator(this); }
|
||||
std::shared_ptr<Iterator> beginp() const { return std::make_shared<Iterator>(this); }
|
||||
Iterator end() const { return *m_eof_iterator; }
|
||||
|
@ -551,15 +551,19 @@ void Window::handle_command(const EncodedString & command)
|
||||
|
||||
void Window::command_write_file(const CommandParser & cp)
|
||||
{
|
||||
std::shared_ptr<Buffer> buffer = m_focused_buffer_pane->buffer();
|
||||
std::string path;
|
||||
std::shared_ptr<Buffer> buffer = m_focused_buffer_pane->buffer();
|
||||
auto filename = buffer->filename();
|
||||
if (cp.size() >= 2)
|
||||
{
|
||||
path = cp[1].to_string();
|
||||
if (!filename)
|
||||
{
|
||||
buffer->set_filename(path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto filename = buffer->filename();
|
||||
if (filename)
|
||||
{
|
||||
path = *filename;
|
||||
|
Loading…
x
Reference in New Issue
Block a user