diff options
| -rw-r--r-- | doc/ScintillaDoc.html | 11 | ||||
| -rw-r--r-- | include/Scintilla.h | 3 | ||||
| -rw-r--r-- | src/Document.cxx | 31 | ||||
| -rw-r--r-- | src/Document.h | 7 | ||||
| -rw-r--r-- | src/Editor.cxx | 10 | 
5 files changed, 45 insertions, 17 deletions
| diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index c2ce990df..d35b0b541 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -418,6 +418,17 @@ SCI_SETUSETABS(bool usetabs)        and space or be based purely on spaces.      </p>  <pre> +SCI_SETLINEINDENTATION(int line, int indentation) +SCI_GETLINEINDENTATION(int line) +SCI_GETLINEINDENTPOSITION(int line) +</pre> +    <p> +     The amount of indentation on a line can be discovered and set with SCI_GETLINEINDENTATION and  +     SCI_SETLINEINDENTATION. The indnetation is measuered in character columns which correspond  +     to the width of space characters.  +     SCI_GETLINEINDENTPOSITION returns the position at the end of indentation of a line. +    </p> +<pre>  SCI_SETCODEPAGE(int codepage)  </pre>      <p> diff --git a/include/Scintilla.h b/include/Scintilla.h index e86dec35e..8e5826bf5 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -225,6 +225,9 @@ extern "C" {  #define SCI_GETINDENT SCI_START + 123  #define SCI_SETUSETABS SCI_START + 124  #define SCI_GETUSETABS SCI_START + 125 +#define SCI_SETLINEINDENTATION SCI_START + 126 +#define SCI_GETLINEINDENTATION SCI_START + 127 +#define SCI_GETLINEINDENTPOSITION SCI_START + 128  #define SCI_CALLTIPSHOW SCI_START + 200  #define SCI_CALLTIPCANCEL SCI_START + 201 diff --git a/src/Document.cxx b/src/Document.cxx index 7e4b888fc..709deaf80 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -530,7 +530,7 @@ static void CreateIndentation(char *linebuf, int length, int indent, int tabSize  int Document::GetLineIndentation(int line) {  	int indent = 0; -	if (line >= 0) { +	if ((line >= 0) && (line < LinesTotal())) {  		int lineStart = LineStart(line);  		int length = Length();  		for (int i=lineStart;i<length;i++) { @@ -546,6 +546,20 @@ int Document::GetLineIndentation(int line) {  	return indent;  } +void Document::SetLineIndentation(int line, int indent) { +	int indentOfLine = GetLineIndentation(line); +	if (indent < 0) +		indent = 0; +	if (indent != indentOfLine) { +		char linebuf[1000]; +		CreateIndentation(linebuf, sizeof(linebuf), indent, tabInChars, !useTabs); +		int thisLineStart = LineStart(line); +		int indentPos = GetLineIndentPosition(line); +		DeleteChars(thisLineStart, indentPos - thisLineStart); +		InsertString(thisLineStart, linebuf); +	} +} +  int Document::GetLineIndentPosition(int line) {  	int pos = LineStart(line);  	int length = Length(); @@ -556,24 +570,13 @@ int Document::GetLineIndentPosition(int line) {  }  void Document::Indent(bool forwards, int lineBottom, int lineTop) { -	char linebuf[1000];  	// Dedent - suck white space off the front of the line to dedent by equivalent of a tab  	for (int line = lineBottom; line >= lineTop; line--) {  		int indentOfLine = GetLineIndentation(line); -		int indentNew = indentOfLine;  		if (forwards) -			indentNew += IndentSize(); +			SetLineIndentation(line, indentOfLine + IndentSize());  		else -			indentNew -= IndentSize(); -		if (indentNew < 0) -			indentNew = 0; -		if (indentNew != indentOfLine) { -			CreateIndentation(linebuf, sizeof(linebuf), indentNew, tabInChars, !useTabs); -			int thisLineStart = LineStart(line); -			int indentPos = GetLineIndentPosition(line); -			DeleteChars(thisLineStart, indentPos - thisLineStart); -			InsertString(thisLineStart, linebuf); -		} +			SetLineIndentation(line, indentOfLine - IndentSize());  	}  } diff --git a/src/Document.h b/src/Document.h index af449ac73..15f8f1121 100644 --- a/src/Document.h +++ b/src/Document.h @@ -120,6 +120,10 @@ public:  	void EndUndoAction() { cb.EndUndoAction(); }  	void SetSavePoint();  	bool IsSavePoint() { return cb.IsSavePoint(); } + +	int GetLineIndentation(int line); +	void SetLineIndentation(int line, int indent); +	int GetLineIndentPosition(int line);  	void Indent(bool forwards, int lineBottom, int lineTop);  	void ConvertLineEnds(int eolModeSet);  	void SetReadOnly(bool set) { cb.SetReadOnly(set); } @@ -185,9 +189,6 @@ private:  	bool IsWordAt(int start, int end);  	void ModifiedAt(int pos); -	int GetLineIndentation(int line); -	int GetLineIndentPosition(int line); -		  	void NotifyModifyAttempt();  	void NotifySavePoint(bool atSavePoint);  	void NotifyModified(DocModification mh); diff --git a/src/Editor.cxx b/src/Editor.cxx index ef6b4b450..a4ac0be17 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -3384,6 +3384,16 @@ LRESULT Editor::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {  	case SCI_GETUSETABS:  		return pdoc->useTabs; +	case SCI_SETLINEINDENTATION: +		pdoc->SetLineIndentation(wParam, lParam); +		break; +		 +	case SCI_GETLINEINDENTATION: +		return pdoc->GetLineIndentation(wParam); +		 +	case SCI_GETLINEINDENTPOSITION: +		return pdoc->GetLineIndentPosition(wParam); +		  	case SCI_SETCODEPAGE:  		pdoc->dbcsCodePage = wParam;  		break; | 
