From 86248087b229eb72018ac9f1e7a829ad336fe983 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 15 Nov 2009 17:01:52 +0000 Subject: [PATCH] [NEW] Make Marker Jumper wrap able. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@562 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 110 ++++++++++++++++++++----------- PowerEditor/src/Notepad_plus.h | 4 +- 2 files changed, 73 insertions(+), 41 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 87b261fb9..8c3539b52 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -9739,66 +9739,98 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return result; } -void Notepad_plus::goToPreviousIndicator(int indicID2Search) const +bool Notepad_plus::goToPreviousIndicator(int indicID2Search, bool isWrap) const { int position = _pEditView->execute(SCI_GETCURRENTPOS); + int docLen = _pEditView->getCurrentDocLen(); + BOOL isInIndicator = _pEditView->execute(SCI_INDICATORVALUEAT, indicID2Search, position); int posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, position); - int posEnd; + int posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, position); + + // pre-condition + if ((posStart == 0) && (posEnd == docLen - 1)) + return false; + + if (posStart <= 0) + { + if (!isWrap) + return false; + + isInIndicator = _pEditView->execute(SCI_INDICATORVALUEAT, indicID2Search, docLen - 1); + posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, docLen - 1); + } - if (isInIndicator) + if (isInIndicator) // try to get out of indicator { - if (posStart <= 0) - return; posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, posStart - 1); if (posStart <= 0) - return; - int newPos = posStart - 1; - posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, newPos); - posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, newPos); - } - else - { - if (posStart <= 0) - return; - int newPos = posStart - 1; - posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, newPos); - posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, newPos); - } - _pEditView->execute(SCI_SETSEL, posEnd, posStart); - _pEditView->execute(SCI_SCROLLCARET); + { + if (!isWrap) + return false; + posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, docLen - 1); + } + } + + int newPos = posStart - 1; + posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, newPos); + posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, newPos); + + // found + if (_pEditView->execute(SCI_INDICATORVALUEAT, indicID2Search, posStart)) + { + _pEditView->execute(SCI_SETSEL, posEnd, posStart); + _pEditView->execute(SCI_SCROLLCARET); + return true; + } + return false; } -void Notepad_plus::goToNextIndicator(int indicID2Search) const +bool Notepad_plus::goToNextIndicator(int indicID2Search, bool isWrap) const { int position = _pEditView->execute(SCI_GETCURRENTPOS); int docLen = _pEditView->getCurrentDocLen(); + BOOL isInIndicator = _pEditView->execute(SCI_INDICATORVALUEAT, indicID2Search, position); - int posStart; + int posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, position); int posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, position); - if (isInIndicator) + // pre-condition + if ((posStart == 0) && (posEnd == docLen - 1)) + return false; + + if (posEnd >= docLen) + { + if (!isWrap) + return false; + + isInIndicator = _pEditView->execute(SCI_INDICATORVALUEAT, indicID2Search, 0); + posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, 0); + } + + if (isInIndicator) // try to get out of indicator { - if (posEnd >= docLen) - return; posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, posEnd); if (posEnd >= docLen) - return; - int newPos = posEnd; - posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, newPos); - posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, newPos); - } - else - { - if (posEnd >= docLen) - return; - int newPos = posEnd + 1; - posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, newPos); - posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, newPos); + { + if (!isWrap) + return false; + posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, 0); + } } - _pEditView->execute(SCI_SETSEL, posStart, posEnd); - _pEditView->execute(SCI_SCROLLCARET); + int newPos = posEnd + 1; + posStart = _pEditView->execute(SCI_INDICATORSTART, indicID2Search, newPos); + posEnd = _pEditView->execute(SCI_INDICATOREND, indicID2Search, newPos); + + // found + if (_pEditView->execute(SCI_INDICATORVALUEAT, indicID2Search, posStart)) + { + _pEditView->execute(SCI_SETSEL, posStart, posEnd); + _pEditView->execute(SCI_SCROLLCARET); + return true; + } + return false; } LRESULT CALLBACK Notepad_plus::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index e53db2f49..aaf80e890 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -573,8 +573,8 @@ private: void loadCommandlineParams(const TCHAR * commandLine, CmdLineParams * pCmdParams); bool noOpenedDoc() const; - void goToPreviousIndicator(int indicID2Search) const; - void goToNextIndicator(int indicID2Search) const; + bool goToPreviousIndicator(int indicID2Search, bool isWrap = true) const; + bool goToNextIndicator(int indicID2Search, bool isWrap = true) const; }; #endif //NOTEPAD_PLUS_H