Commit 848ff01f authored by Wesley Wiser's avatar Wesley Wiser

Filter out transient buffers when validating user buffer indexes

parent f03cc01a
......@@ -92,7 +92,7 @@ impl Editor {
if let Some(buffer_command) = try_get_buffer_command(c) {
match buffer_command {
BufferCommand::SwitchToBuffer(n) => {
if n >= self.buffers.len() {
if !self.buffers.is_buffer_index_valid(n) {
self.status_bar.msg = format!("Invalid buffer #{}", n);
} else {
self.buffers.switch_to(n);
......
......@@ -142,6 +142,11 @@ impl BufferManager {
self.current_buffer_index -= 1;
}
}
/// Validates that the specifed buffer index is valid
pub fn is_buffer_index_valid(&self, n: usize) -> bool {
n < self.buffers.iter().filter(|b| !b.is_transient).count()
}
}
/// The current state of the editor, including the file, the cursor, the scrolling info, etc.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment