mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
Sanitize the DEPM!
* BufferView: - checkDepm(): new method for DEPM mechanism. - mouseSetCursor(): use checkDepm(). * text2.C: - use BufferView::checkDepm() instead of using LyXText::deleteEmptyParagraphMechanism() directly. - deleteEmptyParagraphMechanism(): prepare for conversion to DocIterator (code transferred to BufferView::checkDepm()). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16442 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1e74724606
commit
ceb51f7f76
@ -1239,6 +1239,28 @@ void BufferView::setCursor(DocIterator const & dit)
|
||||
}
|
||||
|
||||
|
||||
bool BufferView::checkDepm(LCursor & cur, LCursor & old)
|
||||
{
|
||||
// Would be wrong to delete anything if we have a selection.
|
||||
if (cur.selection())
|
||||
return false;
|
||||
|
||||
bool need_anchor_change = false;
|
||||
bool changed = cursor_.text()->deleteEmptyParagraphMechanism(cur, old,
|
||||
need_anchor_change);
|
||||
|
||||
if (need_anchor_change)
|
||||
cur.resetAnchor();
|
||||
|
||||
if (!changed)
|
||||
return false;
|
||||
|
||||
updateMetrics(false);
|
||||
buffer_->changed();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool BufferView::mouseSetCursor(LCursor & cur)
|
||||
{
|
||||
BOOST_ASSERT(&cur.bv() == this);
|
||||
@ -1252,7 +1274,7 @@ bool BufferView::mouseSetCursor(LCursor & cur)
|
||||
// FIXME: move this to InsetText::notifyCursorLeaves?
|
||||
bool update = false;
|
||||
if (!badcursor && cursor_.inTexted())
|
||||
update = cursor_.text()->deleteEmptyParagraphMechanism(cur, cursor_);
|
||||
checkDepm(cur, cursor_);
|
||||
|
||||
cursor_ = cur;
|
||||
cursor_.clearSelection();
|
||||
|
@ -184,6 +184,9 @@ public:
|
||||
/// sets cursor.
|
||||
/// This will also open all relevant collapsable insets.
|
||||
void setCursor(DocIterator const &);
|
||||
/// Check deleteEmptyParagraphMechanism and update metrics if needed.
|
||||
/// \retval true if an update was needed.
|
||||
bool checkDepm(LCursor & cur, LCursor & old);
|
||||
/// sets cursor.
|
||||
/// This is used when handling LFUN_MOUSE_PRESS.
|
||||
bool mouseSetCursor(LCursor & cur);
|
||||
|
@ -30,11 +30,11 @@ class Buffer;
|
||||
class BufferParams;
|
||||
class BufferView;
|
||||
class CursorSlice;
|
||||
class DocIterator;
|
||||
class ErrorList;
|
||||
class InsetBase;
|
||||
class InsetBase_code;
|
||||
class FuncRequest;
|
||||
class FuncStatus;
|
||||
class InsetBase;
|
||||
class LColor_color;
|
||||
class LCursor;
|
||||
class LyXTextClass;
|
||||
@ -349,8 +349,10 @@ public:
|
||||
bool boundary) const;
|
||||
|
||||
/// delete double space or empty paragraphs around old cursor
|
||||
/// FIXME: replace LCursor with DocIterator.
|
||||
bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
|
||||
/// FIXME: replace LCursor with DocIterator. This is not possible right
|
||||
/// now because recordUndo() is called which needs a LCursor.
|
||||
bool deleteEmptyParagraphMechanism(LCursor & cur,
|
||||
LCursor & old, bool & need_anchor_change);
|
||||
|
||||
/// sets row.end to the pos value *after* which a row should break.
|
||||
/// for example, the pos after which isNewLine(pos) == true
|
||||
|
30
src/text2.C
30
src/text2.C
@ -671,7 +671,7 @@ bool LyXText::setCursor(LCursor & cur, pit_type par, pos_type pos,
|
||||
{
|
||||
LCursor old = cur;
|
||||
setCursorIntern(cur, par, pos, setfont, boundary);
|
||||
return deleteEmptyParagraphMechanism(cur, old);
|
||||
return cur.bv().checkDepm(cur, old);
|
||||
}
|
||||
|
||||
|
||||
@ -1154,7 +1154,7 @@ bool LyXText::cursorUp(LCursor & cur)
|
||||
if (dummy == old)
|
||||
++dummy.pos();
|
||||
|
||||
return deleteEmptyParagraphMechanism(dummy, old);
|
||||
cur.bv().checkDepm(dummy, old);
|
||||
}
|
||||
|
||||
bool updateNeeded = false;
|
||||
@ -1207,14 +1207,14 @@ bool LyXText::cursorDown(LCursor & cur)
|
||||
LCursor dummy = cur;
|
||||
if (dummy == old)
|
||||
++dummy.pos();
|
||||
|
||||
bool const changed = deleteEmptyParagraphMechanism(dummy, old);
|
||||
|
||||
bool const changed = cur.bv().checkDepm(dummy, old);
|
||||
|
||||
// Make sure that cur gets back whatever happened to dummy(Lgb)
|
||||
if (changed)
|
||||
cur = dummy;
|
||||
|
||||
return changed;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool updateNeeded = false;
|
||||
@ -1276,12 +1276,9 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where)
|
||||
}
|
||||
|
||||
|
||||
bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
|
||||
bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur,
|
||||
LCursor & old, bool & need_anchor_change)
|
||||
{
|
||||
// Would be wrong to delete anything if we have a selection.
|
||||
if (cur.selection())
|
||||
return false;
|
||||
|
||||
//lyxerr[Debug::DEBUG] << "DEPM: cur:\n" << cur << "old:\n" << old << endl;
|
||||
// old should point to us
|
||||
BOOST_ASSERT(old.text() == this);
|
||||
@ -1322,8 +1319,6 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
|
||||
&& oldpar.isLineSeparator(old.pos() - 1)
|
||||
&& !oldpar.isDeleted(old.pos() - 1)) {
|
||||
oldpar.eraseChar(old.pos() - 1, false); // do not track changes in DEPM
|
||||
TextMetrics & tm = cur.bv().textMetrics(this);
|
||||
tm.redoParagraph(old.pit());
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning This will not work anymore when we have multiple views of the same buffer
|
||||
// In this case, we will have to correct also the cursors held by
|
||||
@ -1333,7 +1328,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
|
||||
// correct all cursor parts
|
||||
if (same_par) {
|
||||
fixCursorAfterDelete(cur.top(), old.top());
|
||||
cur.resetAnchor();
|
||||
need_anchor_change = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1370,19 +1365,14 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old)
|
||||
// their address has changed. Therefore we
|
||||
// need to `regenerate' cur. (JMarc)
|
||||
cur.updateInsets(&(cur.bottom().inset()));
|
||||
cur.resetAnchor();
|
||||
need_anchor_change = true;
|
||||
}
|
||||
}
|
||||
// There is a crash reported by Edwin Leuven (16/04/2006) because of:
|
||||
//ParIterator par_it(old);
|
||||
//updateLabels(old.buffer(), par_it);
|
||||
// So for now we do the full update:
|
||||
updateLabels(old.buffer());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (oldpar.stripLeadingSpaces())
|
||||
cur.resetAnchor();
|
||||
need_anchor_change = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace lyx {
|
||||
|
||||
class BufferParams;
|
||||
class BufferView;
|
||||
class DocIterator;
|
||||
class LCursor;
|
||||
|
||||
|
||||
@ -118,6 +119,8 @@ void finishUndo();
|
||||
*/
|
||||
|
||||
/// The general case: prepare undo for an arbitrary range.
|
||||
/// FIXME: replace LCursor with DocIterator. This is not possible right
|
||||
/// now because we need access to Buffer->params()!.
|
||||
void recordUndo(LCursor & cur, Undo::undo_kind kind,
|
||||
pit_type from, pit_type to);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user