From 9e59273e1a91a77efd675b0f912e5e680ce300a6 Mon Sep 17 00:00:00 2001
From: nyamatongwe
Date: Tue, 11 Apr 2000 11:11:00 +0000
Subject: Added smart indentation support code.
---
doc/ScintillaDoc.html | 11 +++++++++++
include/Scintilla.h | 3 +++
src/Document.cxx | 31 +++++++++++++++++--------------
src/Document.h | 7 ++++---
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.
+SCI_SETLINEINDENTATION(int line, int indentation)
+SCI_GETLINEINDENTATION(int line)
+SCI_GETLINEINDENTPOSITION(int line)
+
+
+ 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.
+
+
SCI_SETCODEPAGE(int codepage)
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= 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;
--
cgit v1.2.3