X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText3.cpp;h=22253f27f4b9a184060f96023e41cd8323d0b7d4;hb=472953dbe14b9d0fad8f50e9ca80e114bf30b946;hp=07df90ee16b4f6dfdcf7ddb461cf16c6dfeb8f46;hpb=566b4de5cd4d9ac2d12f3d7b8fa0af8e0f0702da;p=lyx.git diff --git a/src/Text3.cpp b/src/Text3.cpp index 07df90ee16..22253f27f4 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -67,6 +67,7 @@ #include "support/convert.h" #include "support/debug.h" +#include "support/docstring_list.h" #include "support/filetools.h" #include "support/gettext.h" #include "support/lassert.h" @@ -312,6 +313,14 @@ static bool doInsertInset(Cursor & cur, Text * text, } text->insertInset(cur, inset); + InsetText * inset_text = inset->asInsetText(); + if (inset_text) { + Font const & font = inset->inheritFont() + ? cur.bv().textMetrics(text).displayFont(cur.pit(), cur.pos()) + : buffer.params().getFont(); + inset_text->setOuterFont(cur.bv(), font.fontInfo()); + } + if (edit) inset->edit(cur, true); @@ -322,7 +331,6 @@ static bool doInsertInset(Cursor & cur, Text * text, cur.buffer()->errors("Paste"); cur.clearSelection(); // bug 393 cur.finishUndo(); - InsetText * inset_text = inset->asInsetText(); if (inset_text) { inset_text->fixParagraphsFont(); cur.pos() = 0; @@ -2082,15 +2090,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // inside it. doInsertInset(cur, this, cmd, true, true); cur.posForward(); - if (act == LFUN_SCRIPT_INSERT) { - /* Script insets change the font style in metrics(), and - * this is used to compute the height of the caret - * (because the font is stored in TextMetrics::font_). - * When we insert, we have to make sure that metrics are - * computed so that the caret height is wrong. Arguably, - * this is hackish.*/ - bv->processUpdateFlags(Update::SinglePar); - } cur.setCurrentFont(); // Some insets are numbered, others are shown in the outline pane so // let's update the labels and the toc backend. @@ -2477,6 +2476,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; } + case LFUN_FONT_NO_SPELLCHECK: { + Font font(ignore_font, ignore_language); + font.fontInfo().setNoSpellcheck(FONT_TOGGLE); + toggleAndShow(cur, this, font); + break; + } + case LFUN_FONT_SIZE: { Font font(ignore_font, ignore_language); setLyXSize(to_utf8(cmd.argument()), font.fontInfo()); @@ -2673,8 +2679,15 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) docstring arg = cmd.argument(); if (arg.empty()) { arg = cur.selectionAsString(false); - // FIXME + // Too large. We unselect if needed and try to get + // the first word in selection or under cursor if (arg.size() > 100 || arg.empty()) { + if (cur.selection()) { + DocIterator selbeg = cur.selectionBegin(); + cur.clearSelection(); + setCursorIntern(cur, selbeg.pit(), selbeg.pos()); + cur.screenUpdateFlags(Update::Force); + } // Get word or selection selectWordWhenUnderCursor(cur, WHOLE_WORD); arg = cur.selectionAsString(false); @@ -2719,6 +2732,75 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) break; } + case LFUN_SPELLING_ADD_LOCAL: { + Language const * language = getLanguage(cur, cmd.getArg(1)); + docstring word = from_utf8(cmd.getArg(0)); + if (word.empty()) { + word = cur.selectionAsString(false); + if (word.size() > 100) + break; + if (word.empty()) { + // Get word or selection + selectWordWhenUnderCursor(cur, WHOLE_WORD); + word = cur.selectionAsString(false); + } + } + WordLangTuple wl(word, language); + if (!bv->buffer().params().spellignored(wl)) { + cur.recordUndoBufferParams(); + bv->buffer().params().spellignore().push_back(wl); + cur.recordUndo(); + // trigger re-check + WordLangTuple wl; + docstring_list suggestions; + Paragraph const & par = cur.paragraph(); + pos_type from = cur.pos(); + pos_type to = from; + par.spellCheck(from, to, wl, suggestions, true, true); + } + break; + } + + case LFUN_SPELLING_REMOVE_LOCAL: { + Language const * language = getLanguage(cur, cmd.getArg(1)); + docstring word = from_utf8(cmd.getArg(0)); + if (word.empty()) { + word = cur.selectionAsString(false); + if (word.size() > 100) + break; + if (word.empty()) { + // Get word or selection + selectWordWhenUnderCursor(cur, WHOLE_WORD); + word = cur.selectionAsString(false); + } + } + WordLangTuple wl(word, language); + bool has_item = false; + vector::const_iterator it = bv->buffer().params().spellignore().begin(); + for (; it != bv->buffer().params().spellignore().end(); ++it) { + if (it->lang()->code() != wl.lang()->code()) + continue; + if (it->word() == wl.word()) { + has_item = true; + break; + } + } + if (has_item) { + cur.recordUndoBufferParams(); + bv->buffer().params().spellignore().erase(it); + cur.recordUndo(); + // trigger re-check + WordLangTuple wl; + docstring_list suggestions; + Paragraph const & par = cur.paragraph(); + pos_type from = cur.pos(); + pos_type to = from; + par.spellCheck(from, to, wl, suggestions, true, true); + } + break; + } + + case LFUN_SPELLING_IGNORE: { Language const * language = getLanguage(cur, cmd.getArg(1)); docstring word = from_utf8(cmd.getArg(0)); @@ -2816,32 +2898,31 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) needsUpdate = true; break; - case LFUN_SERVER_GET_STATISTICS: - { - DocIterator from, to; - if (cur.selection()) { - from = cur.selectionBegin(); - to = cur.selectionEnd(); - } else { - from = doc_iterator_begin(cur.buffer()); - to = doc_iterator_end(cur.buffer()); - } - - cur.buffer()->updateStatistics(from, to); - string const arg0 = cmd.getArg(0); - if (arg0 == "words") { - cur.message(convert(cur.buffer()->wordCount())); - } else if (arg0 == "chars") { - cur.message(convert(cur.buffer()->charCount(false))); - } else if (arg0 == "chars-space") { - cur.message(convert(cur.buffer()->charCount(true))); - } else { - cur.message(convert(cur.buffer()->wordCount()) + " " - + convert(cur.buffer()->charCount(false)) + " " - + convert(cur.buffer()->charCount(true))); - } + case LFUN_SERVER_GET_STATISTICS: { + DocIterator from, to; + if (cur.selection()) { + from = cur.selectionBegin(); + to = cur.selectionEnd(); + } else { + from = doc_iterator_begin(cur.buffer()); + to = doc_iterator_end(cur.buffer()); + } + + cur.buffer()->updateStatistics(from, to); + string const arg0 = cmd.getArg(0); + if (arg0 == "words") { + cur.message(convert(cur.buffer()->wordCount())); + } else if (arg0 == "chars") { + cur.message(convert(cur.buffer()->charCount(false))); + } else if (arg0 == "chars-space") { + cur.message(convert(cur.buffer()->charCount(true))); + } else { + cur.message(convert(cur.buffer()->wordCount()) + " " + + convert(cur.buffer()->charCount(false)) + " " + + convert(cur.buffer()->charCount(true))); } break; + } default: LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by Text"); @@ -3449,6 +3530,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, break; case LFUN_SPELLING_ADD: + case LFUN_SPELLING_ADD_LOCAL: + case LFUN_SPELLING_REMOVE_LOCAL: case LFUN_SPELLING_IGNORE: case LFUN_SPELLING_REMOVE: enable = theSpellChecker() != nullptr; @@ -3466,7 +3549,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, docstring const layout = resolveLayout(req_layout, cur); enable = !owner_->forcePlainLayout() && !layout.empty(); - status.setOnOff(isAlreadyLayout(layout, cur)); + status.setOnOff(!owner_->forcePlainLayout() && isAlreadyLayout(layout, cur)); break; } @@ -3546,6 +3629,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_FONT_CROSSOUT: case LFUN_FONT_UNDERUNDERLINE: case LFUN_FONT_UNDERWAVE: + case LFUN_FONT_NO_SPELLCHECK: case LFUN_TEXTSTYLE_UPDATE: enable = !cur.paragraph().isPassThru(); break;