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