]> git.lyx.org Git - features.git/commitdiff
Introduce jump-back navigation through bookmark 0
authorPavel Sanda <sanda@lyx.org>
Fri, 13 Feb 2009 13:46:08 +0000 (13:46 +0000)
committerPavel Sanda <sanda@lyx.org>
Fri, 13 Feb 2009 13:46:08 +0000 (13:46 +0000)
http://bugzilla.lyx.org/show_bug.cgi?id=898
http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg147949.html

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28478 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ui/stdcontext.inc
src/BufferView.cpp
src/BufferView.h
src/LyXFunc.cpp
src/Text3.cpp

index 9d4d5fa645597bc4afe9f3099f84baf06a053924..301608c211cfc0439ced133f084fe3d962544386 100644 (file)
@@ -88,7 +88,7 @@ Menuset
 #
        Menu "context-label"
                Item "Next Cross-Reference|N" "reference-next"
-               Item "Go back to Reference|G" "bookmark-goto 0"
+               Item "Go back|G" "bookmark-goto 0"
                Separator
                Item "Copy as Reference|C" "copy-label-as-reference"
                Separator
@@ -275,7 +275,7 @@ Menuset
                Item "Paste" "paste"
                Submenu "Paste Recent|e" "edit_pasterecent"
                Separator
-               Item "Jump to Saved Bookmark|B" "bookmark-goto 0"
+               Item "Jump Back to Saved Bookmark|B" "bookmark-goto 0"
                Separator
                Item "Move Paragraph Up|o" "paragraph-move-up"
                Item "Move Paragraph Down|v" "paragraph-move-down"
index 35edfe9fbf5ca72a1865bd1cb8ed4c710669d387..2a5b39f48915efce7f76b1903585bc5f5466971f 100644 (file)
@@ -218,7 +218,7 @@ struct BufferView::Private
        Private(BufferView & bv): wh_(0), cursor_(bv),
                anchor_pit_(0), anchor_ypos_(0),
                inlineCompletionUniqueChars_(0),
-               last_inset_(0), gui_(0)
+               last_inset_(0), bookmark_edit_position_(0), gui_(0)
        {}
 
        ///
@@ -261,6 +261,9 @@ struct BufferView::Private
          */
        Inset * last_inset_;
 
+       // cache for id of the paragraph which was edited the last time
+       int bookmark_edit_position_;
+
        mutable TextMetricsCache text_metrics_;
 
        /// Whom to notify.
@@ -670,6 +673,16 @@ CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
 }
 
 
+void BufferView::bookmarkEditPosition()
+{
+       // Don't eat cpu time for each keystroke
+       if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
+               return;
+       saveBookmark(0);
+       d->bookmark_edit_position_ = d->cursor_.paragraph().id();
+}
+
+
 void BufferView::saveBookmark(unsigned int idx)
 {
        // tentatively save bookmark, id and pos will be used to
index d13d7d9782cc709d6ca4a4b2d16f29722c9e5f53..0f6b55b80ad95e74c42410e336fad9c5c88f0f50 100644 (file)
@@ -289,6 +289,8 @@ public:
        void insertPlaintextFile(support::FileName const & f, bool asParagraph);
        ///
        void insertLyXFile(support::FileName const & f);
+       /// save temporary bookmark for jump back navigation
+       void bookmarkEditPosition();
 
 private:
        /// noncopyable
index 411da71e6878aff4ae8a1a0b87cf6827c82e2114..5fc04c1eac542e861f685f56a625e552266337ca 100644 (file)
@@ -257,15 +257,27 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer)
        if (!theBufferList().exists(bm.filename))
                return;
 
+       // bm can be changed when saving
+       BookmarksSection::Bookmark tmp = bm;
+
+       // Special case idx == 0 used for back-from-back jump navigation
+       if (idx == 0)
+               dispatch(FuncRequest(LFUN_BOOKMARK_SAVE, "0"));
+
        // if the current buffer is not that one, switch to it.
-       if (lyx_view_->buffer()->fileName() != bm.filename) {
+       if (lyx_view_->buffer()->fileName() != tmp.filename) {
                if (!switchToBuffer)
                        return;
                dispatch(FuncRequest(LFUN_BUFFER_SWITCH, file));
        }
+
        // moveToPosition try paragraph id first and then paragraph (pit, pos).
-       if (!view()->moveToPosition(bm.bottom_pit, bm.bottom_pos,
-               bm.top_id, bm.top_pos))
+       if (!view()->moveToPosition(tmp.bottom_pit, tmp.bottom_pos,
+               tmp.top_id, tmp.top_pos))
+               return;
+
+       // bm changed
+       if (idx == 0)
                return;
 
        // Cursor jump succeeded!
index c4373d50b1b5f630c98d1a96627af92194700da6..c212f156f1bccdb58ed80566da4be5212c5d1cd0 100644 (file)
@@ -1385,6 +1385,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
                cur.resetAnchor();
                moveCursor(cur, false);
+               bv->bookmarkEditPosition();
                break;
        }