diff options
author | jedailey <unknown> | 2016-08-31 11:30:52 +1000 |
---|---|---|
committer | jedailey <unknown> | 2016-08-31 11:30:52 +1000 |
commit | 26869ee3d67d8f58c6573a6b010e9a615c9d681a (patch) | |
tree | c0b7a1a2ec3de36ee60ced2ae8a0267f01175f7d /src | |
parent | 917c4a524591b20ebc039ef8e32c158218412855 (diff) | |
download | scintilla-mirror-26869ee3d67d8f58c6573a6b010e9a615c9d681a.tar.gz |
Bug [#1850]. Use tabs for virtual space in indentation when tabs enabled.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 40 | ||||
-rw-r--r-- | src/Editor.h | 3 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 2 |
3 files changed, 28 insertions, 17 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index bcba9bdf4..f9ac97b45 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1837,15 +1837,26 @@ void Editor::ChangeSize() { } } -int Editor::InsertSpace(int position, unsigned int spaces) { - if (spaces > 0) { - std::string spaceText(spaces, ' '); - const int lengthInserted = pdoc->InsertString(position, spaceText.c_str(), spaces); - position += lengthInserted; +int Editor::RealizeVirtualSpace(int position, unsigned int virtualSpace) { + if (virtualSpace > 0) { + const int line = pdoc->LineFromPosition(position); + const int indent = pdoc->GetLineIndentPosition(line); + if (indent == position) { + return pdoc->SetLineIndentation(line, pdoc->GetLineIndentation(line) + virtualSpace); + } else { + std::string spaceText(virtualSpace, ' '); + const int lengthInserted = pdoc->InsertString(position, spaceText.c_str(), virtualSpace); + position += lengthInserted; + } } return position; } +SelectionPosition Editor::RealizeVirtualSpace(const SelectionPosition &position) { + // Return the new position with no virtual space + return SelectionPosition(RealizeVirtualSpace(position.Position(), position.VirtualSpace())); +} + void Editor::AddChar(char ch) { char s[2]; s[0] = ch; @@ -1901,7 +1912,7 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) { } } } - positionInsert = InsertSpace(positionInsert, currentSel->caret.VirtualSpace()); + positionInsert = RealizeVirtualSpace(positionInsert, currentSel->caret.VirtualSpace()); const int lengthInserted = pdoc->InsertString(positionInsert, s, len); if (lengthInserted > 0) { currentSel->caret.SetPosition(positionInsert + lengthInserted); @@ -1975,7 +1986,7 @@ void Editor::ClearBeforeTentativeStart() { sel.Range(r).MinimizeVirtualSpace(); } } - InsertSpace(positionInsert, sel.Range(r).caret.VirtualSpace()); + RealizeVirtualSpace(positionInsert, sel.Range(r).caret.VirtualSpace()); sel.Range(r).ClearVirtualSpace(); } } @@ -1984,7 +1995,7 @@ void Editor::ClearBeforeTentativeStart() { void Editor::InsertPaste(const char *text, int len) { if (multiPasteMode == SC_MULTIPASTE_ONCE) { SelectionPosition selStart = sel.Start(); - selStart = SelectionPosition(InsertSpace(selStart.Position(), selStart.VirtualSpace())); + selStart = RealizeVirtualSpace(selStart); const int lengthInserted = pdoc->InsertString(selStart.Position(), text, len); if (lengthInserted > 0) { SetEmptySelection(selStart.Position() + lengthInserted); @@ -2004,7 +2015,7 @@ void Editor::InsertPaste(const char *text, int len) { sel.Range(r).MinimizeVirtualSpace(); } } - positionInsert = InsertSpace(positionInsert, sel.Range(r).caret.VirtualSpace()); + positionInsert = RealizeVirtualSpace(positionInsert, sel.Range(r).caret.VirtualSpace()); const int lengthInserted = pdoc->InsertString(positionInsert, text, len); if (lengthInserted > 0) { sel.Range(r).caret.SetPosition(positionInsert + lengthInserted); @@ -2126,8 +2137,7 @@ void Editor::PasteRectangular(SelectionPosition pos, const char *ptr, int len) { sel.RangeMain() = SelectionRange(pos); int line = pdoc->LineFromPosition(sel.MainCaret()); UndoGroup ug(pdoc); - sel.RangeMain().caret = SelectionPosition( - InsertSpace(sel.RangeMain().caret.Position(), sel.RangeMain().caret.VirtualSpace())); + sel.RangeMain().caret = RealizeVirtualSpace(sel.RangeMain().caret); int xInsert = XFromPosition(sel.RangeMain().caret); bool prevCr = false; while ((len > 0) && IsEOLChar(ptr[len-1])) @@ -2179,9 +2189,9 @@ void Editor::Clear() { if (!RangeContainsProtected(sel.Range(r).caret.Position(), sel.Range(r).caret.Position() + 1)) { if (sel.Range(r).Start().VirtualSpace()) { if (sel.Range(r).anchor < sel.Range(r).caret) - sel.Range(r) = SelectionRange(InsertSpace(sel.Range(r).anchor.Position(), sel.Range(r).anchor.VirtualSpace())); + sel.Range(r) = SelectionRange(RealizeVirtualSpace(sel.Range(r).anchor.Position(), sel.Range(r).anchor.VirtualSpace())); else - sel.Range(r) = SelectionRange(InsertSpace(sel.Range(r).caret.Position(), sel.Range(r).caret.VirtualSpace())); + sel.Range(r) = SelectionRange(RealizeVirtualSpace(sel.Range(r).caret.Position(), sel.Range(r).caret.VirtualSpace())); } if ((sel.Count() == 1) || !pdoc->IsPositionInLineEnd(sel.Range(r).caret.Position())) { pdoc->DelChar(sel.Range(r).caret.Position()); @@ -3504,7 +3514,7 @@ int Editor::DelWordOrLine(unsigned int iMessage) { } else { // Delete to the right so first realise the virtual space. sel.Range(r) = SelectionRange( - InsertSpace(sel.Range(r).caret.Position(), sel.Range(r).caret.VirtualSpace())); + RealizeVirtualSpace(sel.Range(r).caret)); } Range rangeDelete; @@ -4208,7 +4218,7 @@ void Editor::DropAt(SelectionPosition position, const char *value, size_t length SetEmptySelection(position); } else { position = MovePositionOutsideChar(position, sel.MainCaret() - position.Position()); - position = SelectionPosition(InsertSpace(position.Position(), position.VirtualSpace())); + position = RealizeVirtualSpace(position); const int lengthInserted = pdoc->InsertString( position.Position(), convertedText.c_str(), static_cast<int>(convertedText.length())); if (lengthInserted > 0) { diff --git a/src/Editor.h b/src/Editor.h index 93a86fa39..72d4719ed 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -390,7 +390,8 @@ protected: // ScintillaBase subclass needs access to much of Editor void ChangeSize(); void FilterSelections(); - int InsertSpace(int position, unsigned int spaces); + int RealizeVirtualSpace(int position, unsigned int virtualSpace); + SelectionPosition RealizeVirtualSpace(const SelectionPosition &position); void AddChar(char ch); virtual void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false); void ClearBeforeTentativeStart(); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index b6e2fb333..92605d9b3 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -218,7 +218,7 @@ void ScintillaBase::AutoCompleteInsert(Position startPos, int removeLen, const c if (!RangeContainsProtected(sel.Range(r).Start().Position(), sel.Range(r).End().Position())) { int positionInsert = sel.Range(r).Start().Position(); - positionInsert = InsertSpace(positionInsert, sel.Range(r).caret.VirtualSpace()); + positionInsert = RealizeVirtualSpace(positionInsert, sel.Range(r).caret.VirtualSpace()); if (positionInsert - removeLen >= 0) { positionInsert -= removeLen; pdoc->DeleteChars(positionInsert, removeLen); |