X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftext.C;h=7ca49fe69e88754bee75bb0fcdb28d7305d990fd;hb=35204f8f33d7400a5fefeffea533fb4cb4097211;hp=674b7103f16c146a25b47e9055825379d873104b;hpb=cf7084771cd276eb1e42eca8fc4f2d2dcf45da0e;p=lyx.git diff --git a/src/text.C b/src/text.C index 674b7103f1..7ca49fe69e 100644 --- a/src/text.C +++ b/src/text.C @@ -1153,8 +1153,12 @@ void LyXText::breakParagraph(LCursor & cur, bool keep_layout) // Because of the mix between the model (the paragraph contents) and the // view (the paragraph breaking in rows, we have to do this here before // the setCursor() call below. - redoParagraph(cur.bv(), cpit); - redoParagraph(cur.bv(), cpit + 1); + bool changed_height = redoParagraph(cur.bv(), cpit); + changed_height |= redoParagraph(cur.bv(), cpit + 1); + if (changed_height) + // A singlePar update is not enough in this case. + cur.updateFlags(Update::Force); + // This check is necessary. Otherwise the new empty paragraph will // be deleted automatically. And it is more friendly for the user! @@ -1253,7 +1257,9 @@ void LyXText::insertChar(LCursor & cur, char_type c) // FIXME: Inserting a character has nothing to do with setting a cursor. // Because of the mix between the model (the paragraph contents) and the // view (the paragraph breaking in rows, we have to do this here. - redoParagraph(cur.bv(), cur.pit()); + if (redoParagraph(cur.bv(), cur.pit())) + // A singlePar update is not enough in this case. + cur.updateFlags(Update::Force); setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary()); charInserted(); } @@ -1671,9 +1677,18 @@ bool LyXText::erase(LCursor & cur) } else needsUpdate = dissolveInset(cur); - // Make sure the cursor is correct. Is this really needed? - if (needsUpdate) + // FIXME: Inserting characters has nothing to do with setting a cursor. + // Because of the mix between the model (the paragraph contents) + // and the view (the paragraph breaking in rows, we have to do this + // here before the setCursorIntern() call. + if (needsUpdate) { + if (redoParagraph(cur.bv(), cur.pit())) + // A singlePar update is not enough in this case. + cur.updateFlags(Update::Force); + // Make sure the cursor is correct. Is this really needed? + // No, not really... at least not here! setCursorIntern(cur, cur.pit(), cur.pos()); + } return needsUpdate; } @@ -1780,7 +1795,9 @@ bool LyXText::backspace(LCursor & cur) // Because of the mix between the model (the paragraph contents) // and the view (the paragraph breaking in rows, we have to do this // here before the setCursor() call. - redoParagraph(cur.bv(), cur.pit()); + if (redoParagraph(cur.bv(), cur.pit())) + // A singlePar update is not enough in this case. + cur.updateFlags(Update::Force); setCursor(cur, cur.pit(), cur.pos(), false, cur.boundary()); return needsUpdate; @@ -1793,6 +1810,7 @@ bool LyXText::dissolveInset(LCursor & cur) { if (isMainText(*cur.bv().buffer()) || cur.inset().nargs() != 1) return false; + bool const in_ert = cur.inset().lyxCode() == InsetBase::ERT_CODE; recordUndoInset(cur); cur.selHandle(false); // save position @@ -1810,6 +1828,19 @@ bool LyXText::dissolveInset(LCursor & cur) { // FIXME: change tracking (MG) cur.paragraph().eraseChar(cur.pos(), b.params().trackChanges); if (!plist.empty()) { + if (in_ert) { + // ERT paragraphs have the Language latex_language. + // This is invalid outside of ERT, so we need to + // change it to the buffer language. + ParagraphList::iterator it = plist.begin(); + ParagraphList::iterator it_end = plist.end(); + for (; it != it_end; it++) { + it->changeLanguage(b.params(), + latex_language, + b.getLanguage()); + } + } + pasteParagraphList(cur, plist, b.params().textclass, b.errorList("Paste")); // restore position @@ -1909,7 +1940,7 @@ bool LyXText::redoParagraph(BufferView & bv, pit_type const pit) dim.asc += par.rows()[0].ascent(); dim.des -= par.rows()[0].ascent(); - bool const same = dim == par.dim(); + bool const same = dim.height() == par.dim().height(); par.dim() = dim; //lyxerr << "redoParagraph: " << par.rows().size() << " rows\n"; @@ -2508,4 +2539,61 @@ bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y) } +void LyXText::charsTranspose(LCursor & cur) +{ + BOOST_ASSERT(this == cur.text()); + + pos_type pos = cur.pos(); + + // If cursor is at beginning or end of paragraph, do nothing. + if (pos == cur.lastpos() || pos == 0) + return; + + Paragraph & par = cur.paragraph(); + + // Get the positions of the characters to be transposed. + pos_type pos1 = pos - 1; + pos_type pos2 = pos; + + // In change tracking mode, ignore deleted characters. + while (pos2 < cur.lastpos() && par.isDeleted(pos2)) + ++pos2; + if (pos2 == cur.lastpos()) + return; + + while (pos1 >= 0 && par.isDeleted(pos1)) + --pos1; + if (pos1 < 0) + return; + + // Don't do anything if one of the "characters" is not regular text. + if (par.isInset(pos1) || par.isInset(pos2)) + return; + + // Store the characters to be transposed (including font information). + char_type char1 = par.getChar(pos1); + LyXFont const font1 = + par.getFontSettings(cur.buffer().params(), pos1); + + char_type char2 = par.getChar(pos2); + LyXFont const font2 = + par.getFontSettings(cur.buffer().params(), pos2); + + // And finally, we are ready to perform the transposition. + // Track the changes if Change Tracking is enabled. + bool const trackChanges = cur.buffer().params().trackChanges; + + recordUndo(cur); + + par.eraseChar(pos2, trackChanges); + par.eraseChar(pos1, trackChanges); + par.insertChar(pos1, char2, font2, trackChanges); + par.insertChar(pos2, char1, font1, trackChanges); + + // After the transposition, move cursor to after the transposition. + setCursor(cur, cur.pit(), pos2); + cur.forwardPos(); +} + + } // namespace lyx