From 0adc92b07242894ff940acfceb3ee9b33ffb51d7 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 16 Sep 2016 10:32:25 +0200 Subject: [PATCH] Minor cleanup and fixes to spell checking and smart paste --- src/source.cc | 17 ++++++++++++++++- src/source_diff.cc | 2 +- src/source_spellcheck.cc | 21 ++++++++++----------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/source.cc b/src/source.cc index 933f432..25c3199 100644 --- a/src/source.cc +++ b/src/source.cc @@ -744,7 +744,22 @@ void Source::View::paste() { text.replace(c, 1, "\n"); } } - + + //Exception for when pasted text is only whitespaces + bool only_whitespaces=true; + for(auto &chr: text) { + if(chr!='\n' && chr!='\r' && chr!=' ' && chr!='\t') { + only_whitespaces=false; + break; + } + } + if(only_whitespaces) { + Gtk::Clipboard::get()->set_text(text); + get_buffer()->paste_clipboard(Gtk::Clipboard::get()); + scroll_to_cursor_delayed(this, false, false); + return; + } + get_buffer()->begin_user_action(); if(get_buffer()->get_has_selection()) { Gtk::TextIter start, end; diff --git a/src/source_diff.cc b/src/source_diff.cc index adf7078..4a88852 100644 --- a/src/source_diff.cc +++ b/src/source_diff.cc @@ -229,7 +229,7 @@ void Source::DiffView::configure() { status_branch=repository->get_branch(); dispatcher.post([this] { if(update_status_branch) - update_status_branch(this); + update_status_branch(this); }); } catch(const std::exception &) { diff --git a/src/source_spellcheck.cc b/src/source_spellcheck.cc index c4f087e..278f81c 100644 --- a/src/source_spellcheck.cc +++ b/src/source_spellcheck.cc @@ -65,7 +65,7 @@ Source::SpellCheckView::SpellCheckView() : Gsv::View() { else { auto previous_iter=iter; //When for instance using space to split two words - if(previous_iter.backward_char() && !is_word_iter(previous_iter)) { + if(previous_iter.backward_char() && (*previous_iter==' ' || *previous_iter=='-')) { auto first=previous_iter; auto second=iter; if(first.backward_char()) { @@ -129,21 +129,20 @@ Source::SpellCheckView::SpellCheckView() : Gsv::View() { }); // In case of for instance text paste or undo/redo - get_buffer()->signal_insert().connect([this](const Gtk::TextIter &end_iter, const Glib::ustring &inserted_string, int) { + get_buffer()->signal_insert().connect([this](const Gtk::TextIter &start_iter, const Glib::ustring &inserted_string, int) { if(spellcheck_checker==nullptr) return; if(inserted_string.size()<=1) return; - auto start_iter=end_iter; - start_iter.backward_chars(inserted_string.size()); - if(!is_word_iter(start_iter) && !start_iter.starts_line()) - start_iter.backward_char(); - auto word=get_word(start_iter); - start_iter=word.first; - word=get_word(end_iter); - get_buffer()->remove_tag(spellcheck_error_tag, start_iter, word.second); - }); + auto iter=start_iter; + if(!is_word_iter(iter) && !iter.starts_line()) + iter.backward_char(); + if(is_word_iter(iter)) { + auto word=get_word(iter); + get_buffer()->remove_tag(spellcheck_error_tag, word.first, word.second); + } + }, false); get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iter, const Glib::RefPtr& mark) { if(spellcheck_checker==nullptr)