From 7d420669e6d13b384542e07b93ab14fdef4a1e3e Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Thu, 16 Jul 2015 21:26:41 +0200 Subject: [PATCH] #9496 factor out getting language from LFUN args or cursor position in speller LFUNs --- src/Text3.cpp | 38 +++++++++++++++----------------------- src/WordLangTuple.h | 4 ++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index 47a91b5936..8867e10826 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -486,6 +486,15 @@ bool Text::isRTL(Paragraph const & par) const return par.isRTL(buffer.params()); } + +namespace { + + Language const * getLanguage(Cursor const & cur, string const & lang) { + return lang.empty() ? cur.getFont().language() : languages.getLanguage(lang); + } + +} + void Text::dispatch(Cursor & cur, FuncRequest & cmd) { @@ -2343,8 +2352,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) } case LFUN_SPELLING_ADD: { + Language const * language = getLanguage(cur, cmd.getArg(1)); docstring word = from_utf8(cmd.getArg(0)); - Language * lang; if (word.empty()) { word = cur.selectionAsString(false); // FIXME @@ -2353,22 +2362,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) selectWordWhenUnderCursor(cur, WHOLE_WORD); word = cur.selectionAsString(false); } - lang = const_cast(cur.getFont().language()); - } else if (cmd.getArg(1).empty()) { - // optional language argument is missing - // use the language at cursor position - lang = const_cast(cur.getFont().language()); - } else { - lang = const_cast(languages.getLanguage(cmd.getArg(1))); } - WordLangTuple wl(word, lang); + WordLangTuple wl(word, language); theSpellChecker()->insert(wl); break; } case LFUN_SPELLING_IGNORE: { + Language const * language = getLanguage(cur, cmd.getArg(1)); docstring word = from_utf8(cmd.getArg(0)); - Language * lang; if (word.empty()) { word = cur.selectionAsString(false); // FIXME @@ -2377,20 +2379,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) selectWordWhenUnderCursor(cur, WHOLE_WORD); word = cur.selectionAsString(false); } - lang = const_cast(cur.getFont().language()); - } else if (cmd.getArg(1).empty()) { - lang = const_cast(cur.getFont().language()); - } else { - lang = const_cast(languages.getLanguage(cmd.getArg(1))); } - WordLangTuple wl(word, lang); + WordLangTuple wl(word, language); theSpellChecker()->accept(wl); break; } case LFUN_SPELLING_REMOVE: { + Language const * language = getLanguage(cur, cmd.getArg(1)); docstring word = from_utf8(cmd.getArg(0)); - Language * lang; if (word.empty()) { word = cur.selectionAsString(false); // FIXME @@ -2399,13 +2396,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) selectWordWhenUnderCursor(cur, WHOLE_WORD); word = cur.selectionAsString(false); } - lang = const_cast(cur.getFont().language()); - } else if (cmd.getArg(1).empty()) { - lang = const_cast(cur.getFont().language()); - } else { - lang = const_cast(languages.getLanguage(cmd.getArg(1))); } - WordLangTuple wl(word, lang); + WordLangTuple wl(word, language); theSpellChecker()->remove(wl); break; } diff --git a/src/WordLangTuple.h b/src/WordLangTuple.h index 0e3391e296..baf9338578 100644 --- a/src/WordLangTuple.h +++ b/src/WordLangTuple.h @@ -29,7 +29,7 @@ class WordLangTuple { public: WordLangTuple() : lang_(0) {} - WordLangTuple(docstring const & w, Language * l) + WordLangTuple(docstring const & w, Language const * l) : word_(w), lang_(l) {} @@ -47,7 +47,7 @@ private: /// the word docstring word_; /// language of word - Language * lang_; + Language const * lang_; };