From c4097eefbd742482360d5e6bcc0652cc81878f40 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 2 Oct 2015 19:07:05 +0200 Subject: [PATCH 1/2] More effective tag_similar_tokens. Especially when sourcemap is turned on (might be an OS X issue only though).. --- src/source.cc | 19 ++++++++++++++++--- src/source.h | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/source.cc b/src/source.cc index 5233984..1115c3d 100644 --- a/src/source.cc +++ b/src/source.cc @@ -2216,16 +2216,29 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { void Source::ClangViewRefactor::tag_similar_tokens(const Token &token) { if(source_readable) { if(token && last_tagged_token!=token) { - get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); + for(auto &mark: similar_token_marks) { + get_buffer()->remove_tag(similar_tokens_tag, mark.first->get_iter(), mark.second->get_iter()); + get_buffer()->delete_mark(mark.first); + get_buffer()->delete_mark(mark.second); + } + similar_token_marks.clear(); auto offsets=clang_tokens->get_similar_token_offsets(static_cast(token.type), token.spelling, token.usr); for(auto &offset: offsets) { - get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1), get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1)); + auto start_iter=get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1); + auto end_iter=get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1); + get_buffer()->apply_tag(similar_tokens_tag, start_iter, end_iter); + similar_token_marks.emplace_back(get_buffer()->create_mark(start_iter), get_buffer()->create_mark(end_iter)); } last_tagged_token=token; } } if(!token && last_tagged_token) { - get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); + for(auto &mark: similar_token_marks) { + get_buffer()->remove_tag(similar_tokens_tag, mark.first->get_iter(), mark.second->get_iter()); + get_buffer()->delete_mark(mark.first); + get_buffer()->delete_mark(mark.second); + } + similar_token_marks.clear(); last_tagged_token=Token(); } } diff --git a/src/source.h b/src/source.h index 88c3735..4cb7ece 100644 --- a/src/source.h +++ b/src/source.h @@ -257,6 +257,7 @@ namespace Source { ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language); ~ClangViewRefactor(); private: + std::list, Glib::RefPtr > > similar_token_marks; void tag_similar_tokens(const Token &token); Glib::RefPtr similar_tokens_tag; Token last_tagged_token; From 634a1161844d1dcd54b605d439275bb14e599ee6 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 2 Oct 2015 21:09:11 +0200 Subject: [PATCH 2/2] Now compiles on Ubuntu 14. --- src/source.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source.cc b/src/source.cc index 1115c3d..b5efc4a 100644 --- a/src/source.cc +++ b/src/source.cc @@ -2077,7 +2077,7 @@ bool Source::ClangViewAutocomplete::restart_parse() { Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language): Source::ClangViewAutocomplete(file_path, project_path, language) { similar_tokens_tag=get_buffer()->create_tag(); - similar_tokens_tag->property_weight()=Pango::WEIGHT_ULTRAHEAVY; + similar_tokens_tag->property_weight()=1000; //TODO: replace with Pango::WEIGHT_ULTRAHEAVY in 2016 or so (when Ubuntu 14 is history) get_buffer()->signal_changed().connect([this]() { if(!renaming && last_tagged_token) {