diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-09-09 20:50:07 +0300 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2025-11-09 22:10:35 +0100 |
| commit | a5b8fca36a7a050edfa1c4bb9e91f7722e12f3f6 (patch) | |
| tree | db20f53a3007245a64bf268ea67202dbdc08345f | |
| parent | d4fa2014808092ddfaa0c97c1755af87a182be6b (diff) | |
| download | scintilla-mirror-a5b8fca36a7a050edfa1c4bb9e91f7722e12f3f6.tar.gz | |
added SC_LINE_END_TYPE_NONE: allows ignoring all line ends
This can help when using Scintilla views as command line widgets.
It can also help when using Scintilla to edit binary files as you
don't want to attach special meaning to CR and LF.
| -rw-r--r-- | doc/ScintillaDoc.html | 8 | ||||
| -rw-r--r-- | include/Scintilla.h | 1 | ||||
| -rw-r--r-- | include/Scintilla.iface | 1 | ||||
| -rw-r--r-- | include/ScintillaTypes.h | 1 | ||||
| -rw-r--r-- | src/CellBuffer.cxx | 86 | ||||
| -rw-r--r-- | src/Document.cxx | 4 | ||||
| -rw-r--r-- | src/ScintillaBase.cxx | 2 |
7 files changed, 62 insertions, 41 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 0dfe986f4..deae30251 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3015,15 +3015,17 @@ struct Sci_TextToFindFull { <p><b id="SCI_GETLINEENDTYPESSUPPORTED">SCI_GETLINEENDTYPESSUPPORTED → int</b><br /> <code>SCI_GETLINEENDTYPESSUPPORTED</code> reports the different types of line ends supported - by the current lexer. This is a bit set although there is currently only a single choice - with either <code>SC_LINE_END_TYPE_DEFAULT</code> (0) or <code>SC_LINE_END_TYPE_UNICODE</code> (1). + by the current lexer. This is a choice between <code>SC_LINE_END_TYPE_DEFAULT</code> (0), + <code>SC_LINE_END_TYPE_UNICODE</code> (1) and <code>SC_LINE_END_TYPE_NONE</code> (2). These values are also used by the other messages concerned with Unicode line ends.</p> - <p><b id="SCI_SETLINEENDTYPESALLOWED">SCI_SETLINEENDTYPESALLOWED(int lineEndBitSet)</b><br /> + <p><b id="SCI_SETLINEENDTYPESALLOWED">SCI_SETLINEENDTYPESALLOWED(int lineEndType)</b><br /> <b id="SCI_GETLINEENDTYPESALLOWED">SCI_GETLINEENDTYPESALLOWED → int</b><br /> By default, only the ASCII line ends are interpreted. Unicode line ends may be requested with <code>SCI_SETLINEENDTYPESALLOWED(SC_LINE_END_TYPE_UNICODE)</code> but this will be ineffective unless the lexer also allows you Unicode line ends. + <code>SC_LINE_END_TYPE_NONE</code> disables interpretation of all line ends which effectively + creates a one-line view. <code>SCI_GETLINEENDTYPESALLOWED</code> returns the current state.</p> <p><b id="SCI_GETLINEENDTYPESACTIVE">SCI_GETLINEENDTYPESACTIVE → int</b><br /> diff --git a/include/Scintilla.h b/include/Scintilla.h index f7afa4f50..115003c1b 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -1144,6 +1144,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP #define SCI_SETCARETLINEVISIBLEALWAYS 2655 #define SC_LINE_END_TYPE_DEFAULT 0 #define SC_LINE_END_TYPE_UNICODE 1 +#define SC_LINE_END_TYPE_NONE 2 #define SCI_SETLINEENDTYPESALLOWED 2656 #define SCI_GETLINEENDTYPESALLOWED 2657 #define SCI_GETLINEENDTYPESACTIVE 2658 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 9ba834aed..3e0bbd147 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -3145,6 +3145,7 @@ set void SetCaretLineVisibleAlways=2655(bool alwaysVisible,) enu LineEndType=SC_LINE_END_TYPE_ val SC_LINE_END_TYPE_DEFAULT=0 val SC_LINE_END_TYPE_UNICODE=1 +val SC_LINE_END_TYPE_NONE=2 # Set the line end types that the application wants to use. May not be used if incompatible with lexer or encoding. set void SetLineEndTypesAllowed=2656(LineEndType lineEndBitSet,) diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index 0991a1480..411876f97 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -522,6 +522,7 @@ enum class Technology { enum class LineEndType { Default = 0, Unicode = 1, + None = 2, }; enum class RepresentationAppearance { diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 3e9deb934..28141e2cd 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -521,6 +521,9 @@ void CellBuffer::SetLineEndTypes(LineEndType utf8LineEnds_) { } bool CellBuffer::ContainsLineEnd(const char *s, Sci::Position length) const noexcept { + if (utf8LineEnds == LineEndType::None) { + return false; + } unsigned char chBeforePrev = 0; unsigned char chPrev = 0; for (Sci::Position i = 0; i < length; i++) { @@ -572,6 +575,8 @@ Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept { return 0; else if (line >= Lines()) return Length(); + else if (LineEndType::None == GetLineEndTypes()) + return 0; else return plv->LineStart(line); } @@ -579,6 +584,8 @@ Sci::Position CellBuffer::LineStart(Sci::Line line) const noexcept { Sci::Position CellBuffer::LineEnd(Sci::Line line) const noexcept { if (line >= Lines() - 1) { return LineStart(line + 1); + } else if (LineEndType::None == GetLineEndTypes()) { + return Length(); } else { Sci::Position position = LineStart(line + 1); if (LineEndType::Unicode == GetLineEndTypes()) { @@ -718,6 +725,11 @@ void CellBuffer::ResetLineEnds() { constexpr Sci::Position position = 0; const Sci::Position length = Length(); plv->InsertText(0, length); + + if (LineEndType::None == GetLineEndTypes()) { + return; + } + Sci::Line lineInsert = 1; constexpr bool atLineStart = true; unsigned char chBeforePrev = 0; @@ -819,7 +831,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P plv->InsertText(lineInsert-1, insertLength); unsigned char chBeforePrev = substance.ValueAt(position - 2); unsigned char chPrev = substance.ValueAt(position - 1); - if (chPrev == '\r' && chAfter == '\n') { + if (LineEndType::None != GetLineEndTypes() && chPrev == '\r' && chAfter == '\n') { // Splitting up a crlf pair at position InsertLine(lineInsert, position, false); lineInsert++; @@ -838,7 +850,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P const char *ptr = s; unsigned char ch = 0; - if (chPrev == '\r' && *ptr == '\n') { + if (LineEndType::None != GetLineEndTypes() && chPrev == '\r' && *ptr == '\n') { ++ptr; // Patch up what was end of line plv->SetLineStart(lineInsert - 1, (position + ptr - s)); @@ -847,8 +859,10 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P if (ptr < end) { uint8_t eolTable[256]{}; - eolTable[static_cast<uint8_t>('\n')] = 1; - eolTable[static_cast<uint8_t>('\r')] = 2; + if (LineEndType::None != GetLineEndTypes()) { + eolTable[static_cast<uint8_t>('\n')] = 1; + eolTable[static_cast<uint8_t>('\r')] = 2; + } if (utf8LineEnds == LineEndType::Unicode) { // see UniConversion.h for LS, PS and NEL eolTable[0x85] = 4; @@ -906,7 +920,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P ch = *end; if (ptr == end) { ++ptr; - if (ch == '\r' || ch == '\n') { + if (LineEndType::None != GetLineEndTypes() && (ch == '\r' || ch == '\n')) { InsertLine(lineInsert, (position + ptr - s), atLineStart); lineInsert++; } else if (utf8LineEnds == LineEndType::Unicode && !UTF8IsAscii(ch)) { @@ -918,7 +932,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P } // Joining two lines where last insertion is cr and following substance starts with lf - if (chAfter == '\n') { + if (LineEndType::None != GetLineEndTypes() && chAfter == '\n') { if (ch == '\r') { // End of line already in buffer so drop the newly created one RemoveLine(lineInsert - 1); @@ -999,7 +1013,7 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe } bool ignoreNL = false; - if (chPrev == '\r' && chNext == '\n') { + if (LineEndType::None != GetLineEndTypes() && chPrev == '\r' && chNext == '\n') { // Move back one plv->SetLineStart(lineRemove, position); lineRemove++; @@ -1011,38 +1025,40 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe } } - unsigned char ch = chNext; - for (Sci::Position i = 0; i < deleteLength; i++) { - chNext = substance.ValueAt(position + i + 1); - if (ch == '\r') { - if (chNext != '\n') { - RemoveLine(lineRemove); - } - } else if (ch == '\n') { - if (ignoreNL) { - ignoreNL = false; // Further \n are real deletions - } else { - RemoveLine(lineRemove); - } - } else if (utf8LineEnds == LineEndType::Unicode) { - if (!UTF8IsAscii(ch)) { - const unsigned char next3[3] = {ch, chNext, - static_cast<unsigned char>(substance.ValueAt(position + i + 2))}; - if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) { + if (LineEndType::None != GetLineEndTypes()) { + unsigned char ch = chNext; + for (Sci::Position i = 0; i < deleteLength; i++) { + chNext = substance.ValueAt(position + i + 1); + if (ch == '\r') { + if (chNext != '\n') { RemoveLine(lineRemove); } + } else if (ch == '\n') { + if (ignoreNL) { + ignoreNL = false; // Further \n are real deletions + } else { + RemoveLine(lineRemove); + } + } else if (utf8LineEnds == LineEndType::Unicode) { + if (!UTF8IsAscii(ch)) { + const unsigned char next3[3] = {ch, chNext, + static_cast<unsigned char>(substance.ValueAt(position + i + 2))}; + if (UTF8IsSeparator(next3) || UTF8IsNEL(next3)) { + RemoveLine(lineRemove); + } + } } - } - ch = chNext; - } - // May have to fix up end if last deletion causes cr to be next to lf - // or removes one of a crlf pair - const char chAfter = substance.ValueAt(position + deleteLength); - if (chBefore == '\r' && chAfter == '\n') { - // Using lineRemove-1 as cr ended line before start of deletion - RemoveLine(lineRemove - 1); - plv->SetLineStart(lineRemove - 1, position + 1); + ch = chNext; + } + // May have to fix up end if last deletion causes cr to be next to lf + // or removes one of a crlf pair + const char chAfter = substance.ValueAt(position + deleteLength); + if (chBefore == '\r' && chAfter == '\n') { + // Using lineRemove-1 as cr ended line before start of deletion + RemoveLine(lineRemove - 1); + plv->SetLineStart(lineRemove - 1, position + 1); + } } } substance.DeleteRange(position, deleteLength); diff --git a/src/Document.cxx b/src/Document.cxx index c79c5002b..5025b3fe2 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -100,7 +100,7 @@ LineEndType LexInterface::LineEndTypesSupported() { if (instance) { return static_cast<LineEndType>(instance->LineEndTypesSupported()); } - return LineEndType::Default; + return LineEndType::None; } bool LexInterface::UseContainerLexing() const noexcept { @@ -260,7 +260,7 @@ LineAnnotation *Document::EOLAnnotations() const noexcept { LineEndType Document::LineEndTypesSupported() const { if ((CpUtf8 == dbcsCodePage) && pli) return pli->LineEndTypesSupported(); - return LineEndType::Default; + return LineEndType::None; } bool Document::SetDBCSCodePage(int dbcsCodePage_) { diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 1f4c360da..90b3d3275 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -735,7 +735,7 @@ LineEndType LexState::LineEndTypesSupported() { if (instance) { return static_cast<LineEndType>(instance->LineEndTypesSupported()); } - return LineEndType::Default; + return LineEndType::None; } int LexState::AllocateSubStyles(int styleBase, int numberStyles) { |
