diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 886801957..814571cff 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -4259,6 +4259,7 @@ void Notepad_plus::setLanguage(int id, LangType langType) { if (bothActive()) { if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) { reset = true; + _subEditView.saveCurrentPos(); prev = _subEditView.execute(SCI_GETDOCPOINTER); _subEditView.execute(SCI_SETDOCPOINTER, 0, 0); } @@ -4271,6 +4272,7 @@ void Notepad_plus::setLanguage(int id, LangType langType) { if (reset) { _subEditView.execute(SCI_SETDOCPOINTER, 0, prev); + _subEditView.restoreCurrentPos(); } }; @@ -7916,7 +7918,9 @@ void Notepad_plus::getCurrentOpenedFiles(Session & session) //_mainEditView.activateBuffer(mainBuf->getID()); //restore buffer //_subEditView.activateBuffer(subBuf->getID()); //restore buffer _mainEditView.execute(SCI_SETDOCPOINTER, 0, mainBuf->getDocument()); + _mainEditView.restoreCurrentPos(); _subEditView.execute(SCI_SETDOCPOINTER, 0, subBuf->getDocument()); + _subEditView.restoreCurrentPos(); } bool Notepad_plus::fileLoadSession(const char *fn) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index daff49e66..b9495dc41 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -356,10 +356,12 @@ Buffer * FileManager::getBufferByIndex(int index) { return _buffers.at(index); } +/* Buffer * FileManager::getBufferByID(BufferID id) { return (Buffer*)id; //return _buffers.at(getBufferIndexByID(id)); } +*/ void FileManager::beNotifiedOfBufferChange(Buffer * theBuf, int mask) { _pNotepadPlus->notifyBufferChanged(theBuf, mask); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index f6953badc..7861f7094 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -57,6 +57,7 @@ struct HeaderLineState { const int userLangNameMax = 16; //File manager class maintains all buffers +class Buffer; class FileManager { public: void init(Notepad_plus * pNotepadPlus, ScintillaEditView * pscratchTilla); @@ -67,7 +68,7 @@ public: int getNrBuffers() { return _nrBufs; }; int getBufferIndexByID(BufferID id); Buffer * getBufferByIndex(int index); //generates exception if index is invalid - Buffer * getBufferByID(BufferID id); //generates exception if id is invalid + Buffer * getBufferByID(BufferID id) {return (Buffer*)id;} void beNotifiedOfBufferChange(Buffer * theBuf, int mask); diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index d8a681500..d87a675b5 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -986,8 +986,8 @@ void ScintillaEditView::saveCurrentPos() Position pos; // the correct visible line number pos._firstVisibleLine = docLine; - pos._startPos = static_cast(execute(SCI_GETSELECTIONSTART)); - pos._endPos = static_cast(execute(SCI_GETSELECTIONEND)); + pos._startPos = static_cast(execute(SCI_GETANCHOR)); + pos._endPos = static_cast(execute(SCI_GETCURRENTPOS)); pos._xOffset = static_cast(execute(SCI_GETXOFFSET)); pos._selMode = execute(SCI_GETSELECTIONMODE); pos._scrollWidth = execute(SCI_GETSCROLLWIDTH); @@ -1002,9 +1002,10 @@ void ScintillaEditView::restoreCurrentPos() execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document - execute(SCI_SETSELECTIONMODE, pos._selMode); - execute(SCI_SETSELECTIONSTART, pos._startPos); - execute(SCI_SETSELECTIONEND, pos._endPos); + execute(SCI_SETSELECTIONMODE, pos._selMode); //enable + execute(SCI_SETANCHOR, pos._startPos); + execute(SCI_SETCURRENTPOS, pos._endPos); + execute(SCI_CANCEL); //disable if (!isWrap()) { //only offset if not wrapping, otherwise the offset isnt needed at all execute(SCI_SETSCROLLWIDTH, pos._scrollWidth); execute(SCI_SETXOFFSET, pos._xOffset);