mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 13:48:59 +00:00
* src/lyxtext.h:
* src/text.C: rename acceptOrRejectChange() to acceptOrRejectChanges() because it can handle many changes within the given selection; add acceptChanges() and rejectChanges() * src/text3.C: * src/BufferView.C: adjust * src/insets/insettext.C: accept/rejectChanges() become wrapper methods that call LyXText::acccept/rejectChanges * src/text2.C: add assertion git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16859 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f4cc84d5a6
commit
77427d620a
@ -862,7 +862,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
|
||||
#warning FIXME changes
|
||||
#endif
|
||||
while (findNextChange(this))
|
||||
getLyXText()->acceptOrRejectChange(cursor_, LyXText::ChangeOp::ACCEPT);
|
||||
getLyXText()->acceptOrRejectChanges(cursor_, LyXText::ChangeOp::ACCEPT);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -872,7 +872,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
|
||||
#warning FIXME changes
|
||||
#endif
|
||||
while (findNextChange(this))
|
||||
getLyXText()->acceptOrRejectChange(cursor_, LyXText::ChangeOp::REJECT);
|
||||
getLyXText()->acceptOrRejectChanges(cursor_, LyXText::ChangeOp::REJECT);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -279,73 +279,13 @@ void InsetText::setChange(Change const & change)
|
||||
|
||||
void InsetText::acceptChanges(BufferParams const & bparams)
|
||||
{
|
||||
ParagraphList & pars = paragraphs();
|
||||
pit_type pars_size = (pit_type) pars.size();
|
||||
|
||||
// first, accept changes within each individual paragraph
|
||||
// (do not consider end-of-par)
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
if (!pars[pit].empty()) // prevent assertion failure
|
||||
pars[pit].acceptChanges(bparams, 0, pars[pit].size());
|
||||
}
|
||||
|
||||
// next, accept imaginary end-of-par characters
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
pos_type pos = pars[pit].size();
|
||||
|
||||
if (pars[pit].isInserted(pos)) {
|
||||
pars[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else if (pars[pit].isDeleted(pos)) {
|
||||
if (pit == pars.size() - 1) {
|
||||
// we cannot remove a par break at the end of the last
|
||||
// paragraph; instead, we mark it unchanged
|
||||
pars[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else {
|
||||
mergeParagraph(bparams, pars, pit);
|
||||
--pit;
|
||||
--pars_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally, invoke the DEPM
|
||||
text_.deleteEmptyParagraphMechanism(0, pars.size() - 1, bparams.trackChanges);
|
||||
text_.acceptChanges(bparams);
|
||||
}
|
||||
|
||||
|
||||
void InsetText::rejectChanges(BufferParams const & bparams)
|
||||
{
|
||||
ParagraphList & pars = paragraphs();
|
||||
pit_type pars_size = (pit_type) pars.size();
|
||||
|
||||
// first, reject changes within each individual paragraph
|
||||
// (do not consider end-of-par)
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
if (!pars[pit].empty()) // prevent assertion failure
|
||||
pars[pit].rejectChanges(bparams, 0, pars[pit].size());
|
||||
}
|
||||
|
||||
// next, reject imaginary end-of-par characters
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
pos_type pos = pars[pit].size();
|
||||
|
||||
if (pars[pit].isDeleted(pos)) {
|
||||
pars[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else if (pars[pit].isInserted(pos)) {
|
||||
if (pit == pars.size() - 1) {
|
||||
// we mark the par break at the end of the last
|
||||
// paragraph unchanged
|
||||
pars[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else {
|
||||
mergeParagraph(bparams, pars, pit);
|
||||
--pit;
|
||||
--pars_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally, invoke the DEPM
|
||||
text_.deleteEmptyParagraphMechanism(0, pars.size() - 1, bparams.trackChanges);
|
||||
text_.rejectChanges(bparams);
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,7 +159,11 @@ public:
|
||||
REJECT
|
||||
};
|
||||
/// accept or reject the selected change
|
||||
void acceptOrRejectChange(LCursor & cur, ChangeOp op);
|
||||
void acceptOrRejectChanges(LCursor & cur, ChangeOp op);
|
||||
/// accept the changes within the complete LyXText
|
||||
void acceptChanges(BufferParams const & bparams);
|
||||
/// reject the changes within the complete LyXText
|
||||
void rejectChanges(BufferParams const & bparams);
|
||||
|
||||
/// returns true if par was empty and was removed
|
||||
bool setCursor(LCursor & cur, pit_type par, pos_type pos,
|
||||
|
72
src/text.C
72
src/text.C
@ -845,7 +845,7 @@ bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
|
||||
}
|
||||
|
||||
|
||||
void LyXText::acceptOrRejectChange(LCursor & cur, ChangeOp op)
|
||||
void LyXText::acceptOrRejectChanges(LCursor & cur, ChangeOp op)
|
||||
{
|
||||
BOOST_ASSERT(this == cur.text());
|
||||
|
||||
@ -949,6 +949,76 @@ void LyXText::acceptOrRejectChange(LCursor & cur, ChangeOp op)
|
||||
}
|
||||
|
||||
|
||||
void LyXText::acceptChanges(BufferParams const & bparams)
|
||||
{
|
||||
pit_type pars_size = (pit_type) pars_.size();
|
||||
|
||||
// first, accept changes within each individual paragraph
|
||||
// (do not consider end-of-par)
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
if (!pars_[pit].empty()) // prevent assertion failure
|
||||
pars_[pit].acceptChanges(bparams, 0, pars_[pit].size());
|
||||
}
|
||||
|
||||
// next, accept imaginary end-of-par characters
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
pos_type pos = pars_[pit].size();
|
||||
|
||||
if (pars_[pit].isInserted(pos)) {
|
||||
pars_[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else if (pars_[pit].isDeleted(pos)) {
|
||||
if (pit == pars_size - 1) {
|
||||
// we cannot remove a par break at the end of the last
|
||||
// paragraph; instead, we mark it unchanged
|
||||
pars_[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else {
|
||||
mergeParagraph(bparams, pars_, pit);
|
||||
--pit;
|
||||
--pars_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally, invoke the DEPM
|
||||
deleteEmptyParagraphMechanism(0, pars_size - 1, bparams.trackChanges);
|
||||
}
|
||||
|
||||
|
||||
void LyXText::rejectChanges(BufferParams const & bparams)
|
||||
{
|
||||
pit_type pars_size = (pit_type) pars_.size();
|
||||
|
||||
// first, reject changes within each individual paragraph
|
||||
// (do not consider end-of-par)
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
if (!pars_[pit].empty()) // prevent assertion failure
|
||||
pars_[pit].rejectChanges(bparams, 0, pars_[pit].size());
|
||||
}
|
||||
|
||||
// next, reject imaginary end-of-par characters
|
||||
for (pit_type pit = 0; pit < pars_size; ++pit) {
|
||||
pos_type pos = pars_[pit].size();
|
||||
|
||||
if (pars_[pit].isDeleted(pos)) {
|
||||
pars_[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else if (pars_[pit].isInserted(pos)) {
|
||||
if (pit == pars_size - 1) {
|
||||
// we mark the par break at the end of the last
|
||||
// paragraph unchanged
|
||||
pars_[pit].setChange(pos, Change(Change::UNCHANGED));
|
||||
} else {
|
||||
mergeParagraph(bparams, pars_, pit);
|
||||
--pit;
|
||||
--pars_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// finally, invoke the DEPM
|
||||
deleteEmptyParagraphMechanism(0, pars_size - 1, bparams.trackChanges);
|
||||
}
|
||||
|
||||
|
||||
// Delete from cursor up to the end of the current or next word.
|
||||
void LyXText::deleteWordForward(LCursor & cur)
|
||||
{
|
||||
|
@ -1246,6 +1246,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur,
|
||||
|
||||
void LyXText::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges)
|
||||
{
|
||||
BOOST_ASSERT(first >= 0 && first <= last && last < pars_.size());
|
||||
|
||||
for (pit_type pit = first; pit <= last; ++pit) {
|
||||
Paragraph & par = pars_[pit];
|
||||
|
||||
|
@ -1429,12 +1429,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
|
||||
}
|
||||
|
||||
case LFUN_CHANGE_ACCEPT: {
|
||||
acceptOrRejectChange(cur, ACCEPT);
|
||||
acceptOrRejectChanges(cur, ACCEPT);
|
||||
break;
|
||||
}
|
||||
|
||||
case LFUN_CHANGE_REJECT: {
|
||||
acceptOrRejectChange(cur, REJECT);
|
||||
acceptOrRejectChanges(cur, REJECT);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user