return PitPosPair(endpit, endpos);
}
- bool all_erased = true;
-
- // Clear fragments of the first par in selection
- pars[startpit].erase(startpos, pars[startpit].size());
- if (pars[startpit].size() != startpos)
- all_erased = false;
-
- // Clear fragments of the last par in selection
- endpos -= pars[endpit].erase(0, endpos);
- if (endpos != 0)
- all_erased = false;
-
- // Erase all the "middle" paragraphs.
- if (params.tracking_changes) {
- // Look through the deleted pars if any, erasing as needed
- for (pit_type pit = startpit + 1; pit != endpit;) {
- // "erase" the contents of the par
- pars[pit].erase(0, pars[pit].size());
- if (pars[pit].empty()) {
- // remove the par if it's now empty
- pars.erase(pars.begin() + pit);
- --endpit;
- } else {
- ++pit;
- all_erased = false;
- }
- }
- } else {
- pars.erase(pars.begin() + startpit + 1, pars.begin() + endpit);
- endpit = startpit + 1;
- }
-
-#if 0 // FIXME: why for cut but not copy ?
- // the cut selection should begin with standard layout
- if (realcut) {
- buf->params().clear();
- buf->bibkey = 0;
- buf->layout(textclasslist[buffer->params.textclass].defaultLayoutName());
- }
-#endif
-
- if (startpit + 1 == pit_type(pars.size()))
- return PitPosPair(endpit, endpos);
-
- if (doclear) {
- pars[startpit + 1].stripLeadingSpaces();
- }
-
- // Merge first and last paragraph, if possible
- if (all_erased &&
- (pars[startpit].hasSameLayout(pars[startpit + 1]) ||
- pars[startpit + 1].empty())) {
- mergeParagraph(params, pars, startpit);
- // This because endpar gets deleted here!
- endpit = startpit;
- endpos = startpos;
+ // A paragraph break has to be physically removed by merging, but
+ // only if either (1) change tracking is off, or (2) the para break
+ // is "blue"
+ for (pit_type pit = startpit; pit != endpit + 1;) {
+ bool const merge = !params.tracking_changes ||
+ pars[pit].lookupChange(pars[pit].size()) ==
+ Change::INSERTED;
+ pos_type const left = ( pit == startpit ? startpos : 0 );
+ pos_type const right = ( pit == endpit ? endpos :
+ pars[pit].size() + 1 );
+ // Logical erase only:
+ pars[pit].erase(left, right);
+ // Separate handling of para break:
+ if (merge && pit != endpit &&
+ pars[pit].hasSameLayout(pars[pit + 1])) {
+ pos_type const thissize = pars[pit].size();
+ if (doclear)
+ pars[pit + 1].stripLeadingSpaces();
+ mergeParagraph(params, pars, pit);
+ --endpit;
+ if (pit == endpit)
+ endpos += thissize;
+ } else
+ ++pit;
}
+ // Ensure legal cursor pos:
+ endpit = startpit;
+ endpos = startpos;
return PitPosPair(endpit, endpos);
}
} else if (token == "\\change_unchanged") {
// Hack ! Needed for empty paragraphs :/
// FIXME: is it still ??
+ /*
if (!par.size())
par.cleanChanges();
+ */
change = Change(Change::UNCHANGED);
} else if (token == "\\change_inserted") {
lex.eatLine();
break;
}
}
+ // Final change goes to paragraph break:
+ par.setChangeFull(par.size(), change);
+
// Initialize begin_of_body_ on load; redoParagraph maintains
par.setBeginOfBody();
}
void LyXText::breakParagraph(LCursor & cur, bool keep_layout)
{
BOOST_ASSERT(this == cur.text());
- // allow only if at start or end, or all previous is new text
+
Paragraph & cpar = cur.paragraph();
pit_type cpit = cur.pit();
- if (cur.pos() != 0 && cur.pos() != cur.lastpos()
- && cpar.isChangeEdited(0, cur.pos()))
- return;
-
LyXTextClass const & tclass = cur.buffer().params().getLyXTextClass();
LyXLayout_ptr const & layout = cpar.layout();
updateCounters(cur.buffer());
+ // Mark "carriage return" as inserted if change tracking:
+ if (cur.buffer().params().tracking_changes) {
+ cur.paragraph().setChange(cur.paragraph().size(),
+ Change::INSERTED);
+ }
+
// This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user!
if (cur.pos() != 0 || isempty)
if (!cur.selection() && cur.lastpos() != 0)
return;
- CursorSlice const & startc = cur.selBegin();
- CursorSlice const & endc = cur.selEnd();
- if (startc.pit() == endc.pit()) {
- recordUndoSelection(cur, Undo::INSERT);
- pars_[startc.pit()].acceptChange(startc.pos(), endc.pos());
- finishUndo();
- cur.clearSelection();
- setCursorIntern(cur, startc.pit(), 0);
+ recordUndoSelection(cur, Undo::INSERT);
+
+ DocIterator it = cur.selectionBegin();
+ DocIterator et = cur.selectionEnd();
+ pit_type pit = it.pit();
+ Change::Type const type = pars_[pit].lookupChange(it.pos());
+ for (; pit <= et.pit(); ++pit) {
+ pos_type left = ( pit == it.pit() ? it.pos() : 0 );
+ pos_type right =
+ ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
+ pars_[pit].acceptChange(left, right);
}
-#ifdef WITH_WARNINGS
-#warning handle multi par selection
-#endif
+ if (type == Change::DELETED) {
+ ParagraphList & plist = paragraphs();
+ if (it.pit() + 1 < et.pit())
+ pars_.erase(plist.begin() + it.pit() + 1,
+ plist.begin() + et.pit());
+
+ // Paragraph merge if appropriate:
+ if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
+ == Change::DELETED) {
+ setCursorIntern(cur, it.pit() + 1, 0);
+ backspacePos0(cur);
+ }
+ }
+ finishUndo();
+ cur.clearSelection();
+ setCursorIntern(cur, it.pit(), 0);
}
if (!cur.selection() && cur.lastpos() != 0)
return;
- CursorSlice const & startc = cur.selBegin();
- CursorSlice const & endc = cur.selEnd();
- if (startc.pit() == endc.pit()) {
- recordUndoSelection(cur, Undo::INSERT);
- pars_[startc.pit()].rejectChange(startc.pos(), endc.pos());
- finishUndo();
- cur.clearSelection();
- setCursorIntern(cur, startc.pit(), 0);
+ recordUndoSelection(cur, Undo::INSERT);
+
+ DocIterator it = cur.selectionBegin();
+ DocIterator et = cur.selectionEnd();
+ pit_type pit = it.pit();
+ Change::Type const type = pars_[pit].lookupChange(it.pos());
+ for (; pit <= et.pit(); ++pit) {
+ pos_type left = ( pit == it.pit() ? it.pos() : 0 );
+ pos_type right =
+ ( pit == et.pit() ? et.pos() : pars_[pit].size() + 1 );
+ pars_[pit].rejectChange(left, right);
}
-#ifdef WITH_WARNINGS
-#warning handle multi par selection
-#endif
+ if (type == Change::INSERTED) {
+ ParagraphList & plist = paragraphs();
+ if (it.pit() + 1 < et.pit())
+ pars_.erase(plist.begin() + it.pit() + 1,
+ plist.begin() + et.pit());
+ // Paragraph merge if appropriate:
+ if (pars_[it.pit()].lookupChange(pars_[it.pit()].size())
+ == Change::INSERTED) {
+ setCursorIntern(cur, it.pit() + 1, 0);
+ backspacePos0(cur);
+ }
+ }
+ finishUndo();
+ cur.clearSelection();
+ setCursorIntern(cur, it.pit(), 0);
}
}
-bool LyXText::backspace(LCursor & cur)
+bool LyXText::backspacePos0(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
bool needsUpdate = false;
- if (cur.pos() == 0) {
- // The cursor is at the beginning of a paragraph, so
- // the the backspace will collapse two paragraphs into
- // one.
- // but it's not allowed unless it's new
- Paragraph & par = cur.paragraph();
- if (par.isChangeEdited(0, par.size()))
- return false;
+ Paragraph & par = cur.paragraph();
+ // is it an empty paragraph?
+ pos_type lastpos = cur.lastpos();
+ if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
+ // This is an empty paragraph and we delete it just
+ // by moving the cursor one step
+ // left and let the DeleteEmptyParagraphMechanism
+ // handle the actual deletion of the paragraph.
- // we may paste some paragraphs
-
- // is it an empty paragraph?
- pos_type lastpos = cur.lastpos();
- if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
- // This is an empty paragraph and we delete it just
- // by moving the cursor one step
- // left and let the DeleteEmptyParagraphMechanism
- // handle the actual deletion of the paragraph.
-
- if (cur.pit() != 0) {
- // For KeepEmpty layouts we need to get
- // rid of the keepEmpty setting first.
- // And the only way to do this is to
- // reset the layout to something
- // else: f.ex. the default layout.
- if (par.allowEmpty()) {
- Buffer & buf = cur.buffer();
- BufferParams const & bparams = buf.params();
- par.layout(bparams.getLyXTextClass().defaultLayout());
- }
-
- cursorLeft(cur);
- return true;
+ if (cur.pit() != 0) {
+ // For KeepEmpty layouts we need to get
+ // rid of the keepEmpty setting first.
+ // And the only way to do this is to
+ // reset the layout to something
+ // else: f.ex. the default layout.
+ if (par.allowEmpty()) {
+ Buffer & buf = cur.buffer();
+ BufferParams const & bparams = buf.params();
+ par.layout(bparams.getLyXTextClass().defaultLayout());
}
+
+ cursorLeft(cur);
+ return true;
}
+ }
- if (cur.pit() != 0)
- recordUndo(cur, Undo::DELETE, cur.pit() - 1);
+ if (cur.pit() != 0)
+ recordUndo(cur, Undo::DELETE, cur.pit() - 1);
+
+ pit_type tmppit = cur.pit();
+ // We used to do cursorLeftIntern() here, but it is
+ // not a good idea since it triggers the auto-delete
+ // mechanism. So we do a cursorLeftIntern()-lite,
+ // without the dreaded mechanism. (JMarc)
+ if (cur.pit() != 0) {
+ // steps into the above paragraph.
+ setCursorIntern(cur, cur.pit() - 1,
+ pars_[cur.pit() - 1].size(),
+ false);
+ }
- pit_type tmppit = cur.pit();
- // We used to do cursorLeftIntern() here, but it is
- // not a good idea since it triggers the auto-delete
- // mechanism. So we do a cursorLeftIntern()-lite,
- // without the dreaded mechanism. (JMarc)
- if (cur.pit() != 0) {
- // steps into the above paragraph.
- setCursorIntern(cur, cur.pit() - 1,
- pars_[cur.pit() - 1].size(),
- false);
- }
+ // Pasting is not allowed, if the paragraphs have different
+ // layout. I think it is a real bug of all other
+ // word processors to allow it. It confuses the user.
+ // Correction: Pasting is always allowed with standard-layout
+ // Correction (Jug 20050717): Remove check about alignment!
+ Buffer & buf = cur.buffer();
+ BufferParams const & bufparams = buf.params();
+ LyXTextClass const & tclass = bufparams.getLyXTextClass();
+ pit_type const cpit = cur.pit();
- // Pasting is not allowed, if the paragraphs have different
- // layout. I think it is a real bug of all other
- // word processors to allow it. It confuses the user.
- // Correction: Pasting is always allowed with standard-layout
- // Correction (Jug 20050717): Remove check about alignment!
- Buffer & buf = cur.buffer();
- BufferParams const & bufparams = buf.params();
- LyXTextClass const & tclass = bufparams.getLyXTextClass();
- pit_type const cpit = cur.pit();
-
- if (cpit != tmppit
- && (pars_[cpit].layout() == pars_[tmppit].layout()
- || pars_[tmppit].layout() == tclass.defaultLayout()))
- {
- mergeParagraph(bufparams, pars_, cpit);
- needsUpdate = true;
+ if (cpit != tmppit
+ && (pars_[cpit].layout() == pars_[tmppit].layout()
+ || pars_[tmppit].layout() == tclass.defaultLayout()))
+ {
+ mergeParagraph(bufparams, pars_, cpit);
+ needsUpdate = true;
- if (cur.pos() != 0 && pars_[cpit].isSeparator(cur.pos() - 1))
+ if (cur.pos() != 0 && pars_[cpit].isSeparator(cur.pos() - 1))
--cur.pos();
- // the counters may have changed
- updateCounters(cur.buffer());
- setCursor(cur, cur.pit(), cur.pos(), false);
+ // the counters may have changed
+ updateCounters(cur.buffer());
+ setCursor(cur, cur.pit(), cur.pos(), false);
+ }
+ return needsUpdate;
+}
+
+
+bool LyXText::backspace(LCursor & cur)
+{
+ BOOST_ASSERT(this == cur.text());
+ bool needsUpdate = false;
+ if (cur.pos() == 0) {
+ // The cursor is at the beginning of a paragraph, so
+ // the the backspace will collapse two paragraphs into
+ // one.
+
+ if (cur.buffer().params().tracking_changes) {
+ // Previous paragraph, mark "carriage return" as
+ // deleted:
+ Paragraph & par = pars_[cur.pit() - 1];
+ par.setChange(par.size(), Change::DELETED);
+ setCursorIntern(cur, cur.pit() - 1, par.size());
+ return false;
}
+
+ needsUpdate = backspacePos0(cur);
+
} else {
// this is the code for a normal backspace, not pasting
// any paragraphs
std::ostringstream os;
bool const show_change = buf.params().tracking_changes
- && cur.pos() != cur.lastpos()
&& par.lookupChange(cur.pos()) != Change::UNCHANGED;
+ if (buf.params().tracking_changes)
+ os << "[C] ";
+
if (show_change) {
Change change = par.lookupChangeFull(cur.pos());
Author const & a = buf.params().authors().get(change.author);