[BUG_FIXED] (Author: Ivan Radić, aka Loreia) Fix link hotspot colourising issue.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@970 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 12 years ago
parent a97b25ed92
commit 25ae135f82

@ -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

@ -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<pair<int, int> > hotspotStylers;
std::vector<unsigned char> 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<unsigned char>(_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<int, int> 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<int>(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);

@ -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)

@ -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);

@ -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

@ -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)

@ -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);
}

@ -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;
}

@ -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<HeaderLineState> lineStateVector = getCurrentFoldStates();
std::vector<HeaderLineState> 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<HeaderLineState> & lineStateVectorNew = newBuf->getHeaderLineState(this);
syncFoldStateWith(lineStateVectorNew);
@ -1619,9 +1632,8 @@ void ScintillaEditView::activateBuffer(BufferID buffer)
return; //all done
}
std::vector<HeaderLineState> ScintillaEditView::getCurrentFoldStates()
void ScintillaEditView::getCurrentFoldStates(std::vector<HeaderLineState> & lineStateVector)
{
std::vector<HeaderLineState> lineStateVector;
int maxLine = execute(SCI_GETLINECOUNT);
for (int line = 0; line < maxLine; line++)
@ -1633,7 +1645,6 @@ std::vector<HeaderLineState> ScintillaEditView::getCurrentFoldStates()
lineStateVector.push_back(HeaderLineState(line, expanded));
}
}
return lineStateVector;
}
void ScintillaEditView::syncFoldStateWith(const std::vector<HeaderLineState> & 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.

@ -242,7 +242,7 @@ public:
void activateBuffer(BufferID buffer);
std::vector<HeaderLineState> getCurrentFoldStates();
void getCurrentFoldStates(std::vector<HeaderLineState> & lineStateVector);
void syncFoldStateWith(const std::vector<HeaderLineState> & lineStateVectorNew);
void getText(char *dest, int start, int end) const;

@ -47,7 +47,9 @@ void DocumentMap::reloadMap()
_pScintillaEditView->setCurrentBuffer(editBuf);
// folding
_pScintillaEditView->syncFoldStateWith((*_ppEditView)->getCurrentFoldStates());
std::vector<HeaderLineState> lineStateVector;
(*_ppEditView)->getCurrentFoldStates(lineStateVector);
_pScintillaEditView->syncFoldStateWith(lineStateVector);
// Wrapping
if ((*_ppEditView)->isWrap() && needToRecomputeWith())

Loading…
Cancel
Save