aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2003-11-01 11:40:37 +0000
committernyamatongwe <unknown>2003-11-01 11:40:37 +0000
commit1cb0c37b721cfa4909a260a48aa82999f61cacc0 (patch)
treed176377cdf80118ee4a7fc9363f14492317c5fb3
parent40780f412ede5e9a0aee4378d22909172ad3ace3 (diff)
downloadscintilla-mirror-1cb0c37b721cfa4909a260a48aa82999f61cacc0.tar.gz
Patch from Roy Wood to allow changing the characters that are in the
whitespace class.
-rw-r--r--doc/ScintillaDoc.html9
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface2
-rw-r--r--src/Document.cxx53
-rw-r--r--src/Document.h8
-rw-r--r--src/Editor.cxx11
6 files changed, 75 insertions, 9 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index bbdf57a90..221d141db 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -2217,6 +2217,8 @@ struct TextToFind {
<a class="message" href="#SCI_GETCODEPAGE">SCI_GETCODEPAGE</a><br />
<a class="message" href="#SCI_SETWORDCHARS">SCI_SETWORDCHARS(&lt;unused&gt;, const char
*chars)</a><br />
+ <a class="message" href="#SCI_SETWHITESPACECHARS">SCI_SETWHITESPACECHARS(&lt;unused&gt;, const char
+ *chars)</a><br />
<a class="message" href="#SCI_GRABFOCUS">SCI_GRABFOCUS</a><br />
<a class="message" href="#SCI_SETFOCUS">SCI_SETFOCUS(bool focus)</a><br />
<a class="message" href="#SCI_GETFOCUS">SCI_GETFOCUS</a><br />
@@ -2308,6 +2310,13 @@ struct TextToFind {
use:<br />
<code>SCI_SETWORDCHARS(0, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")</code>;</p>
+ <p><b id="SCI_SETWHITESPACECHARS">SCI_SETWHITESPACECHARS(&lt;unused&gt;, const char *chars)</b><br />
+ Similar to <code>SCI_SETWORDCHARS</code>, this message allows the user to define which chars Scintilla considers
+ as whitespace. If <code>chars</code> is null then the default set, space and all char codes less than
+ 0x20, are used. Setting the whitespace chars allows the user to fine-tune Scintilla's behaviour doing
+ such things as moving the cursor to the start or end of a word; for example, by defining punctuation chars
+ as whitespace, they will be skipped over when the user presses ctrl+left or ctrl+right.
+
<p><b id="SCI_GRABFOCUS">SCI_GRABFOCUS</b><br />
<b id="SCI_SETFOCUS">SCI_SETFOCUS(bool focus)</b><br />
<b id="SCI_GETFOCUS">SCI_GETFOCUS</b><br />
diff --git a/include/Scintilla.h b/include/Scintilla.h
index d0b788e47..44a608d9f 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -567,6 +567,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_WORDLEFTENDEXTEND 2440
#define SCI_WORDRIGHTEND 2441
#define SCI_WORDRIGHTENDEXTEND 2442
+#define SCI_SETWHITESPACECHARS 2443
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
#define SCI_SETLEXER 4001
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 1e4d0db34..93173d07e 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1538,6 +1538,8 @@ fun void WordRightEnd=2441(,)
# Move caret right one word, position cursor at end of word, extending selection to new caret position.
fun void WordRightEndExtend=2442(,)
+# Set the set of characters making up whitespace for when moving or selecting by word.
+set void SetWhitespaceChars=2443(, string characters)
# Start notifying the container of all key presses and commands.
fun void StartRecord=3001(,)
diff --git a/src/Document.cxx b/src/Document.cxx
index 130a920e1..53d01d2b8 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -50,7 +50,7 @@ Document::Document() {
stylingBits = 5;
stylingBitsMask = 0x1F;
stylingMask = 0;
- SetWordChars(0);
+ SetDefaultCharClasses();
endStyled = 0;
styleClock = 0;
enteredCount = 0;
@@ -1119,29 +1119,74 @@ void Document::ChangeCase(Range r, bool makeUpperCase) {
}
}
-void Document::SetWordChars(unsigned char *chars) {
+
+void Document::SetDefaultCharClasses() {
int ch;
+ // Initialize all char classes to default values
for (ch = 0; ch < 256; ch++) {
if (ch == '\r' || ch == '\n')
charClass[ch] = ccNewLine;
else if (ch < 0x20 || ch == ' ')
charClass[ch] = ccSpace;
+ else if (ch >= 0x80 || isalnum(ch) || ch == '_')
+ charClass[ch] = ccWord;
else
charClass[ch] = ccPunctuation;
}
+}
+
+void Document::SetCharClasses(unsigned char *chars, charClassification newCharClass) {
+ int ch;
+ // The old code always reset all chars to their default charClass and then applied the new charClass
+ // to a specific set of chars, so the most reasonable way to honour the old promise is to reset all chars
+ // that currently are of class newCharClass, and then apply the newCharClass to any specified chars. Remember,
+ // the point is to allow the caller to explicitly define all chars which are to be of class newCharClass.
+ // The only other tricky thing is that the old promise was that if the user passes in NULL for the chars
+ // parameter, we are supposed to reset all chars that default to newCharClass, which is not the
+ // same as resetting the char class of any chars that are currently of newCharClass (user might have altered
+ // some char classes from their default class).
+
+ // If all of that seems a little complex, well, it is. If we could break the old promise and make some
+ // simplifying assumptions, this would all be waaaaay simpler. This way though, Scintilla will do the right
+ // thing if lots of changes of charClass are applied during the lifetime of the Document object (not very likely,
+ // but as long as I'm doing this, might as well get it right).
+
+ // So, first reset the char class of any chars that are currently of the class newCharClass
+ for (ch = 0; ch < 256; ch++) {
+ if (charClass[ch] == newCharClass) {
+ if (ch == '\r' || ch == '\n')
+ charClass[ch] = ccNewLine;
+ else if (ch < 0x20 || ch == ' ')
+ charClass[ch] = ccSpace;
+ else if (ch >= 0x80 || isalnum(ch) || ch == '_')
+ charClass[ch] = ccWord;
+ else
+ charClass[ch] = ccPunctuation;
+ }
+ }
+
+ // Next, apply the newCharClass to the specifed chars
if (chars) {
while (*chars) {
- charClass[*chars] = ccWord;
+ charClass[*chars] = newCharClass;
chars++;
}
} else {
+ // If user passed NULL for chars, reinitialize only the specified class of chars
for (ch = 0; ch < 256; ch++) {
- if (ch >= 0x80 || isalnum(ch) || ch == '_')
+ if ((ch == '\r' || ch == '\n') && newCharClass == ccNewLine)
+ charClass[ch] = ccNewLine;
+ else if ((ch < 0x20 || ch == ' ') && newCharClass == ccSpace)
+ charClass[ch] = ccSpace;
+ else if ((ch >= 0x80 || isalnum(ch) || ch == '_') && newCharClass == ccWord)
charClass[ch] = ccWord;
+ else if (newCharClass == ccPunctuation)
+ charClass[ch] = ccPunctuation;
}
}
}
+
void Document::SetStylingBits(int bits) {
stylingBits = bits;
stylingBitsMask = 0;
diff --git a/src/Document.h b/src/Document.h
index f811bf077..dc9e38e21 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -87,11 +87,12 @@ public:
userData = 0;
}
};
+
+ enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };
private:
int refCount;
CellBuffer cb;
- enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };
charClassification charClass[256];
char stylingMask;
int endStyled;
@@ -199,8 +200,9 @@ public:
int LinesTotal();
void ChangeCase(Range r, bool makeUpperCase);
-
- void SetWordChars(unsigned char *chars);
+
+ void SetDefaultCharClasses();
+ void SetCharClasses(unsigned char *chars, charClassification newCharClass);
void SetStylingBits(int bits);
void StartStyling(int position, char mask);
bool SetStyleFor(int length, char style);
diff --git a/src/Editor.cxx b/src/Editor.cxx
index b1811e075..c4e6860e9 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1122,7 +1122,7 @@ This way, we favour the displaying of useful information: the begining of lines,
where most code reside, and the lines after the caret, eg. the body of a function.
| | | | |
-slop | strict | jumps | even | Caret can go to the margin | When reaching limit (caret going out of
+slop | strict | jumps | even | Caret can go to the margin | When reaching limitƯ(caret going out of
| | | | | visibility or going into the UZ) display is...
-----+--------+-------+------+--------------------------------------------+--------------------------------------------------------------
0 | 0 | 0 | 0 | Yes | moved to put caret on top/on right
@@ -5733,7 +5733,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_SETWORDCHARS: {
if (lParam == 0)
return 0;
- pdoc->SetWordChars(reinterpret_cast<unsigned char *>(lParam));
+ pdoc->SetCharClasses(reinterpret_cast<unsigned char *>(lParam), Document::ccWord);
+ }
+ break;
+
+ case SCI_SETWHITESPACECHARS: {
+ if (lParam == 0)
+ return 0;
+ pdoc->SetCharClasses(reinterpret_cast<unsigned char *>(lParam), Document::ccSpace);
}
break;