commit e52a38549328a58b6fe8efeecef21a71fb9c8d65
Author: Jean-Marc Lasgouttes <[email protected]>
Date: Sun Oct 19 20:43:17 2014 +0200
Reimplement inset-select-all in a generic way
There are 3 possible actions (in order)
* select current cell
* select all calls of inset
* select the inset from outside (in the containing inset)
This fixes completely #7727.
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index faa08f0..47e6512 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1087,6 +1087,7 @@ bool BufferView::getStatus(FuncRequest const & cmd,
FuncStatus & flag)
case LFUN_KEYMAP_PRIMARY:
case LFUN_KEYMAP_SECONDARY:
case LFUN_KEYMAP_TOGGLE:
+ case LFUN_INSET_SELECT_ALL:
flag.setEnabled(true);
break;
@@ -1800,6 +1801,38 @@ void BufferView::dispatch(FuncRequest const & cmd,
DispatchResult & dr)
}
+ case LFUN_INSET_SELECT_ALL:
+ if (cur.depth() > 1
+ && cur.selBegin().at_begin()
+ && cur.selEnd().at_end()) {
+ // All the contents of the inset if selected.
+ // Select the inset from outside.
+ cur.pop();
+ cur.resetAnchor();
+ cur.setSelection(true);
+ cur.posForward();
+ } else if (cur.selBegin().idx() != cur.selEnd().idx()
+ || (cur.selBegin().at_cell_begin()
+ && cur.selEnd().at_cell_end())) {
+ // At least one complete cell is selected.
+ // Select all cells
+ cur.pos() = 0;
+ cur.idx() = 0;
+ cur.resetAnchor();
+ cur.setSelection(true);
+ cur.idx() = cur.lastidx();
+ cur.pos() = cur.lastpos();
+ } else {
+ // select current cell
+ cur.pos() = 0;
+ cur.resetAnchor();
+ cur.setSelection(true);
+ cur.pos() = cur.lastpos();
+ }
+ dr.screenUpdate(Update::Force);
+ break;
+
+
// This would be in Buffer class if only Cursor did not
// require a bufferview
case LFUN_INSET_FORALL: {
diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp
index 0e46c07..e7ef90e 100644
--- a/src/CursorSlice.cpp
+++ b/src/CursorSlice.cpp
@@ -158,15 +158,27 @@ void CursorSlice::backwardPos()
}
-bool CursorSlice::at_end() const
+bool CursorSlice::at_cell_end() const
{
- return idx_ == lastidx() && pit_ == lastpit() && pos_ == lastpos();
+ return pit_ == lastpit() && pos_ == lastpos();
+}
+
+
+bool CursorSlice::at_cell_begin() const
+{
+ return pit_ == 0 && pos_ == 0;
+}
+
+
+bool CursorSlice::at_end() const
+{
+ return idx_ == lastidx() && at_cell_end();
}
bool CursorSlice::at_begin() const
{
- return idx_ == 0 && pit_ == 0 && pos_ == 0;
+ return idx_ == 0 && at_cell_begin();
}
diff --git a/src/CursorSlice.h b/src/CursorSlice.h
index 01634bd..d703cb4 100644
--- a/src/CursorSlice.h
+++ b/src/CursorSlice.h
@@ -132,6 +132,10 @@ public:
void forwardIdx();
/// move to previous cell
void backwardIdx();
+ /// are we at the end of the cell
+ bool at_cell_end() const;
+ /// are we at the start of the cell
+ bool at_cell_begin() const;
/// are we at the end of this slice
bool at_end() const;
/// are we at the start of this slice
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 6bf3bc6..20885dd 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -599,18 +599,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
cur.screenUpdateFlags(Update::FitCursor);
break;
- case LFUN_INSET_SELECT_ALL:
- if (cur.depth() == 1 || !cur.selection() ||
!cur.selBegin().at_begin()
- || !cur.selEnd().at_end()) {
- needsUpdate |= cur.selHandle(false);
- needsUpdate |= cursorTop(cur);
- needsUpdate |= cur.selHandle(true);
- needsUpdate |= cursorBottom(cur);
- } else
- cur.undispatched();
- cur.screenUpdateFlags(Update::FitCursor);
- break;
-
case LFUN_CHAR_FORWARD:
case LFUN_CHAR_FORWARD_SELECT:
//LYXERR0(" LFUN_CHAR_FORWARD[SEL]:\n" << cur);
@@ -3118,7 +3106,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const &
cmd,
case LFUN_INSET_END:
case LFUN_INSET_BEGIN_SELECT:
case LFUN_INSET_END_SELECT:
- case LFUN_INSET_SELECT_ALL:
case LFUN_PARAGRAPH_UP:
case LFUN_PARAGRAPH_DOWN:
case LFUN_LINE_BEGIN:
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index fc398e4..5bcab87 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -731,7 +731,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest &
cmd)
case LFUN_MOUSE_DOUBLE:
case LFUN_MOUSE_TRIPLE:
case LFUN_WORD_SELECT:
- case LFUN_INSET_SELECT_ALL:
cur.pos() = 0;
cur.idx() = 0;
cur.resetAnchor();