|
|
|
@ -137,17 +137,17 @@ void Source::View::paste() { |
|
|
|
const std::regex spaces_regex(std::string("^(")+Singleton::Config::source()->tab_char+"*)(.*)$"); |
|
|
|
const std::regex spaces_regex(std::string("^(")+Singleton::Config::source()->tab_char+"*)(.*)$"); |
|
|
|
auto line=get_line_before_insert(); |
|
|
|
auto line=get_line_before_insert(); |
|
|
|
std::smatch sm; |
|
|
|
std::smatch sm; |
|
|
|
std::string prefix; |
|
|
|
std::string prefix_tabs; |
|
|
|
if(std::regex_match(line, sm, spaces_regex) && sm[2].str().size()==0) { |
|
|
|
if(std::regex_match(line, sm, spaces_regex) && sm[2].str().size()==0) { |
|
|
|
prefix=sm[1].str(); |
|
|
|
prefix_tabs=sm[1].str(); |
|
|
|
|
|
|
|
|
|
|
|
Glib::ustring::size_type start_line=0; |
|
|
|
Glib::ustring::size_type start_line=0; |
|
|
|
Glib::ustring::size_type end_line=0; |
|
|
|
Glib::ustring::size_type end_line=0; |
|
|
|
bool paste_line=false; |
|
|
|
bool paste_line=false; |
|
|
|
bool first_paste_line=true; |
|
|
|
bool first_paste_line=true; |
|
|
|
size_t first_paste_line_tabs=0; |
|
|
|
size_t paste_line_tabs=-1; |
|
|
|
get_source_buffer()->begin_user_action(); |
|
|
|
bool first_paste_line_has_tabs=false; |
|
|
|
for(Glib::ustring::size_type c=0;c<text.size();c++) { |
|
|
|
for(Glib::ustring::size_type c=0;c<text.size();c++) {; |
|
|
|
if(text[c]=='\n') { |
|
|
|
if(text[c]=='\n') { |
|
|
|
end_line=c; |
|
|
|
end_line=c; |
|
|
|
paste_line=true; |
|
|
|
paste_line=true; |
|
|
|
@ -157,36 +157,55 @@ void Source::View::paste() { |
|
|
|
paste_line=true; |
|
|
|
paste_line=true; |
|
|
|
} |
|
|
|
} |
|
|
|
if(paste_line) { |
|
|
|
if(paste_line) { |
|
|
|
if(first_paste_line) { |
|
|
|
|
|
|
|
std::string line=text.substr(start_line, end_line-start_line); |
|
|
|
std::string line=text.substr(start_line, end_line-start_line); |
|
|
|
|
|
|
|
size_t tabs=0; |
|
|
|
for(auto chr: line) { |
|
|
|
for(auto chr: line) { |
|
|
|
if(chr==Singleton::Config::source()->tab_char) |
|
|
|
if(chr==Singleton::Config::source()->tab_char) |
|
|
|
first_paste_line_tabs++; |
|
|
|
tabs++; |
|
|
|
else |
|
|
|
else |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
get_buffer()->insert_at_cursor(text.substr(start_line+first_paste_line_tabs, end_line-start_line-first_paste_line_tabs)); |
|
|
|
if(first_paste_line) { |
|
|
|
|
|
|
|
if(tabs!=0) { |
|
|
|
|
|
|
|
first_paste_line_has_tabs=true; |
|
|
|
|
|
|
|
paste_line_tabs=tabs; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
first_paste_line=false; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
std::string line=text.substr(start_line, end_line-start_line); |
|
|
|
|
|
|
|
size_t paste_line_tabs=0; |
|
|
|
|
|
|
|
for(auto chr: line) { |
|
|
|
|
|
|
|
if(chr==Singleton::Config::source()->tab_char) |
|
|
|
|
|
|
|
paste_line_tabs++; |
|
|
|
|
|
|
|
else |
|
|
|
else |
|
|
|
break; |
|
|
|
paste_line_tabs=std::min(paste_line_tabs, tabs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start_line=end_line+1; |
|
|
|
|
|
|
|
paste_line=false; |
|
|
|
} |
|
|
|
} |
|
|
|
if(paste_line_tabs>=first_paste_line_tabs) |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor("\n"+prefix+text.substr(start_line+first_paste_line_tabs, end_line-start_line-first_paste_line_tabs)); |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
size_t tabs=0; |
|
|
|
|
|
|
|
if(prefix.size()>(first_paste_line_tabs-paste_line_tabs)) |
|
|
|
|
|
|
|
tabs=prefix.size()-(first_paste_line_tabs-paste_line_tabs); |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor("\n"+prefix.substr(0, tabs)+text.substr(start_line+paste_line_tabs, end_line-start_line-paste_line_tabs)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(paste_line_tabs==(size_t)-1) |
|
|
|
|
|
|
|
paste_line_tabs=0; |
|
|
|
|
|
|
|
start_line=0; |
|
|
|
|
|
|
|
end_line=0; |
|
|
|
|
|
|
|
paste_line=false; |
|
|
|
|
|
|
|
first_paste_line=true; |
|
|
|
|
|
|
|
get_source_buffer()->begin_user_action(); |
|
|
|
|
|
|
|
for(Glib::ustring::size_type c=0;c<text.size();c++) { |
|
|
|
|
|
|
|
if(text[c]=='\n') { |
|
|
|
|
|
|
|
end_line=c; |
|
|
|
|
|
|
|
paste_line=true; |
|
|
|
} |
|
|
|
} |
|
|
|
start_line=end_line+1; |
|
|
|
else if(c==text.size()-1) { |
|
|
|
|
|
|
|
end_line=c+1; |
|
|
|
|
|
|
|
paste_line=true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(paste_line) { |
|
|
|
|
|
|
|
if(first_paste_line) { |
|
|
|
|
|
|
|
if(first_paste_line_has_tabs) |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor(text.substr(start_line+paste_line_tabs, end_line-start_line-paste_line_tabs)); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor(text.substr(start_line, end_line-start_line)); |
|
|
|
first_paste_line=false; |
|
|
|
first_paste_line=false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor('\n'+prefix_tabs+text.substr(start_line+paste_line_tabs, end_line-start_line-paste_line_tabs)); |
|
|
|
|
|
|
|
start_line=end_line+1; |
|
|
|
paste_line=false; |
|
|
|
paste_line=false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|