X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FText.cpp;h=00b575b07a70174413c2385c899048450e4e30f8;hb=0c7bd9a57f2a308bb9659200eda3b7e45f8d5d3c;hp=416a67bf0db29dfe42fc30e93e519d97fec2cb03;hpb=4154e088b0578dd516d6ae951195b354f8f5bf72;p=lyx.git diff --git a/src/Text.cpp b/src/Text.cpp index 416a67bf0d..00b575b07a 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -69,34 +69,11 @@ #include "support/lyxalgo.h" #include "support/lyxtime.h" #include "support/textutils.h" +#include "support/unique_ptr.h" #include -// TODO: replace if in Text::readParToken() with compile time switch -#if 0 - -#include "support/metahash.h" - -typedef boost::mpl::string<'\\end','_lay','out'> end_layout; -typedef boost::mpl::string<'\\end','in','set'> end_inset; - -void foo() -{ - std::string token = "\\end_layout"; - - switch (boost::hash_value(token)) { - case lyx::support::hash_string::value: - return; - case lyx::support::hash_string::value: - return; - default: ; - }; - -} -#endif - - using namespace std; using namespace lyx::support; @@ -133,12 +110,12 @@ static bool moveItem(Paragraph & fromPar, pos_type fromPos, void breakParagraphConservative(BufferParams const & bparams, - ParagraphList & pars, pit_type par_offset, pos_type pos) + ParagraphList & pars, pit_type pit, pos_type pos) { // create a new paragraph - Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), par_offset + 1), + Paragraph & tmp = *pars.insert(lyx::next(pars.begin(), pit + 1), Paragraph()); - Paragraph & par = pars[par_offset]; + Paragraph & par = pars[pit]; tmp.setInsetOwner(&par.inInset()); tmp.makeSameLayout(par); @@ -211,9 +188,8 @@ Text::Text(InsetText * owner, bool use_default_layout) Text::Text(InsetText * owner, Text const & text) - : owner_(owner) + : owner_(owner), pars_(text.pars_) { - pars_ = text.pars_; ParagraphList::iterator const end = pars_.end(); ParagraphList::iterator it = pars_.begin(); for (; it != end; ++it) @@ -488,8 +464,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex, } else if (token == "\\SpecialChar" || (token == "\\SpecialCharNoPassThru" && !par.layout().pass_thru && !inset().isPassThru())) { - auto_ptr inset; - inset.reset(new InsetSpecialChar); + auto inset = make_unique(); inset->read(lex); inset->setBuffer(*buf); par.insertInset(par.size(), inset.release(), font, change); @@ -498,8 +473,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex, docstring const s = ltrim(lex.getDocString(), "\\"); par.insert(par.size(), s, font, change); } else if (token == "\\IPAChar") { - auto_ptr inset; - inset.reset(new InsetIPAChar); + auto inset = make_unique(); inset->read(lex); inset->setBuffer(*buf); par.insertInset(par.size(), inset.release(), font, change); @@ -524,7 +498,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex, } else if (token == "\\backslash") { par.appendChar('\\', font, change); } else if (token == "\\LyXTable") { - auto_ptr inset(new InsetTabular(buf)); + auto inset = make_unique(buf); inset->read(lex); par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\change_unchanged") { @@ -931,11 +905,11 @@ void Text::insertChar(Cursor & cur, char_type c) if (lyxrc.auto_number) { static docstring const number_operators = from_ascii("+-/*"); static docstring const number_unary_operators = from_ascii("+-"); - static docstring const number_seperators = from_ascii(".,:"); + static docstring const number_separators = from_ascii(".,:"); if (cur.current_font.fontInfo().number() == FONT_ON) { if (!isDigitASCII(c) && !contains(number_operators, c) && - !(contains(number_seperators, c) && + !(contains(number_separators, c) && cur.pos() != 0 && cur.pos() != cur.lastpos() && tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON && @@ -956,7 +930,7 @@ void Text::insertChar(Cursor & cur, char_type c) ) { setCharFont(pit, cur.pos() - 1, cur.current_font, tm.font_); - } else if (contains(number_seperators, c) + } else if (contains(number_separators, c) && cur.pos() >= 2 && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) { setCharFont(pit, cur.pos() - 1, cur.current_font, @@ -1479,7 +1453,7 @@ void Text::deleteWordForward(Cursor & cur) cursorForward(cur); else { cur.resetAnchor(); - cur.setSelection(true); + cur.selection(true); cursorForwardOneWord(cur); cur.setSelection(); cutSelection(cur, true, false); @@ -1495,7 +1469,7 @@ void Text::deleteWordBackward(Cursor & cur) cursorBackward(cur); else { cur.resetAnchor(); - cur.setSelection(true); + cur.selection(true); cursorBackwardOneWord(cur); cur.setSelection(); cutSelection(cur, true, false); @@ -1611,6 +1585,7 @@ bool Text::erase(Cursor & cur) return dissolveInset(cur); if (!par.isMergedOnEndOfParDeletion(cur.buffer()->params().track_changes)) { + cur.recordUndo(DELETE_UNDO); par.setChange(cur.pos(), Change(Change::DELETED)); cur.forwardPos(); needsUpdate = true; @@ -1625,7 +1600,7 @@ bool Text::erase(Cursor & cur) if (needsUpdate) { // Make sure the cursor is correct. Is this really needed? // No, not really... at least not here! - cur.text()->setCursor(cur.top(), cur.pit(), cur.pos()); + cur.top().setPitPos(cur.pit(), cur.pos()); cur.checkBufferStructure(); } @@ -1732,7 +1707,7 @@ bool Text::backspace(Cursor & cur) // A singlePar update is not enough in this case. // cur.screenUpdateFlags(Update::Force); - setCursor(cur.top(), cur.pit(), cur.pos()); + cur.top().setPitPos(cur.pit(), cur.pos()); return needsUpdate; }