From 756bd0a69cdc7218e9fb0ce41cf8f714f740ff01 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sat, 5 Sep 2015 18:41:05 +0200 Subject: [PATCH] Fixed a bug in find_tab_char_and_size(). --- src/source.cc | 52 +++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/source.cc b/src/source.cc index c6b50c7..e0c8b04 100644 --- a/src/source.cc +++ b/src/source.cc @@ -703,7 +703,7 @@ bool Source::View::on_button_press_event(GdkEventButton *event) { } std::pair Source::View::find_tab_char_and_size() { - const std::regex indent_regex("^([ \t]+).*$"); + const std::regex indent_regex("^([ \t]+)(.*)$"); auto size=get_buffer()->get_line_count(); std::unordered_map tab_chars; std::unordered_map tab_sizes; @@ -711,28 +711,36 @@ std::pair Source::View::find_tab_char_and_size() { for(int c=0;c(str.size()-last_tab_size)); - if(tab_diff>0) { - unsigned tab_diff_unsigned=static_cast(tab_diff); - auto it_size=tab_sizes.find(tab_diff_unsigned); - if(it_size!=tab_sizes.end()) - it_size->second++; - else - tab_sizes[tab_diff_unsigned]=1; - } - - last_tab_size=str.size(); - - if(str.size()>0) { - auto it_char=tab_chars.find(str[0]); - if(it_char!=tab_chars.end()) - it_char->second++; - else - tab_chars[str[0]]=1; - } + if(sm[2].str().size()==0) + continue; + str=sm[1].str(); + } + else { + str=""; + if(line.size()==0) + continue; + } + + long tab_diff=abs(static_cast(str.size()-last_tab_size)); + if(tab_diff>0) { + unsigned tab_diff_unsigned=static_cast(tab_diff); + auto it_size=tab_sizes.find(tab_diff_unsigned); + if(it_size!=tab_sizes.end()) + it_size->second++; + else + tab_sizes[tab_diff_unsigned]=1; + } + + last_tab_size=str.size(); + + if(str.size()>0) { + auto it_char=tab_chars.find(str[0]); + if(it_char!=tab_chars.end()) + it_char->second++; + else + tab_chars[str[0]]=1; } } char found_tab_char=0;