diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index d4443d76a..e8acd8c72 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -36,6 +36,8 @@ const bool dirDown = false; #define NPP_CP_DOS_437 437 #define NPP_CP_BIG5 950 +#define LINKTRIGGERED WM_USER+555 + #ifdef UNICODE #define NppMainEntry wWinMain #define generic_strtol wcstol diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 1917a823a..c31f641f2 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -122,7 +122,7 @@ Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(N _pMainSplitter(NULL), _recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _pFileSwitcherPanel(NULL), _pProjectPanel_1(NULL), _pProjectPanel_2(NULL), _pProjectPanel_3(NULL), _pDocMap(NULL), - _linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _isFolding(false), + _linkTriggered(true), _isHotspotDblClicked(false), _isFolding(false), _sysMenuEntering(false), _autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg), _isFileOpening(false), _rememberThisSession(true), _pAnsiCharPanel(NULL), _pClipboardHistoryPanel(NULL) @@ -2025,40 +2025,12 @@ void Notepad_plus::setUniModeText() } -void Notepad_plus::addHotSpot(bool docIsModifing) +void Notepad_plus::addHotSpot() { - //bool docIsModifing = true; - int posBegin2style = 0; - if (docIsModifing) - posBegin2style = _pEditView->execute(SCI_GETCURRENTPOS); - + int startPos = 0; + int endPos = -1; int endStyle = _pEditView->execute(SCI_GETENDSTYLED); - if (docIsModifing) - { - - posBegin2style = _pEditView->execute(SCI_GETCURRENTPOS); - if (posBegin2style > 0) posBegin2style--; - UCHAR ch = (UCHAR)_pEditView->execute(SCI_GETCHARAT, posBegin2style); - - // determinating the type of EOF to make sure how many steps should we be back - if ((ch == 0x0A) || (ch == 0x0D)) - { - int eolMode = _pEditView->execute(SCI_GETEOLMODE); - if ((eolMode == SC_EOL_CRLF) && (posBegin2style > 1)) - posBegin2style -= 2; - else if (posBegin2style > 0) - posBegin2style -= 1; - } - - ch = (UCHAR)_pEditView->execute(SCI_GETCHARAT, posBegin2style); - while ((posBegin2style > 0) && ((ch != 0x0A) && (ch != 0x0D))) - { - ch = (UCHAR)_pEditView->execute(SCI_GETCHARAT, posBegin2style--); - } - } - - int startPos = 0, endPos = -1; _pEditView->getVisibleStartAndEndPosition(&startPos, &endPos); _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); @@ -2066,9 +2038,30 @@ void Notepad_plus::addHotSpot(bool docIsModifing) _pEditView->execute(SCI_SETTARGETSTART, startPos); _pEditView->execute(SCI_SETTARGETEND, endPos); - vector > hotspotStylers; + std::vector hotspotPairs; //= _pEditView->GetHotspotPairs(); + + unsigned char style_hotspot = 0; + unsigned char mask = INDIC1_MASK; + + // INDIC2_MASK == 255 and it represents MSB bit + // only LEX_HTML and LEX_POSTSCRIPT use use INDIC2_MASK bit internally + // LEX_HTML is using INDIC2_MASK bit even though it has only 127 states, so it is safe to overwrite 8th bit + // INDIC2_MASK will be used for LEX_HTML + + // LEX_POSTSCRIPT is using INDIC2_MASK bit for "tokenization", and is using mask=31 in lexer, + // therefore hotspot in LEX_POSTSCRIPT will be saved to 5th bit + // there are only 15 states in LEX_POSTSCRIPT, so it is safe to overwrite 5th bit + + // rule of the thumb is, any lexet that calls: styler.StartAt(startPos, 255); + // must have special processing here, all other lexers are fine with INDIC1_MASK (7th bit) + + LangType type = _pEditView->getCurrentBuffer()->getLangType(); + + if (type == L_HTML) + mask = INDIC2_MASK; + else if (type == L_PS) + mask = 16; - int style_hotspot = 30; int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(URL_REG_EXPR), (LPARAM)URL_REG_EXPR); while (posFound != -1) @@ -2076,75 +2069,72 @@ void Notepad_plus::addHotSpot(bool docIsModifing) int start = int(_pEditView->execute(SCI_GETTARGETSTART)); int end = int(_pEditView->execute(SCI_GETTARGETEND)); int foundTextLen = end - start; - int idStyle = _pEditView->execute(SCI_GETSTYLEAT, posFound); + unsigned char idStyle = static_cast(_pEditView->execute(SCI_GETSTYLEAT, posFound)); - if (end < posBegin2style - 1) + // Search the style + int fs = -1; + for (size_t i = 0 ; i < hotspotPairs.size() ; i++) { - if (style_hotspot > 24) - style_hotspot--; - } - else - { - int fs = -1; - for (size_t i = 0 ; i < hotspotStylers.size() ; i++) + // make sure to ignore "hotspot bit" when comparing document style with archived hotspot style + if ((hotspotPairs[i] & ~mask) == (idStyle & ~mask)) { - if (hotspotStylers[i].second == idStyle) - { - fs = hotspotStylers[i].first; + fs = hotspotPairs[i]; + _pEditView->execute(SCI_STYLEGETFORE, fs); break; - } } + } - if (fs != -1) - { - _pEditView->execute(SCI_STARTSTYLING, start, 0xFF); - _pEditView->execute(SCI_SETSTYLING, foundTextLen, fs); + // if we found it then use it to colourize + if (fs != -1) + { + _pEditView->execute(SCI_STARTSTYLING, start, 0xFF); + _pEditView->execute(SCI_SETSTYLING, foundTextLen, fs); - } - else - { - pair p(style_hotspot, idStyle); - hotspotStylers.push_back(p); - int activeFG = 0xFF0000; - char fontNameA[128]; + } + else // generize a new style and add it into a array + { + style_hotspot = idStyle | mask; // set "hotspot bit" + hotspotPairs.push_back(style_hotspot); + int activeFG = 0xFF0000; + unsigned char idStyleMSBunset = idStyle & ~mask; + char fontNameA[128]; - Style hotspotStyle; + Style hotspotStyle; - hotspotStyle._styleID = style_hotspot; - _pEditView->execute(SCI_STYLEGETFONT, idStyle, (LPARAM)fontNameA); - TCHAR *generic_fontname = new TCHAR[128]; + hotspotStyle._styleID = static_cast(style_hotspot); + _pEditView->execute(SCI_STYLEGETFONT, idStyleMSBunset, (LPARAM)fontNameA); + TCHAR *generic_fontname = new TCHAR[128]; #ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const wchar_t * fontNameW = wmc->char2wchar(fontNameA, _nativeLangSpeaker.getLangEncoding()); - lstrcpy(generic_fontname, fontNameW); + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * fontNameW = wmc->char2wchar(fontNameA, _nativeLangSpeaker.getLangEncoding()); + lstrcpy(generic_fontname, fontNameW); #else - lstrcpy(generic_fontname, fontNameA); + lstrcpy(generic_fontname, fontNameA); #endif - hotspotStyle._fontName = generic_fontname; - - hotspotStyle._fgColor = _pEditView->execute(SCI_STYLEGETFORE, idStyle); - hotspotStyle._bgColor = _pEditView->execute(SCI_STYLEGETBACK, idStyle); - hotspotStyle._fontSize = _pEditView->execute(SCI_STYLEGETSIZE, idStyle); - - int isBold = _pEditView->execute(SCI_STYLEGETBOLD, idStyle); - int isItalic = _pEditView->execute(SCI_STYLEGETITALIC, idStyle); - int isUnderline = _pEditView->execute(SCI_STYLEGETUNDERLINE, idStyle); - hotspotStyle._fontStyle = (isBold?FONTSTYLE_BOLD:0) | (isItalic?FONTSTYLE_ITALIC:0) | (isUnderline?FONTSTYLE_UNDERLINE:0); - - int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; - if (urlAction == 2) - hotspotStyle._fontStyle |= FONTSTYLE_UNDERLINE; - - _pEditView->setHotspotStyle(hotspotStyle); - - _pEditView->execute(SCI_STYLESETHOTSPOT, style_hotspot, TRUE); - _pEditView->execute(SCI_SETHOTSPOTACTIVEFORE, TRUE, activeFG); - _pEditView->execute(SCI_SETHOTSPOTSINGLELINE, style_hotspot, 0); - _pEditView->execute(SCI_STARTSTYLING, start, 0x1F); - _pEditView->execute(SCI_SETSTYLING, foundTextLen, style_hotspot); - if (style_hotspot > 24) - style_hotspot--; - } + hotspotStyle._fontName = generic_fontname; + + hotspotStyle._fgColor = _pEditView->execute(SCI_STYLEGETFORE, idStyleMSBunset); + hotspotStyle._bgColor = _pEditView->execute(SCI_STYLEGETBACK, idStyleMSBunset); + hotspotStyle._fontSize = _pEditView->execute(SCI_STYLEGETSIZE, idStyleMSBunset); + + int isBold = _pEditView->execute(SCI_STYLEGETBOLD, idStyleMSBunset); + int isItalic = _pEditView->execute(SCI_STYLEGETITALIC, idStyleMSBunset); + int isUnderline = _pEditView->execute(SCI_STYLEGETUNDERLINE, idStyleMSBunset); + hotspotStyle._fontStyle = (isBold?FONTSTYLE_BOLD:0) | (isItalic?FONTSTYLE_ITALIC:0) | (isUnderline?FONTSTYLE_UNDERLINE:0); + + int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; + if (urlAction == 2) + hotspotStyle._fontStyle |= FONTSTYLE_UNDERLINE; + + _pEditView->setHotspotStyle(hotspotStyle); + + _pEditView->execute(SCI_STYLESETHOTSPOT, style_hotspot, TRUE); + _pEditView->execute(SCI_SETHOTSPOTACTIVEFORE, TRUE, activeFG); + _pEditView->execute(SCI_SETHOTSPOTSINGLELINE, style_hotspot, 0); + + // colourize it! + _pEditView->execute(SCI_STARTSTYLING, start, 0xFF); + _pEditView->execute(SCI_SETSTYLING, foundTextLen, style_hotspot); } _pEditView->execute(SCI_SETTARGETSTART, posFound + foundTextLen); diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 66f326769..2b8435ee2 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -375,7 +375,6 @@ private: // For hotspot bool _linkTriggered; - bool _isDocModifing; bool _isHotspotDblClicked; bool _isFolding; @@ -518,7 +517,7 @@ private: }; void MaintainIndentation(TCHAR ch); - void addHotSpot(bool docIsModifing = false); + void addHotSpot(); void bookmarkAdd(int lineno) const { if (lineno == -1) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 299a73416..1ff11f06b 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1279,6 +1279,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa checkUndoState(); //4 } + if (wParam == LINKTRIGGERED) + notification->wParam = LINKTRIGGERED; + _pluginsManager.notify(notification); return notify(notification); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 69e68a7e1..35d473a73 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -168,8 +168,6 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi } PathRemoveFileSpec(longFileName); _linkTriggered = true; - _isDocModifing = false; - _isFileOpening = false; // Notify plugins that current file is just opened diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 3fa250d7c..7891bde4a 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -50,7 +50,6 @@ BOOL Notepad_plus::notify(SCNotification *notification) { prevWasEdit = true; _linkTriggered = true; - _isDocModifing = true; ::InvalidateRect(notifyView->getHSelf(), NULL, TRUE); } @@ -398,7 +397,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) { int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; if ((urlAction == 1) || (urlAction == 2)) - addHotSpot(_isDocModifing); + addHotSpot(); } if (_pDocMap) @@ -473,7 +472,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; if ((urlAction == 1) || (urlAction == 2)) - addHotSpot(_isDocModifing); + addHotSpot(); + break; } @@ -568,13 +568,12 @@ BOOL Notepad_plus::notify(SCNotification *notification) NppParameters *nppParam = NppParameters::getInstance(); // if it's searching/replacing, then do nothing - if (_linkTriggered && !nppParam->_isFindReplacing) + if ((_linkTriggered && !nppParam->_isFindReplacing) || notification->wParam == LINKTRIGGERED) { int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; if ((urlAction == 1) || (urlAction == 2)) - addHotSpot(_isDocModifing); + addHotSpot(); _linkTriggered = false; - _isDocModifing = false; } if (_pDocMap) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 8731a0c4b..d51e962bf 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -79,7 +79,7 @@ void Buffer::setLangType(LangType lang, const TCHAR * userLangName) { _userLangExt = userLangName; } - _needLexer = true; //change of lang means lexern eeds updating + _needLexer = true; //change of lang means lexern needs updating doNotify(BufferChangeLanguage|BufferChangeLexing); } diff --git a/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp b/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp index c63aec1e6..a665553b5 100644 --- a/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp @@ -65,6 +65,14 @@ BOOL CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) (*_ppEditView)->execute(SCI_GOTOPOS, line); } } + + // find hotspots + NMHDR nmhdr; + nmhdr.code = SCN_PAINTED; + nmhdr.hwndFrom = _hSelf; + nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom); + ::SendMessage(_hParent, WM_NOTIFY, (WPARAM)LINKTRIGGERED, (LPARAM)&nmhdr); + (*_ppEditView)->getFocus(); return TRUE; } diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 54588f2b1..c424d311d 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -381,6 +381,20 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa break; } + case WM_KEYUP : + { + if (wParam == VK_PRIOR || wParam == VK_NEXT) + { + // find hotspots + NMHDR nmhdr; + nmhdr.code = SCN_PAINTED; + nmhdr.hwndFrom = _hSelf; + nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom); + ::SendMessage(_hParent, WM_NOTIFY, (WPARAM)LINKTRIGGERED, (LPARAM)&nmhdr); + } + break; + } + case WM_VSCROLL : { break; @@ -1483,18 +1497,9 @@ void ScintillaEditView::defineDocType(LangType typeDoc) setSpecialStyle(styleLN); } setTabSettings(_pParameter->getLangFromID(typeDoc)); - int bitsNeeded = execute(SCI_GETSTYLEBITSNEEDED); - execute(SCI_SETSTYLEBITS, bitsNeeded); - - // Reapply the hotspot styles. - if (_hotspotStyles.find(_currentBuffer) != _hotspotStyles.end()) - { - StyleMap* currentStyleMap = _hotspotStyles[_currentBuffer]; - for (StyleMap::iterator it(currentStyleMap->begin()); it != currentStyleMap->end(); ++it) - { - setStyle(it->second); - } - } + execute(SCI_SETSTYLEBITS, 8); // Always use 8 bit mask in Document class (Document::stylingBitsMask), + // in that way Editor::PositionIsHotspot will return correct hotspot styleID. + // This value has no effect on LexAccessor::mask. } BufferID ScintillaEditView::attachDefaultDoc() @@ -1580,7 +1585,8 @@ void ScintillaEditView::activateBuffer(BufferID buffer) saveCurrentPos(); // get foldStateInfo of current doc - std::vector lineStateVector = getCurrentFoldStates(); + std::vector lineStateVector; + getCurrentFoldStates(lineStateVector); // put the state into the future ex buffer _currentBuffer->setHeaderLineState(lineStateVector, this); @@ -1601,6 +1607,13 @@ void ScintillaEditView::activateBuffer(BufferID buffer) restyleBuffer(); } + // find hotspots + NMHDR nmhdr; + nmhdr.code = SCN_PAINTED; + nmhdr.hwndFrom = _hSelf; + nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom); + ::SendMessage(_hParent, WM_NOTIFY, (WPARAM)LINKTRIGGERED, (LPARAM)&nmhdr); + // restore the collapsed info const std::vector & lineStateVectorNew = newBuf->getHeaderLineState(this); syncFoldStateWith(lineStateVectorNew); @@ -1619,9 +1632,8 @@ void ScintillaEditView::activateBuffer(BufferID buffer) return; //all done } -std::vector ScintillaEditView::getCurrentFoldStates() +void ScintillaEditView::getCurrentFoldStates(std::vector & lineStateVector) { - std::vector lineStateVector; int maxLine = execute(SCI_GETLINECOUNT); for (int line = 0; line < maxLine; line++) @@ -1633,7 +1645,6 @@ std::vector ScintillaEditView::getCurrentFoldStates() lineStateVector.push_back(HeaderLineState(line, expanded)); } } - return lineStateVector; } void ScintillaEditView::syncFoldStateWith(const std::vector & lineStateVectorNew) @@ -1778,7 +1789,7 @@ void ScintillaEditView::fold(int line, bool mode) void ScintillaEditView::foldAll(bool mode) { // The following code is needed : - execute(SCI_COLOURISE, 0, -1); + //execute(SCI_COLOURISE, 0, -1); // according to the Scitilla document : // This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) // to style the document between startPos and endPos. If endPos is -1, the document is styled from startPos to the end. diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index edfee4dc9..eb5795bce 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -242,7 +242,7 @@ public: void activateBuffer(BufferID buffer); - std::vector getCurrentFoldStates(); + void getCurrentFoldStates(std::vector & lineStateVector); void syncFoldStateWith(const std::vector & lineStateVectorNew); void getText(char *dest, int start, int end) const; diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp index 26f562fa5..680d689ef 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp @@ -47,7 +47,9 @@ void DocumentMap::reloadMap() _pScintillaEditView->setCurrentBuffer(editBuf); // folding - _pScintillaEditView->syncFoldStateWith((*_ppEditView)->getCurrentFoldStates()); + std::vector lineStateVector; + (*_ppEditView)->getCurrentFoldStates(lineStateVector); + _pScintillaEditView->syncFoldStateWith(lineStateVector); // Wrapping if ((*_ppEditView)->isWrap() && needToRecomputeWith())