aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <unknown>2000-08-18 10:45:24 +0000
committernyamatongwe <unknown>2000-08-18 10:45:24 +0000
commit74537dd24ba7943e79652b06f4b752be2035bcea (patch)
treec5d0492dca4b04bf79e1ef367a7190df8472bc3f /src
parentd15b65e7fba53354b9a044ba5d8232d256b58d5e (diff)
downloadscintilla-mirror-74537dd24ba7943e79652b06f4b752be2035bcea.tar.gz
Added in most of Ferdinand Prantl's changes except for regular expression
search. Some bits not quite done as well.
Diffstat (limited to 'src')
-rw-r--r--src/AutoComplete.cxx11
-rw-r--r--src/AutoComplete.h6
-rw-r--r--src/Editor.cxx17
-rw-r--r--src/Editor.h3
-rw-r--r--src/LexOthers.cxx45
-rw-r--r--src/PropSet.cxx33
-rw-r--r--src/ScintillaBase.cxx50
-rw-r--r--src/ScintillaBase.h2
8 files changed, 141 insertions, 26 deletions
diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx
index f9dbd4d67..6866364c1 100644
--- a/src/AutoComplete.cxx
+++ b/src/AutoComplete.cxx
@@ -14,7 +14,9 @@ AutoComplete::AutoComplete() {
active = false;
posStart = 0;
strcpy(stopChars, "");
+ strcpy(fillUpChars, "");
separator = ' ';
+ ignoreCase = false;
cancelAtStartPos = true;
}
@@ -45,6 +47,15 @@ bool AutoComplete::IsStopChar(char ch) {
return ch && strchr(stopChars, ch);
}
+void AutoComplete::SetFillUpChars(const char *fillUpChars_) {
+ strncpy(fillUpChars, fillUpChars_, sizeof(fillUpChars));
+ fillUpChars[sizeof(fillUpChars) - 1] = '\0';
+}
+
+bool AutoComplete::IsFillUpChar(char ch) {
+ return ch && strchr(fillUpChars, ch);
+}
+
void AutoComplete::SetSeparator(char separator_) {
separator = separator_;
}
diff --git a/src/AutoComplete.h b/src/AutoComplete.h
index 37795fce6..434679f93 100644
--- a/src/AutoComplete.h
+++ b/src/AutoComplete.h
@@ -9,8 +9,10 @@
class AutoComplete {
bool active;
char stopChars[256];
+ char fillUpChars[256];
char separator;
public:
+ bool ignoreCase;
ListBox lb;
int posStart;
int startLen;
@@ -30,6 +32,10 @@ public:
void SetStopChars(const char *stopChars_);
bool IsStopChar(char ch);
+ // The fillup chars are characters which, when typed, fill up the selected word
+ void SetFillUpChars(const char *fillUpChars_);
+ bool IsFillUpChar(char ch);
+
// The separator character is used when interpreting the list in SetList
void SetSeparator(char separator_);
char GetSeparator();
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 44e28dbc2..6969458d3 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -988,7 +988,7 @@ void Editor::DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVis
for (int indica = 0; indica <= INDIC_MAX; indica++)
indStart[indica] = 0;
- for (int indicPos = 0; indicPos <= ll.numCharsInLine; indicPos++) {
+ for (int indicPos = 0; indicPos < ll.numCharsInLine; indicPos++) {
if (ll.indicators[indicPos] != ll.indicators[indicPos + 1]) {
int mask = 1 << pdoc->stylingBits;
for (int indicnum = 0; mask < 0x100; indicnum++) {
@@ -1718,6 +1718,13 @@ void Editor::NotifyModifyAttempt(Document*, void *) {
NotifyModifyAttempt();
}
+void Editor::NotifyMove(int position) {
+ SCNotification scn;
+ scn.nmhdr.code = SCN_POSCHANGED;
+ scn.position = position;
+ NotifyParent(scn);
+}
+
void Editor::NotifySavePoint(Document*, void *, bool atSavePoint) {
//Platform::DebugPrintf("** Save Point %s\n", atSavePoint ? "On" : "Off");
NotifySavePoint(atSavePoint);
@@ -2122,6 +2129,7 @@ int Editor::KeyCommand(unsigned int iMessage) {
inOverstrike = !inOverstrike;
DropCaret();
ShowCaretAtCurrentPosition();
+ NotifyUpdateUI();
break;
case SCI_CANCEL: // Cancel any modes - handled in subclass
// Also unselect text
@@ -4222,6 +4230,13 @@ long Editor::WndProc(unsigned int iMessage, unsigned long wParam, long lParam) {
case SCI_SELECTIONISRECTANGLE:
return (selType == selRectangle) ? 1 : 0;
+ case SCI_SETOVERTYPE:
+ inOverstrike = wParam;
+ break;
+
+ case SCI_GETOVERTYPE:
+ return inOverstrike ? TRUE : FALSE;
+
#ifdef MACRO_SUPPORT
case SCI_STARTRECORD:
recordingMacro = 1;
diff --git a/src/Editor.h b/src/Editor.h
index 5b79f2ede..83967cfd6 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -178,7 +178,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
void SetSelection(int currentPos_, int anchor_);
void SetSelection(int currentPos_);
void SetEmptySelection(int currentPos_);
- int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
+ int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
int MovePositionTo(int newPos, bool extend = false);
int MovePositionSoVisible(int pos, int moveDir);
void SetLastXChosen();
@@ -228,6 +228,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
virtual void NotifyParent(SCNotification scn) = 0;
virtual void NotifyStyleToNeeded(int endStyleNeeded);
void NotifyChar(char ch);
+ void NotifyMove(int position);
void NotifySavePoint(bool isSavePoint);
void NotifyModifyAttempt();
virtual void NotifyDoubleClick(Point pt, bool shift);
diff --git a/src/LexOthers.cxx b/src/LexOthers.cxx
index 90f41e3bf..edbf5d06f 100644
--- a/src/LexOthers.cxx
+++ b/src/LexOthers.cxx
@@ -49,6 +49,46 @@ static void ColouriseBatchDoc(unsigned int startPos, int length, int, WordList *
ColouriseBatchLine(lineBuffer, startPos + length, styler);
}
+static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) {
+ // It is needed to remember the current state to recognize starting
+ // comment lines before the first "diff " or "--- ". If a real
+ // difference starts then each line starting with ' ' is a whitespace
+ // otherwise it is considered a comment (Only in..., Binary file...)
+ if (0 == strncmp(lineBuffer, "diff ", 3)) {
+ styler.ColourTo(endLine, 2);
+ } else if (0 == strncmp(lineBuffer, "--- ", 3)) {
+ styler.ColourTo(endLine, 3);
+ } else if (0 == strncmp(lineBuffer, "+++ ", 3)) {
+ styler.ColourTo(endLine, 3);
+ } else if (lineBuffer[0] == '@') {
+ styler.ColourTo(endLine, 4);
+ } else if (lineBuffer[0] == '-') {
+ styler.ColourTo(endLine, 5);
+ } else if (lineBuffer[0] == '+') {
+ styler.ColourTo(endLine, 6);
+ } else if (lineBuffer[0] != ' ') {
+ styler.ColourTo(endLine, 1);
+ } else {
+ styler.ColourTo(endLine, 0);
+ }
+}
+
+static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
+ char lineBuffer[1024];
+ styler.StartAt(startPos);
+ styler.StartSegment(startPos);
+ unsigned int linePos = 0;
+ for (unsigned int i = startPos; i < startPos + length; i++) {
+ lineBuffer[linePos++] = styler[i];
+ if (styler[i] == '\r' || styler[i] == '\n' || (linePos >= sizeof(lineBuffer) - 1)) {
+ ColouriseDiffLine(lineBuffer, i, styler);
+ linePos = 0;
+ }
+ }
+ if (linePos > 0)
+ ColouriseDiffLine(lineBuffer, startPos + length, styler);
+}
+
static void ColourisePropsLine(char *lineBuffer, int lengthLine, int startLine, int endPos, Accessor &styler) {
int i = 0;
while (isspace(lineBuffer[i]) && (i < lengthLine)) // Skip initial spaces
@@ -297,8 +337,9 @@ static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,
styler.ColourTo(lengthDoc, state);
}
+LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc);
+LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc);
LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc);
-LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);
LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc);
-LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc);
+LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc);
LexerModule lmLatex(SCLEX_LATEX, ColouriseLatexDoc);
diff --git a/src/PropSet.cxx b/src/PropSet.cxx
index c9aa71b5e..60e6922a6 100644
--- a/src/PropSet.cxx
+++ b/src/PropSet.cxx
@@ -333,7 +333,7 @@ static bool iswordsep(char ch, bool onlyLineEnds) {
// Creates an array that points into each word in the string and puts \0 terminators
// after each word.
-static char **ArrayFromWordList(char *wordlist, bool onlyLineEnds = false) {
+static char **ArrayFromWordList(char *wordlist, int *len, bool onlyLineEnds = false) {
char prev = '\n';
int words = 0;
for (int j = 0; wordlist[j]; j++) {
@@ -345,8 +345,8 @@ static char **ArrayFromWordList(char *wordlist, bool onlyLineEnds = false) {
if (keywords) {
words = 0;
prev = '\0';
- int len = strlen(wordlist);
- for (int k = 0; k < len; k++) {
+ int slen = strlen(wordlist);
+ for (int k = 0; k < slen; k++) {
if (!iswordsep(wordlist[k], onlyLineEnds)) {
if (!prev) {
keywords[words] = &wordlist[k];
@@ -357,7 +357,10 @@ static char **ArrayFromWordList(char *wordlist, bool onlyLineEnds = false) {
}
prev = wordlist[k];
}
- keywords[words] = &wordlist[len];
+ keywords[words] = &wordlist[slen];
+ *len = words;
+ } else {
+ *len = 0;
}
return keywords;
}
@@ -370,12 +373,13 @@ void WordList::Clear() {
words = 0;
list = 0;
len = 0;
+ sorted = false;
}
void WordList::Set(const char *s) {
- len = 0;
list = StringDup(s);
- words = ArrayFromWordList(list, onlyLineEnds);
+ sorted = false;
+ words = ArrayFromWordList(list, &len, onlyLineEnds);
}
char *WordList::Allocate(int size) {
@@ -385,10 +389,11 @@ char *WordList::Allocate(int size) {
}
void WordList::SetFromAllocated() {
- len = 0;
- words = ArrayFromWordList(list, onlyLineEnds);
+ sorted = false;
+ words = ArrayFromWordList(list, &len, onlyLineEnds);
}
+#ifdef __MINGW32__
// Shell sort based upon public domain C implementation by Raymond Gardner 1991
// Used here because of problems with mingw qsort.
static void SortWordList(char **words, unsigned int len) {
@@ -416,13 +421,19 @@ static void SortWordList(char **words, unsigned int len) {
gap = gap / 2;
}
}
+#else
+// traditional qsort - hope it works elsewhere...
+static void SortWordList(char **words, unsigned int len) {
+ qsort (reinterpret_cast<void*>(words), len, sizeof(*words),
+ reinterpret_cast<int (*)(const void*, const void*)>(strcmp));
+}
+#endif
bool WordList::InList(const char *s) {
if (0 == words)
return false;
- if (len == 0) {
- for (int i = 0; words[i][0]; i++)
- len++;
+ if (!sorted) {
+ sorted = true;
SortWordList(words, len);
for (unsigned int k = 0; k < (sizeof(starts) / sizeof(starts[0])); k++)
starts[k] = -1;
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 8d42f0b7b..bf81887f2 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -11,9 +11,9 @@
#include "Platform.h"
#include "Scintilla.h"
+#include "PropSet.h"
#ifdef SCI_LEXER
#include "SciLexer.h"
-#include "PropSet.h"
#include "Accessor.h"
#include "WindowAccessor.h"
#include "DocumentAccessor.h"
@@ -60,6 +60,8 @@ void ScintillaBase::RefreshColourPalette(Palette &pal, bool want) {
void ScintillaBase::AddCharUTF(char *s, unsigned int len) {
bool acActiveBeforeCharAdded = ac.Active();
+ if (!acActiveBeforeCharAdded || !ac.IsFillUpChar(*s))
+ Editor::AddCharUTF(s, len);
Editor::AddCharUTF(s, len);
if (acActiveBeforeCharAdded)
AutoCompleteChanged(s[0]);
@@ -136,6 +138,9 @@ int ScintillaBase::KeyCommand(unsigned int iMessage) {
case SCI_TAB:
AutoCompleteCompleted();
return 0;
+ case SCI_NEWLINE:
+ AutoCompleteCompleted();
+ return 0;
default:
ac.Cancel();
@@ -238,7 +243,9 @@ void ScintillaBase::AutoCompleteMoveToCurrentWord() {
}
void ScintillaBase::AutoCompleteChanged(char ch) {
- if (currentPos <= ac.posStart - ac.startLen) {
+ if (ac.IsFillUpChar(ch)) {
+ AutoCompleteCompleted(ch);
+ } else if (currentPos <= ac.posStart - ac.startLen) {
ac.Cancel();
} else if (ac.cancelAtStartPos && currentPos <= ac.posStart) {
ac.Cancel();
@@ -249,20 +256,39 @@ void ScintillaBase::AutoCompleteChanged(char ch) {
}
}
-void ScintillaBase::AutoCompleteCompleted() {
+void ScintillaBase::AutoCompleteCompleted(char fillUp/*='\0'*/) {
int item = ac.lb.GetSelection();
char selected[1000];
if (item != -1) {
ac.lb.GetValue(item, selected, sizeof(selected));
}
ac.Cancel();
- if (currentPos != ac.posStart) {
- pdoc->DeleteChars(ac.posStart, currentPos - ac.posStart);
- }
- SetEmptySelection(ac.posStart);
- if (item != -1) {
- pdoc->InsertString(currentPos, selected + ac.startLen);
- SetEmptySelection(currentPos + strlen(selected + ac.startLen));
+
+ if (ac.ignoreCase) {
+ if (currentPos != ac.posStart) {
+ pdoc->DeleteChars(ac.posStart, currentPos - ac.posStart);
+ }
+ SetEmptySelection(ac.posStart - ac.startLen);
+ pdoc->DeleteChars(ac.posStart - ac.startLen, ac.startLen);
+ if (item != -1) {
+ SString piece = selected;
+ if (fillUp)
+ piece += fillUp;
+ pdoc->InsertString(currentPos, piece.c_str());
+ SetEmptySelection(currentPos + piece.length());
+ }
+ } else {
+ if (currentPos != ac.posStart) {
+ pdoc->DeleteChars(ac.posStart, currentPos - ac.posStart);
+ }
+ SetEmptySelection(ac.posStart);
+ if (item != -1) {
+ SString piece = selected + ac.startLen;
+ if (fillUp)
+ piece += fillUp;
+ pdoc->InsertString(currentPos, piece.c_str());
+ SetEmptySelection(currentPos + piece.length());
+ }
}
}
@@ -366,6 +392,10 @@ long ScintillaBase::WndProc(unsigned int iMessage, unsigned long wParam, long lP
case SCI_AUTOCGETCANCELATSTART:
return ac.cancelAtStartPos;
+ case SCI_AUTOCSETFILLUPS:
+ ac.SetFillUpChars(reinterpret_cast<char *>(lParam));
+ break;
+
case SCI_CALLTIPSHOW: {
AutoCompleteCancel();
if (!ct.wCallTip.Created()) {
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index 80db7137e..e630ba1aa 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -54,7 +54,7 @@ protected:
void AutoCompleteCancel();
void AutoCompleteMove(int delta);
void AutoCompleteChanged(char ch=0);
- void AutoCompleteCompleted();
+ void AutoCompleteCompleted(char fillUp='\0');
void AutoCompleteMoveToCurrentWord();
virtual void CreateCallTipWindow(PRectangle rc) = 0;