mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Adjust bookmark position when inserting/deleting from paragraph
Without this, bookmarks positions drift when editing.
This commit is contained in:
parent
b87a81c394
commit
86bfa10abb
@ -37,6 +37,7 @@
|
||||
#include "output_xhtml.h"
|
||||
#include "output_docbook.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "Session.h"
|
||||
#include "SpellChecker.h"
|
||||
#include "texstream.h"
|
||||
#include "TexRow.h"
|
||||
@ -832,6 +833,10 @@ void Paragraph::Private::insertChar(pos_type pos, char_type c,
|
||||
|
||||
// Update list of misspelled positions
|
||||
speller_state_.increasePosAfterPos(pos);
|
||||
|
||||
// Update bookmarks
|
||||
theSession().bookmarks().adjustPosAfterPos(inset_owner_->buffer().fileName(),
|
||||
id_, pos, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -916,6 +921,10 @@ bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
|
||||
d->speller_state_.decreasePosAfterPos(pos);
|
||||
d->speller_state_.refreshLast(size());
|
||||
|
||||
// Update bookmarks
|
||||
theSession().bookmarks().adjustPosAfterPos(d->inset_owner_->buffer().fileName(),
|
||||
d->id_, pos, -1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -353,6 +353,15 @@ BookmarksSection::bookmarksInPar(FileName const & fn, int const par_id) const
|
||||
}
|
||||
|
||||
|
||||
void BookmarksSection::adjustPosAfterPos(FileName const & fn,
|
||||
int const par_id, pos_type pos, int offset)
|
||||
{
|
||||
for (Bookmark & bkm : bookmarks)
|
||||
if (bkm.filename == fn && bkm.top_id == par_id && bkm.top_pos > pos)
|
||||
bkm.top_pos += offset;
|
||||
}
|
||||
|
||||
|
||||
LastCommandsSection::LastCommandsSection(unsigned int num) :
|
||||
default_num_last_commands(30),
|
||||
absolute_max_last_commands(100)
|
||||
|
@ -196,7 +196,7 @@ public:
|
||||
/// top and bottom level information sometimes needs to be sync'ed. In particular,
|
||||
/// top_id is determined when a bookmark is restored from session; and
|
||||
/// bottom_pit and bottom_pos are determined from top_id when a bookmark
|
||||
/// is save to session. (What a mess! :-)
|
||||
/// is saved to session. (What a mess! :-)
|
||||
///
|
||||
/// TODO: bottom level pit and pos will be replaced by StableDocIterator
|
||||
class Bookmark {
|
||||
@ -268,6 +268,13 @@ public:
|
||||
/// return a list of bookmarks and position for this paragraph
|
||||
BookmarkPosList bookmarksInPar(support::FileName const & fn, int par_id) const;
|
||||
|
||||
/* An insertion/deletion in paragraph \c par_id of buffer \c fn
|
||||
* lead to an offset \c offset after position \c pos. Update
|
||||
* bookmarks accordingly.
|
||||
*/
|
||||
void adjustPosAfterPos(support::FileName const & fn,
|
||||
int const par_id, pos_type pos, int offset);
|
||||
|
||||
private:
|
||||
|
||||
/// allow 9 regular bookmarks, bookmark 0 is temporary
|
||||
|
Loading…
Reference in New Issue
Block a user