diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 4ceaea36a1..4c0f10506c 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1928,6 +1928,28 @@ bool GuiView::closeBuffer(Buffer & buf, bool tolastopened) } +void GuiView::gotoNextOrPreviousBuffer(NextOrPrevious np) +{ + Buffer * const curbuf = buffer(); + Buffer * nextbuf = curbuf; + while (true) { + if (np == NEXTBUFFER) + nextbuf = theBufferList().next(nextbuf); + else + nextbuf = theBufferList().previous(nextbuf); + if (nextbuf == curbuf) + break; + if (nextbuf == 0) { + nextbuf = curbuf; + break; + } + if (workArea(*nextbuf)) + break; + } + setBuffer(nextbuf); +} + + bool GuiView::dispatch(FuncRequest const & cmd) { BufferView * bv = view(); @@ -1946,11 +1968,11 @@ bool GuiView::dispatch(FuncRequest const & cmd) break; case LFUN_BUFFER_NEXT: - setBuffer(theBufferList().next(buffer())); + gotoNextOrPreviousBuffer(NEXTBUFFER); break; case LFUN_BUFFER_PREVIOUS: - setBuffer(theBufferList().previous(buffer())); + gotoNextOrPreviousBuffer(PREVBUFFER); break; case LFUN_COMMAND_EXECUTE: { diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index 98efa5607c..c3f5d5b53d 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -295,6 +295,12 @@ private: bool saveBuffer(Buffer & b); /// bool closeBuffer(Buffer & buf, bool tolastopened = false); + enum NextOrPrevious { + NEXTBUFFER, + PREVBUFFER + }; + /// + void gotoNextOrPreviousBuffer(NextOrPrevious np); /// Inset * getOpenInset(std::string const & name) const;