diff options
author | Neil <nyamatongwe@gmail.com> | 2015-12-31 14:28:37 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2015-12-31 14:28:37 +1100 |
commit | 1ea05a3df97f9a733254ecde9e70b5827083b8e6 (patch) | |
tree | ccf99b9eb15493d3108d9d8c031c0719c4514914 | |
parent | ba6468fb9aca4f448eba0024b96d1bb3ec213720 (diff) | |
download | scintilla-mirror-1ea05a3df97f9a733254ecde9e70b5827083b8e6.tar.gz |
Treat Unicode line ends like common line ends when maintaining fold state.
-rw-r--r-- | src/CellBuffer.cxx | 19 | ||||
-rw-r--r-- | src/CellBuffer.h | 1 | ||||
-rw-r--r-- | src/Document.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 6 |
4 files changed, 22 insertions, 5 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index f43a0c302..6ad990a63 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -496,6 +496,25 @@ void CellBuffer::SetLineEndTypes(int utf8LineEnds_) { } } +bool CellBuffer::ContainsLineEnd(const char *s, int length) const { + unsigned char chBeforePrev = 0; + unsigned char chPrev = 0; + for (int i = 0; i < length; i++) { + const unsigned char ch = s[i]; + if ((ch == '\r') || (ch == '\n')) { + return true; + } else if (utf8LineEnds) { + unsigned char back3[3] = { chBeforePrev, chPrev, ch }; + if (UTF8IsSeparator(back3) || UTF8IsNEL(back3 + 1)) { + return true; + } + } + chBeforePrev = chPrev; + chPrev = ch; + } + return false; +} + void CellBuffer::SetPerLine(PerLine *pl) { lv.SetPerLine(pl); } diff --git a/src/CellBuffer.h b/src/CellBuffer.h index 5e4fc7c8c..1c53d14e6 100644 --- a/src/CellBuffer.h +++ b/src/CellBuffer.h @@ -177,6 +177,7 @@ public: void Allocate(int newSize); int GetLineEndTypes() const { return utf8LineEnds; } void SetLineEndTypes(int utf8LineEnds_); + bool ContainsLineEnd(const char *s, int length) const; void SetPerLine(PerLine *pl); int Lines() const; int LineStart(int line) const; diff --git a/src/Document.h b/src/Document.h index 00f80914c..cc3873f59 100644 --- a/src/Document.h +++ b/src/Document.h @@ -273,6 +273,7 @@ public: Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const; int ClampPositionIntoDocument(int pos) const; + bool ContainsLineEnd(const char *s, int length) const { return cb.ContainsLineEnd(s, length); } bool IsCrLf(int pos) const; int LenChar(int pos); bool InGoodUTF8(int pos, int &start, int &end) const; diff --git a/src/Editor.cxx b/src/Editor.cxx index 9c2703ab0..58abc37fd 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2582,11 +2582,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { // TODO: check if the modified area is hidden. if (mh.modificationType & SC_MOD_BEFOREINSERT) { int lineOfPos = pdoc->LineFromPosition(mh.position); - bool insertingNewLine = false; - for (int i=0; i < mh.length; i++) { - if ((mh.text[i] == '\n') || (mh.text[i] == '\r')) - insertingNewLine = true; - } + const bool insertingNewLine = pdoc->ContainsLineEnd(mh.text, mh.length); if (insertingNewLine && (mh.position != pdoc->LineStart(lineOfPos))) NeedShown(mh.position, pdoc->LineStart(lineOfPos+1) - mh.position); else |