mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-05 08:57:35 +00:00
* src/text.C: (backspacePos0): rewrite to make it simple and allow
deleting empty paragraphs even when keepempty is true. Do not rely on dEPM, since this was silly (bugs 2587 and 2882) (Delete): simplify also and avoid calling backspace. (backspace): small tweak. (patch by Jean-Marc) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15801 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e0fb6ae2cf
commit
4c765ba889
145
src/text.C
145
src/text.C
@ -1630,35 +1630,39 @@ bool LyXText::erase(LCursor & cur)
|
|||||||
{
|
{
|
||||||
BOOST_ASSERT(this == cur.text());
|
BOOST_ASSERT(this == cur.text());
|
||||||
bool needsUpdate = false;
|
bool needsUpdate = false;
|
||||||
|
Paragraph & par = cur.paragraph();
|
||||||
|
|
||||||
if (cur.pos() != cur.lastpos()) {
|
if (cur.pos() != cur.lastpos()) {
|
||||||
recordUndo(cur, Undo::DELETE, cur.pit());
|
// this is the code for a normal delete, not pasting
|
||||||
setCursorIntern(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
|
// any paragraphs
|
||||||
needsUpdate = backspace(cur);
|
recordUndo(cur, Undo::DELETE);
|
||||||
// FIXME: change tracking (MG)
|
// FIXME: change tracking (MG)
|
||||||
if (cur.paragraph().isDeleted(cur.pos()))
|
par.eraseChar(cur.pos(), cur.buffer().params().trackChanges);
|
||||||
cur.posRight();
|
if (par.isDeleted(cur.pos()))
|
||||||
|
cur.forwardPos();
|
||||||
|
needsUpdate = true;
|
||||||
} else if (cur.pit() != cur.lastpit()) {
|
} else if (cur.pit() != cur.lastpit()) {
|
||||||
LCursor scur = cur;
|
if (cur.buffer().params().trackChanges
|
||||||
|
&& par.isInserted(cur.pos())) {
|
||||||
setCursorIntern(cur, cur.pit() + 1, 0, false, false);
|
// mark "carriage return" as deleted:
|
||||||
if (pars_[cur.pit()].layout() == pars_[scur.pit()].layout()) {
|
// FIXME: Change tracking (MG)
|
||||||
recordUndo(scur, Undo::DELETE, scur.pit());
|
par.setChange(cur.pos(), Change(Change::DELETED));
|
||||||
needsUpdate = backspace(cur);
|
cur.forwardPos();
|
||||||
if (cur.buffer().params().trackChanges) {
|
needsUpdate = true;
|
||||||
// FIXME: Change tracking (MG)
|
|
||||||
// move forward after the paragraph break is DELETED
|
|
||||||
Paragraph & par = cur.paragraph();
|
|
||||||
// FIXME: change tracking (MG)
|
|
||||||
if (par.isDeleted(par.size()))
|
|
||||||
setCursorIntern(cur, cur.pit() + 1, 0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setCursorIntern(scur, scur.pit(), scur.pos(), false, scur.boundary());
|
setCursorIntern(cur, cur.pit() + 1, 0);
|
||||||
|
needsUpdate = backspacePos0(cur);
|
||||||
|
// FIXME: Change tracking (MG)
|
||||||
|
if (cur.paragraph().isDeleted(cur.pos()))
|
||||||
|
cur.forwardPos();
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
needsUpdate = dissolveInset(cur);
|
needsUpdate = dissolveInset(cur);
|
||||||
|
|
||||||
|
// Make sure the cursor is correct. Is this really needed?
|
||||||
|
if (needsUpdate)
|
||||||
|
setCursorIntern(cur, cur.pit(), cur.pos());
|
||||||
|
|
||||||
return needsUpdate;
|
return needsUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1666,79 +1670,56 @@ bool LyXText::erase(LCursor & cur)
|
|||||||
bool LyXText::backspacePos0(LCursor & cur)
|
bool LyXText::backspacePos0(LCursor & cur)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(this == cur.text());
|
BOOST_ASSERT(this == cur.text());
|
||||||
|
if (cur.pit() == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
bool needsUpdate = false;
|
bool needsUpdate = false;
|
||||||
|
|
||||||
Paragraph & par = cur.paragraph();
|
BufferParams const & bufparams = cur.buffer().params();
|
||||||
|
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
||||||
|
ParagraphList & plist = cur.text()->paragraphs();
|
||||||
|
Paragraph const & par = cur.paragraph();
|
||||||
|
LCursor prevcur = cur;
|
||||||
|
--prevcur.pit();
|
||||||
|
prevcur.pos() = prevcur.lastpos();
|
||||||
|
Paragraph const & prevpar = prevcur.paragraph();
|
||||||
|
|
||||||
// is it an empty paragraph?
|
// is it an empty paragraph?
|
||||||
pos_type lastpos = cur.lastpos();
|
if (cur.lastpos() == 0
|
||||||
if (lastpos == 0 || (lastpos == 1 && par.isSeparator(0))) {
|
|| (cur.lastpos() == 1 && par.isSeparator(0))) {
|
||||||
// This is an empty paragraph and we delete it just
|
recordUndo(cur, Undo::ATOMIC, prevcur.pit(), cur.pit());
|
||||||
// by moving the cursor one step
|
plist.erase(boost::next(plist.begin(), cur.pit()));
|
||||||
// left and let the DeleteEmptyParagraphMechanism
|
needsUpdate = true;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// is previous par empty?
|
||||||
if (cur.pit() != 0)
|
else if (prevcur.lastpos() == 0
|
||||||
recordUndo(cur, Undo::DELETE, cur.pit() - 1);
|
|| (prevcur.lastpos() == 1 && prevpar.isSeparator(0))) {
|
||||||
|
recordUndo(cur, Undo::ATOMIC, prevcur.pit(), cur.pit());
|
||||||
pit_type tmppit = cur.pit();
|
plist.erase(boost::next(plist.begin(), prevcur.pit()));
|
||||||
// We used to do cursorLeftIntern() here, but it is
|
needsUpdate = true;
|
||||||
// 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
|
// Pasting is not allowed, if the paragraphs have different
|
||||||
// layout. I think it is a real bug of all other
|
// layout. I think it is a real bug of all other
|
||||||
// word processors to allow it. It confuses the user.
|
// word processors to allow it. It confuses the user.
|
||||||
// Correction: Pasting is always allowed with standard-layout
|
// Correction: Pasting is always allowed with standard-layout
|
||||||
// Correction (Jug 20050717): Remove check about alignment!
|
else if (par.layout() == prevpar.layout()
|
||||||
Buffer & buf = cur.buffer();
|
|| par.layout() == tclass.defaultLayout()) {
|
||||||
BufferParams const & bufparams = buf.params();
|
recordUndo(cur, Undo::ATOMIC, prevcur.pit());
|
||||||
LyXTextClass const & tclass = bufparams.getLyXTextClass();
|
mergeParagraph(bufparams, plist, prevcur.pit());
|
||||||
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;
|
needsUpdate = true;
|
||||||
|
|
||||||
if (cur.pos() != 0 && pars_[cpit].isSeparator(cur.pos() - 1))
|
|
||||||
--cur.pos();
|
|
||||||
|
|
||||||
// the counters may have changed
|
|
||||||
ParIterator par_it(cur);
|
|
||||||
updateLabels(cur.buffer(), par_it);
|
|
||||||
|
|
||||||
setCursor(cur, cur.pit(), cur.pos(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (needsUpdate) {
|
||||||
|
updateLabels(cur.buffer());
|
||||||
|
setCursorIntern(cur, prevcur.pit(), prevcur.pos());
|
||||||
|
}
|
||||||
|
|
||||||
return needsUpdate;
|
return needsUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool LyXText::backspace(LCursor & cur)
|
bool LyXText::backspace(LCursor & cur)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(this == cur.text());
|
BOOST_ASSERT(this == cur.text());
|
||||||
@ -1747,11 +1728,7 @@ bool LyXText::backspace(LCursor & cur)
|
|||||||
if (cur.pit() == 0)
|
if (cur.pit() == 0)
|
||||||
return dissolveInset(cur);
|
return dissolveInset(cur);
|
||||||
|
|
||||||
// The cursor is at the beginning of a paragraph, so
|
if (cur.buffer().params().trackChanges) {
|
||||||
// the the backspace will collapse two paragraphs into
|
|
||||||
// one.
|
|
||||||
|
|
||||||
if (cur.pit() != 0 && cur.buffer().params().trackChanges) {
|
|
||||||
// FIXME: Change tracking (MG)
|
// FIXME: Change tracking (MG)
|
||||||
// Previous paragraph, mark "carriage return" as
|
// Previous paragraph, mark "carriage return" as
|
||||||
// deleted:
|
// deleted:
|
||||||
@ -1766,6 +1743,8 @@ bool LyXText::backspace(LCursor & cur)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The cursor is at the beginning of a paragraph, so
|
||||||
|
// the backspace will collapse two paragraphs into one.
|
||||||
needsUpdate = backspacePos0(cur);
|
needsUpdate = backspacePos0(cur);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user