Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit c265ead

Browse files
committed
fix prepend on current index, also format
1 parent 71e6d86 commit c265ead

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/notebook.cc

+24-22
Original file line numberDiff line numberDiff line change
@@ -194,41 +194,43 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
194194
status_branch.set_text("");
195195
}
196196
};
197-
source_views.back()->update_tab_label=[this](Source::View *view) {
198-
const auto update_label = [&](size_t index, const std::string &prepend){
197+
source_views.back()->update_tab_label = [this](Source::View *view) {
198+
const auto update_label = [&](size_t index, const std::string &prepend) {
199199
const auto current_view = source_views[index];
200-
auto title = prepend+current_view->file_path.filename().string();
201-
if(current_view->get_buffer()->get_modified())
202-
title+='*';
200+
auto title = prepend + current_view->file_path.filename().string();
201+
if (current_view->get_buffer()->get_modified())
202+
title += '*';
203203
else
204-
title+=' ';
205-
auto &tab_label=tab_labels.at(index);
204+
title += ' ';
205+
auto &tab_label = tab_labels.at(index);
206206
tab_label->label.set_text(title);
207207
tab_label->set_tooltip_text(filesystem::get_short_path(current_view->file_path).string());
208208
};
209-
const auto file_name=view->file_path.filename();
209+
const auto file_name = view->file_path.filename();
210210
std::string prepend_current_view;
211-
for(size_t c=0;c<size();++c) {
212-
if(source_views[c]==view) {
213-
update_label(c, prepend_current_view);
211+
size_t current_view_index = 0;
212+
for (size_t c = 0; c < size(); ++c) {
213+
if (source_views[c] == view) {
214+
current_view_index = c;
214215
continue;
215216
}
216217
if (source_views[c]->file_path.filename() == file_name) {
217-
int diff=0;
218-
const auto parent_path1=view->file_path.parent_path();
219-
const auto parent_path2=source_views[c]->file_path.parent_path();
220-
auto it1=parent_path1.rbegin();
221-
auto it2=parent_path2.rbegin();
218+
int diff = 0;
219+
const auto parent_path1 = view->file_path.parent_path();
220+
const auto parent_path2 = source_views[c]->file_path.parent_path();
221+
auto it1 = parent_path1.rbegin();
222+
auto it2 = parent_path2.rbegin();
222223
while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) {
223-
++it1;
224-
++it2;
225-
++diff;
224+
++it1;
225+
++it2;
226+
++diff;
226227
}
227-
if(prepend_current_view.empty())
228-
prepend_current_view=it1->string()+(diff>0?"/.../":"/");
229-
update_label(c, it2->string()+(diff>0?"/.../":"/"));
228+
if (prepend_current_view.empty())
229+
prepend_current_view = it1->string() + (diff > 0 ? "/.../" : "/");
230+
update_label(c, it2->string() + (diff > 0 ? "/.../" : "/"));
230231
}
231232
}
233+
update_label(current_view_index, prepend_current_view);
232234
update_status(view);
233235
};
234236
source_views.back()->update_status_diagnostics=[this](Source::View* view) {

0 commit comments

Comments
 (0)