mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
Helpers to set selections to arbitrary DocIterators
This commit is contained in:
parent
3fd2398a28
commit
c36ada6b96
@ -2478,6 +2478,18 @@ void BufferView::setCursor(DocIterator const & dit)
|
||||
}
|
||||
|
||||
|
||||
void BufferView::setCursorSelectionTo(DocIterator const & dit)
|
||||
{
|
||||
size_t const n = dit.depth();
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
dit[i].inset().edit(d->cursor_, true);
|
||||
|
||||
d->cursor_.selection(true);
|
||||
d->cursor_.setCursorSelectionTo(dit);
|
||||
d->cursor_.setCurrentFont();
|
||||
}
|
||||
|
||||
|
||||
bool BufferView::checkDepm(Cursor & cur, Cursor & old)
|
||||
{
|
||||
// Would be wrong to delete anything if we have a selection.
|
||||
|
@ -249,6 +249,8 @@ public:
|
||||
/// sets cursor.
|
||||
/// This will also open all relevant collapsable insets.
|
||||
void setCursor(DocIterator const &);
|
||||
/// set the selection up to dit.
|
||||
void setCursorSelectionTo(DocIterator const & dit);
|
||||
/// Check deleteEmptyParagraphMechanism and update metrics if needed.
|
||||
/// \retval true if an update was needed.
|
||||
bool checkDepm(Cursor & cur, Cursor & old);
|
||||
|
@ -194,13 +194,37 @@ void Cursor::reset()
|
||||
}
|
||||
|
||||
|
||||
// this (intentionally) does neither touch anchor nor selection status
|
||||
void Cursor::setCursor(DocIterator const & cur)
|
||||
{
|
||||
DocIterator::operator=(cur);
|
||||
}
|
||||
|
||||
|
||||
void Cursor::setCursorSelectionTo(DocIterator dit)
|
||||
{
|
||||
size_t i = 0;
|
||||
// normalise dit
|
||||
while (i < dit.depth() && i < anchor_.depth() && dit[i] == anchor_[i])
|
||||
++i;
|
||||
if (i != dit.depth()) {
|
||||
// otherwise the cursor is already normal
|
||||
if (i == anchor_.depth())
|
||||
// dit is a proper extension of the anchor_
|
||||
dit.cutOff(i - 1);
|
||||
else if (i + 1 < dit.depth()) {
|
||||
// one has dit[i] != anchor_[i] but either dit[i-1] == anchor_[i-1]
|
||||
// or i == 0. Remove excess.
|
||||
dit.cutOff(i);
|
||||
if (dit[i] > anchor_[i])
|
||||
// place dit after the inset it was in
|
||||
++dit.pos();
|
||||
}
|
||||
}
|
||||
setCursor(dit);
|
||||
setSelection();
|
||||
}
|
||||
|
||||
|
||||
void Cursor::setCursorToAnchor()
|
||||
{
|
||||
if (selection()) {
|
||||
|
@ -149,7 +149,10 @@ public:
|
||||
/// set the cursor data
|
||||
void setCursorData(CursorData const & data);
|
||||
/// sets cursor part
|
||||
/// this (intentionally) does neither touch anchor nor selection status
|
||||
void setCursor(DocIterator const & it);
|
||||
/// set the cursor to dit normalised against the anchor, and set selection.
|
||||
void setCursorSelectionTo(DocIterator dit);
|
||||
/// sets the cursor to the normalized selection anchor
|
||||
void setCursorToAnchor();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user