Skip to content

Commit

Permalink
Improve Document Peeker performance issue for large files
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed May 17, 2017
1 parent 8dbd956 commit a067de8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions PowerEditor/src/Parameters.cpp
Expand Up @@ -2025,6 +2025,9 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHeight"), &mapPosVal);
if (mapPosStr)
mapPosition._height = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapKByteInDoc"), &mapPosVal);
if (mapPosStr)
mapPosition._KByteInDoc = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWrapIndentMode"), &mapPosVal);
if (mapPosStr)
mapPosition._wrapIndentMode = mapPosVal;
Expand Down Expand Up @@ -2979,6 +2982,7 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHigherPos"), viewSessionFiles[i]._mapPos._higherPos);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWidth"), viewSessionFiles[i]._mapPos._width);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHeight"), viewSessionFiles[i]._mapPos._height);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapKByteInDoc"), static_cast<int>(viewSessionFiles[i]._mapPos._KByteInDoc));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWrapIndentMode"), viewSessionFiles[i]._mapPos._wrapIndentMode);
fileNameNode->ToElement()->SetAttribute(TEXT("mapIsWrap"), viewSessionFiles[i]._mapPos._isWrap ? TEXT("yes") : TEXT("no"));

Expand Down
9 changes: 8 additions & 1 deletion PowerEditor/src/Parameters.h
Expand Up @@ -149,8 +149,15 @@ struct MapPosition
int32_t _width = -1;
int32_t _height = -1;
int32_t _wrapIndentMode = -1;

int64_t _KByteInDoc = _maxPeekLenInKB;

bool _isWrap = false;
bool isValid() { return _firstVisibleDisplayLine != -1; };
bool isValid() const { return (_firstVisibleDisplayLine != -1); };
bool canScroll() const { return (_KByteInDoc < _maxPeekLenInKB); }; // _nbCharInDoc < _maxPeekLen : Don't scroll the document for the performance issue

private:
int64_t _maxPeekLenInKB = 512; // 512 KB
};


Expand Down
10 changes: 8 additions & 2 deletions PowerEditor/src/WinControls/DocumentMap/documentSnapshot.cpp
Expand Up @@ -68,6 +68,7 @@ void DocumentPeeker::goTo(POINT p)
::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y + 10, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW);
}


void DocumentPeeker::syncDisplay(Buffer *buf, ScintillaEditView & scintSource)
{
if (_pPeekerView)
Expand All @@ -85,8 +86,10 @@ void DocumentPeeker::syncDisplay(Buffer *buf, ScintillaEditView & scintSource)
// Wraping & scrolling
//
MapPosition mp = buf->getMapPosition();
if (mp.isValid())
if (mp.isValid() && mp.canScroll())
{
scrollSnapshotWith(mp);
}

Buffer *buf = _pPeekerView->getCurrentBuffer();
_pPeekerView->defineDocType(buf->getLangType());
Expand Down Expand Up @@ -140,7 +143,7 @@ void DocumentPeeker::scrollSnapshotWith(const MapPosition & mapPos)
//

// scroll to the first visible display line
_pPeekerView->execute(SCI_LINESCROLL, 0,mapPos._firstVisibleDisplayLine);
_pPeekerView->execute(SCI_LINESCROLL, 0, mapPos._firstVisibleDisplayLine);

}
}
Expand Down Expand Up @@ -180,6 +183,9 @@ void DocumentPeeker::saveCurrentSnapshot(ScintillaEditView & editView)
mapPos._higherPos = static_cast<int32_t>(editView.execute(SCI_POSITIONFROMPOINT, 0, 0));
}

// Length of document
mapPos._KByteInDoc = editView.getCurrentDocLen() / 1024;

// set current map position in buffer
buffer->setMapPosition(mapPos);
}
Expand Down

0 comments on commit a067de8

Please sign in to comment.