diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Document.cxx | 53 | ||||
| -rw-r--r-- | src/Document.h | 8 | ||||
| -rw-r--r-- | src/Editor.cxx | 11 | 
3 files changed, 63 insertions, 9 deletions
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;  | 
