mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Improve the TexRow Cursor->Row algorithm for selections.
Selections were incorrect after the addition of math due to the invalidation of an invariant.
This commit is contained in:
parent
c51ebd9bbc
commit
73d3816e0f
@ -13,7 +13,7 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "DocIterator.h"
|
||||
#include "Cursor.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TexRow.h"
|
||||
|
||||
@ -400,6 +400,22 @@ std::pair<int,int> TexRow::rowFromDocIterator(DocIterator const & dit) const
|
||||
}
|
||||
|
||||
|
||||
std::pair<int,int> TexRow::rowFromCursor(Cursor const & cur) const
|
||||
{
|
||||
DocIterator beg = cur.selectionBegin();
|
||||
std::pair<int,int> beg_rows = rowFromDocIterator(beg);
|
||||
if (cur.selection()) {
|
||||
DocIterator end = cur.selectionEnd();
|
||||
if (!cur.selIsMultiCell())
|
||||
end.top().backwardPos();
|
||||
std::pair<int,int> end_rows = rowFromDocIterator(end);
|
||||
return std::make_pair(std::min(beg_rows.first, end_rows.first),
|
||||
std::max(beg_rows.second, end_rows.second));
|
||||
} else
|
||||
return std::make_pair(beg_rows.first, beg_rows.second);
|
||||
}
|
||||
|
||||
|
||||
// debugging functions
|
||||
|
||||
///
|
||||
|
@ -23,6 +23,7 @@
|
||||
namespace lyx {
|
||||
|
||||
class LyXErr;
|
||||
class Cursor;
|
||||
class CursorSlice;
|
||||
class DocIterator;
|
||||
class docstring_list;
|
||||
@ -145,6 +146,11 @@ public:
|
||||
/// Finds the best pair of rows for dit
|
||||
/// returns (-1,-1) if not found.
|
||||
std::pair<int,int> rowFromDocIterator(DocIterator const & dit) const;
|
||||
|
||||
/// Finds the best pair of rows for cursor, taking the selection into
|
||||
/// account
|
||||
/// returns (-1,-1) if not found.
|
||||
std::pair<int,int> rowFromCursor(Cursor const & dit) const;
|
||||
|
||||
/// Returns the number of rows contained
|
||||
int rows() const { return rowlist_.size(); }
|
||||
|
@ -257,20 +257,9 @@ void ViewSourceWidget::realUpdateView()
|
||||
} else if (texrow_.get()) {
|
||||
// Use the available position-to-row conversion to highlight
|
||||
// the current selection in the source
|
||||
int beg_row, end_row;
|
||||
{
|
||||
DocIterator beg = bv_->cursor().selectionBegin();
|
||||
DocIterator end = bv_->cursor().selectionEnd();
|
||||
std::pair<int,int> beg_rows = texrow_->rowFromDocIterator(beg);
|
||||
beg_row = beg_rows.first;
|
||||
if (beg != end) {
|
||||
end.backwardChar();
|
||||
std::pair<int,int> end_rows = texrow_->rowFromDocIterator(end);
|
||||
end_row = end_rows.second;
|
||||
} else {
|
||||
end_row = beg_rows.second;
|
||||
}
|
||||
}
|
||||
std::pair<int,int> rows = texrow_->rowFromCursor(bv_->cursor());
|
||||
int const beg_row = rows.first;
|
||||
int const end_row = rows.second;
|
||||
|
||||
QTextCursor c = QTextCursor(viewSourceTV->document());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user