2009-04-24 23:35:41 +00:00
|
|
|
// This file is modified from LexOthers.cxx of Scintilla source code edit control
|
|
|
|
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
//this file is part of notepad++
|
|
|
|
//Copyright (C)2003 Don HO <donho@altern.org >
|
|
|
|
//
|
|
|
|
//This program is free software; you can redistribute it and/or
|
|
|
|
//modify it under the terms of the GNU General Public License
|
|
|
|
//as published by the Free Software Foundation; either
|
|
|
|
//version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
//This program is distributed in the hope that it will be useful,
|
|
|
|
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
//GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
//You should have received a copy of the GNU General Public License
|
|
|
|
//along with this program; if not, write to the Free Software
|
|
|
|
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <vector>
|
2010-08-22 02:20:44 +00:00
|
|
|
#include <assert.h>
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2010-08-22 02:20:44 +00:00
|
|
|
#include "ILexer.h"
|
|
|
|
#include "LexAccessor.h"
|
2010-08-27 01:01:10 +00:00
|
|
|
#include "PropSetSimple.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "Accessor.h"
|
2010-08-22 02:20:44 +00:00
|
|
|
#include "WordList.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "SciLexer.h"
|
2010-08-22 02:20:44 +00:00
|
|
|
#include "CharacterSet.h"
|
|
|
|
#include "LexerModule.h"
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2017-03-13 20:28:02 +00:00
|
|
|
using namespace Scintilla;
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
// The following definitions are a copy of the ones in FindReplaceDlg.h
|
2020-05-04 23:37:47 +00:00
|
|
|
enum { searchHeaderLevel = SC_FOLDLEVELBASE, fileHeaderLevel, resultLevel };
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
static inline bool AtEOL(Accessor &styler, size_t i) {
|
2009-04-24 23:35:41 +00:00
|
|
|
return (styler[i] == '\n') ||
|
|
|
|
((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n'));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * const emptyWordListDesc[] = {
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2019-05-08 08:43:30 +00:00
|
|
|
static void ColouriseSearchResultLine(SearchResultMarkings* pMarkings, char *lineBuffer, size_t startLine, size_t endPos, Accessor &styler, int linenum)
|
2009-04-24 23:35:41 +00:00
|
|
|
{
|
|
|
|
// startLine and endPos are the absolute positions.
|
|
|
|
|
2020-05-04 23:37:47 +00:00
|
|
|
if (lineBuffer[0] == ' ') // white space - file header
|
2009-04-24 23:35:41 +00:00
|
|
|
{
|
|
|
|
styler.ColourTo(endPos, SCE_SEARCHRESULT_FILE_HEADER);
|
|
|
|
}
|
2020-05-04 23:37:47 +00:00
|
|
|
else if (lineBuffer[0] == ' ')// \t - line info
|
2009-04-24 23:35:41 +00:00
|
|
|
{
|
2020-12-09 02:34:18 +00:00
|
|
|
unsigned int firstTokenLen = 0;
|
|
|
|
unsigned int currentPos = 0;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2020-12-09 02:34:18 +00:00
|
|
|
for (; !(lineBuffer[firstTokenLen] >= '0' && lineBuffer[firstTokenLen] <= '9'); firstTokenLen++);
|
|
|
|
|
|
|
|
styler.ColourTo(startLine + firstTokenLen - 1, SCE_SEARCHRESULT_DEFAULT);
|
|
|
|
|
|
|
|
for (currentPos = firstTokenLen; lineBuffer[currentPos] != ':'; currentPos++);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
styler.ColourTo(startLine + currentPos - 1, SCE_SEARCHRESULT_LINE_NUMBER);
|
|
|
|
|
|
|
|
int currentStat = SCE_SEARCHRESULT_DEFAULT;
|
|
|
|
|
|
|
|
SearchResultMarking mi = pMarkings->_markings[linenum];
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
size_t match_start = startLine + mi._start - 1;
|
|
|
|
size_t match_end = startLine + mi._end - 1;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
if (match_start <= endPos) {
|
|
|
|
styler.ColourTo(match_start, SCE_SEARCHRESULT_DEFAULT);
|
|
|
|
if (match_end <= endPos)
|
|
|
|
styler.ColourTo(match_end, SCE_SEARCHRESULT_WORD2SEARCH);
|
|
|
|
else
|
|
|
|
currentStat = SCE_SEARCHRESULT_WORD2SEARCH;
|
|
|
|
}
|
|
|
|
styler.ColourTo(endPos, currentStat);
|
|
|
|
}
|
2020-05-04 23:37:47 +00:00
|
|
|
else // every character - search header
|
|
|
|
{
|
|
|
|
styler.ColourTo(endPos, SCE_SEARCHRESULT_SEARCH_HEADER);
|
|
|
|
}
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
static void ColouriseSearchResultDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], Accessor &styler) {
|
2009-04-24 23:35:41 +00:00
|
|
|
|
|
|
|
char lineBuffer[SC_SEARCHRESULT_LINEBUFFERMAXLENGTH];
|
|
|
|
styler.StartAt(startPos);
|
|
|
|
styler.StartSegment(startPos);
|
|
|
|
unsigned int linePos = 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
size_t startLine = startPos;
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2010-08-27 01:01:10 +00:00
|
|
|
const char *addrMarkingsStruct = (styler.pprops)->Get("@MarkingsStruct");
|
|
|
|
if (!addrMarkingsStruct || !addrMarkingsStruct[0])
|
|
|
|
return;
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
SearchResultMarkings* pMarkings = NULL;
|
2018-02-01 22:05:41 +00:00
|
|
|
sscanf(addrMarkingsStruct, "%p", (void**)&pMarkings);
|
2009-04-24 23:35:41 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
for (size_t i = startPos; i < startPos + length; i++) {
|
2009-04-24 23:35:41 +00:00
|
|
|
lineBuffer[linePos++] = styler[i];
|
|
|
|
if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
|
|
|
|
// End of line (or of line buffer) met, colourise it
|
|
|
|
lineBuffer[linePos] = '\0';
|
2019-05-08 08:43:30 +00:00
|
|
|
ColouriseSearchResultLine(pMarkings, lineBuffer, startLine, i, styler, styler.GetLine(startLine));
|
2009-04-24 23:35:41 +00:00
|
|
|
linePos = 0;
|
|
|
|
startLine = i + 1;
|
|
|
|
while (!AtEOL(styler, i)) i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (linePos > 0) { // Last line does not have ending characters
|
2019-05-08 08:43:30 +00:00
|
|
|
ColouriseSearchResultLine(pMarkings, lineBuffer, startLine, startPos + length - 1, styler, styler.GetLine(startLine));
|
2009-04-24 23:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
static void FoldSearchResultDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], Accessor &styler) {
|
2009-04-24 23:35:41 +00:00
|
|
|
bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
size_t endPos = startPos + length;
|
2009-04-24 23:35:41 +00:00
|
|
|
int visibleChars = 0;
|
|
|
|
int lineCurrent = styler.GetLine(startPos);
|
|
|
|
|
|
|
|
char chNext = styler[startPos];
|
|
|
|
int styleNext = styler.StyleAt(startPos);
|
|
|
|
int headerPoint = 0;
|
|
|
|
int lev;
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
for (size_t i = startPos; i < endPos; i++) {
|
2009-04-24 23:35:41 +00:00
|
|
|
char ch = chNext;
|
|
|
|
chNext = styler[i+1];
|
|
|
|
|
|
|
|
int style = styleNext;
|
|
|
|
styleNext = styler.StyleAt(i + 1);
|
|
|
|
bool atEOL = (ch == '\n') || (ch == '\r' && chNext != '\n');
|
|
|
|
|
|
|
|
if (style == SCE_SEARCHRESULT_FILE_HEADER)
|
|
|
|
{
|
|
|
|
headerPoint = fileHeaderLevel;
|
|
|
|
}
|
|
|
|
else if (style == SCE_SEARCHRESULT_SEARCH_HEADER)
|
|
|
|
{
|
|
|
|
headerPoint = searchHeaderLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atEOL) {
|
|
|
|
lev = headerPoint ? SC_FOLDLEVELHEADERFLAG + headerPoint : resultLevel;
|
|
|
|
headerPoint = 0;
|
|
|
|
|
|
|
|
if (visibleChars == 0 && foldCompact)
|
|
|
|
lev |= SC_FOLDLEVELWHITEFLAG;
|
|
|
|
|
|
|
|
if (lev != styler.LevelAt(lineCurrent)) {
|
|
|
|
styler.SetLevel(lineCurrent, lev);
|
|
|
|
}
|
|
|
|
lineCurrent++;
|
|
|
|
visibleChars = 0;
|
|
|
|
}
|
|
|
|
if (!isspacechar(ch))
|
|
|
|
visibleChars++;
|
|
|
|
}
|
|
|
|
styler.SetLevel(lineCurrent, SC_FOLDLEVELBASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerModule lmSearchResult(SCLEX_SEARCHRESULT, ColouriseSearchResultDoc, "searchResult", FoldSearchResultDoc, emptyWordListDesc);
|