]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Fix typo.
[lyx.git] / src / BufferView.cpp
index 56ecd94e29694099a67855963092d3db506cbf6a..f304798c82355559ff51b1d7a6018b63a2b96e15 100644 (file)
@@ -707,9 +707,7 @@ Change const BufferView::getCurrentChange() const
 
        DocIterator dit = d->cursor_.selectionBegin();
        // The selected content might have been changed (see #7685)
-       while (dit.inMathed())
-               // Find enclosing text cursor
-               dit.pop_back();
+       dit = dit.getInnerText();
        return dit.paragraph().lookupChange(dit.pos());
 }
 
@@ -1132,11 +1130,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
        case LFUN_CHANGE_PREVIOUS:
        case LFUN_ALL_CHANGES_ACCEPT:
        case LFUN_ALL_CHANGES_REJECT:
-               // TODO: context-sensitive enabling of LFUNs
-               // In principle, these command should only be enabled if there
-               // is a change in the document. However, without proper
-               // optimizations, this will inevitably result in poor performance.
-               flag.setEnabled(true);
+               flag.setEnabled(buffer_.areChangesPresent());
                break;
 
        case LFUN_SCREEN_UP:
@@ -1777,21 +1771,25 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
        }
 
 
-       case LFUN_INSET_SELECT_ALL:
-               if (cur.depth() > 1
+       case LFUN_INSET_SELECT_ALL: {
+               // true if all cells are selected
+               bool const all_selected = cur.depth() > 1
                    && cur.selBegin().at_begin()
-                   && cur.selEnd().at_end()) {
-                       // All the contents of the inset if selected.
+                   && cur.selEnd().at_end();
+               // true if some cells are selected
+               bool const cells_selected = cur.depth() > 1
+                   && cur.selBegin().at_cell_begin()
+                       && cur.selEnd().at_cell_end();
+               if (all_selected || (cells_selected && !cur.inset().isTable())) {
+                       // All the contents of the inset if selected, or only at
+                       // least one cell but inset is not a table.
                        // Select the inset from outside.
                        cur.pop();
                        cur.resetAnchor();
                        cur.setSelection(true);
                        cur.posForward();
-               } else if (cur.selBegin().idx() != cur.selEnd().idx()
-                          || (cur.depth() > 1
-                                  && cur.selBegin().at_cell_begin()
-                              && cur.selEnd().at_cell_end())) {
-                       // At least one complete cell is selected.
+               } else if (cells_selected) {
+                       // At least one complete cell is selected and inset is a table.
                        // Select all cells
                        cur.idx() = 0;
                        cur.pos() = 0;
@@ -1811,6 +1809,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                cur.setCurrentFont();
                dr.screenUpdate(Update::Force);
                break;
+       }
 
 
        // This would be in Buffer class if only Cursor did not
@@ -1850,9 +1849,17 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        if (!cur.nextInset() || cur.nextInset() == ins)
                                cur.forwardInset();
                }
-               cur.endUndoGroup();
                cur = savecur;
                cur.fixIfBroken();
+               /** This is a dummy undo record only to remember the cursor
+                * that has just been set; this will be used on a redo action
+                * (see ticket #10097)
+
+                * FIXME: a better fix would be to have a way to set the
+                * cursor value directly, but I am not sure it is worth it.
+                */
+               cur.recordUndo();
+               cur.endUndoGroup();
                dr.screenUpdate(Update::Force);
                dr.forceBufferUpdate();
 
@@ -2203,9 +2210,14 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
                // inset (depending on cmd.x(), cmd.y()). This is needed for
                // editing to fix bug 9628, but e.g. the context menu needs a
                // cursor in front of the inset.
-               if ((inset->hasSettings() || !inset->contextMenuName().empty()) &&
+               if ((inset->hasSettings() || !inset->contextMenuName().empty()
+                    || inset->lyxCode() == SEPARATOR_CODE) &&
                    cur.nextInset() != inset && cur.prevInset() == inset)
                        cur.posBackward();
+       } else if (cur.inTexted() && cur.pos()
+                       && cur.paragraph().isEnvSeparator(cur.pos() - 1)) {
+               // Always place cursor in front of a separator inset.
+               cur.posBackward();
        }
 
        // Put anchor at the same position.
@@ -2512,12 +2524,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select)
        // FIXME: (2) if we had a working InsetText::notifyCursorLeaves,
        // the leftinset bool would not be necessary (badcursor instead).
        bool update = leftinset;
-       if (!do_selection && d->cursor_.inTexted()) {
+       if (!do_selection && d->cursor_.inTexted())
                update |= checkDepm(cur, d->cursor_);
-               if (cur.inTexted() && cur.pos()
-                       && cur.paragraph().isEnvSeparator(cur.pos() - 1))
-                   cur.posBackward();
-       }
 
        if (!do_selection)
                d->cursor_.resetAnchor();