diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Document.cxx | 20 | ||||
| -rw-r--r-- | src/Document.h | 3 | ||||
| -rw-r--r-- | src/Editor.cxx | 55 | ||||
| -rw-r--r-- | src/Editor.h | 1 | 
4 files changed, 35 insertions, 44 deletions
| diff --git a/src/Document.cxx b/src/Document.cxx index 4272dda63..def80c49c 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -535,26 +535,18 @@ void Document::DelChar(int pos) {  	DeleteChars(pos, LenChar(pos));  } -int Document::DelCharBackMove(int pos, int len) { -	if (DeleteChars(pos - len, len)) { -		return pos - len; -	} else { -		return pos; -	} -} - -int Document::DelCharBack(int pos) { +void Document::DelCharBack(int pos) {  	if (pos <= 0) { -		return pos; +		return;  	} else if (IsCrLf(pos - 2)) { -		return DelCharBackMove(pos, 2); +		DeleteChars(pos - 2, 2);  	} else if (SC_CP_UTF8 == dbcsCodePage) {  		int startChar = MovePositionOutsideChar(pos - 1, -1, false); -		return DelCharBackMove(pos, pos - startChar); +		DeleteChars(startChar, pos - startChar);  	} else if (IsDBCS(pos - 1)) { -		return DelCharBackMove(pos, 2); +		DeleteChars(pos - 2, 2);  	} else { -		return DelCharBackMove(pos, 1); +		DeleteChars(pos - 1, 1);  	}  } diff --git a/src/Document.h b/src/Document.h index 61fe33fce..9743583fe 100644 --- a/src/Document.h +++ b/src/Document.h @@ -163,7 +163,7 @@ public:  	bool InsertString(int position, const char *s, int insertLength);  	void ChangeChar(int pos, char ch);  	void DelChar(int pos); -	int DelCharBack(int pos); +	void DelCharBack(int pos);  	char CharAt(int position) { return cb.CharAt(position); }  	void GetCharRange(char *buffer, int position, int lengthRetrieve) { @@ -233,7 +233,6 @@ private:  	void NotifySavePoint(bool atSavePoint);  	void NotifyModified(DocModification mh); -	int DelCharBackMove(int pos, int len);  	int IndentSize() { return indentInChars ? indentInChars : tabInChars; }  }; diff --git a/src/Editor.cxx b/src/Editor.cxx index d66b49238..57856dc37 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2417,8 +2417,7 @@ void Editor::DelCharBack(bool allowLineStartDeletion) {  				SetEmptySelection(pdoc->GetLineIndentPosition(lineCurrentPos));  				pdoc->EndUndoAction();  			} else { -				int newPos = pdoc->DelCharBack(currentPos); -				SetEmptySelection(newPos); +				pdoc->DelCharBack(currentPos);  			}  		}  	} else { @@ -2830,8 +2829,9 @@ void Editor::LineTranspose() {  			end = startNext;  			char *thisLine = CopyRange(start, end);  			pdoc->DeleteChars(start, end - start); -			pdoc->InsertString(startPrev, thisLine, end - start); -			MovePositionTo(startPrev + end - start); +			if (pdoc->InsertString(startPrev, thisLine, end - start)) { +				MovePositionTo(startPrev + end - start); +			}  			delete []thisLine;  		} else {  			// Last line so line has no line end @@ -2839,8 +2839,9 @@ void Editor::LineTranspose() {  			char *prevEnd = CopyRange(endPrev, start);  			pdoc->DeleteChars(endPrev, end - endPrev);  			pdoc->InsertString(startPrev, thisLine, end - start); -			pdoc->InsertString(startPrev + end - start, prevEnd, start - endPrev); -			MovePositionTo(startPrev + end - endPrev); +			if (pdoc->InsertString(startPrev + end - start, prevEnd, start - endPrev)) { +				MovePositionTo(startPrev + end - endPrev); +			}  			delete []thisLine;  			delete []prevEnd;  		} @@ -2850,6 +2851,25 @@ void Editor::LineTranspose() {  void Editor::CancelModes() {} +void Editor::NewLine() { +	ClearSelection(); +	const char *eol = "\n"; +	if (pdoc->eolMode == SC_EOL_CRLF) { +		eol = "\r\n"; +	} else if (pdoc->eolMode == SC_EOL_CR) { +		eol = "\r"; +	} // else SC_EOL_LF -> "\n" already set +	if (pdoc->InsertString(currentPos, eol)) { +		SetEmptySelection(currentPos + strlen(eol)); +		while (*eol) { +			NotifyChar(*eol); +			eol++; +		} +	} +	SetLastXChosen(); +	EnsureCaretVisible(); +} +  int Editor::KeyCommand(unsigned int iMessage) {  	Point pt = LocationFromPosition(currentPos); @@ -2993,23 +3013,7 @@ int Editor::KeyCommand(unsigned int iMessage) {  		EnsureCaretVisible();  		break;  	case SCI_NEWLINE: -		ClearSelection(); -		if (pdoc->eolMode == SC_EOL_CRLF) { -			pdoc->InsertString(currentPos, "\r\n"); -			SetEmptySelection(currentPos + 2); -			NotifyChar('\r'); -			NotifyChar('\n'); -		} else if (pdoc->eolMode == SC_EOL_CR) { -			pdoc->InsertChar(currentPos, '\r'); -			SetEmptySelection(currentPos + 1); -			NotifyChar('\r'); -		} else if (pdoc->eolMode == SC_EOL_LF) { -			pdoc->InsertChar(currentPos, '\n'); -			SetEmptySelection(currentPos + 1); -			NotifyChar('\n'); -		} -		SetLastXChosen(); -		EnsureCaretVisible(); +		NewLine();  		break;  	case SCI_FORMFEED:  		AddChar('\f'); @@ -3037,21 +3041,18 @@ int Editor::KeyCommand(unsigned int iMessage) {  	case SCI_DELWORDLEFT: {  			int startWord = pdoc->NextWordStart(currentPos, -1);  			pdoc->DeleteChars(startWord, currentPos - startWord); -			MovePositionTo(startWord);  			SetLastXChosen();  		}  		break;  	case SCI_DELWORDRIGHT: {  			int endWord = pdoc->NextWordStart(currentPos, 1);  			pdoc->DeleteChars(currentPos, endWord - currentPos); -			MovePositionTo(currentPos);  		}  		break;  	case SCI_DELLINELEFT: {  			int line = pdoc->LineFromPosition(currentPos);  			int start = pdoc->LineStart(line);  			pdoc->DeleteChars(start, currentPos - start); -			MovePositionTo(start);  			SetLastXChosen();  		}  		break; @@ -3059,7 +3060,6 @@ int Editor::KeyCommand(unsigned int iMessage) {  			int line = pdoc->LineFromPosition(currentPos);  			int end = pdoc->LineEnd(line);  			pdoc->DeleteChars(currentPos, end - currentPos); -			MovePositionTo(currentPos);  		}  		break;  	case SCI_LINECUT: { @@ -3081,7 +3081,6 @@ int Editor::KeyCommand(unsigned int iMessage) {  			int start = pdoc->LineStart(line);  			int end = pdoc->LineStart(line + 1);  			pdoc->DeleteChars(start, end - start); -			MovePositionTo(start);  		}  		break;  	case SCI_LINETRANSPOSE: diff --git a/src/Editor.h b/src/Editor.h index d9719dc53..d784f478e 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -396,6 +396,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	void ChangeCaseOfSelection(bool makeUpperCase);  	void LineTranspose();      	virtual void CancelModes(); +	void NewLine();  	virtual int KeyCommand(unsigned int iMessage);  	virtual int KeyDefault(int /* key */, int /*modifiers*/);  	int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0); | 
