aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2025-09-09 20:50:07 +0300
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-05-09 23:00:17 +0200
commita534721011f35a1a56c2a815f8b2fa31e0a8ebbd (patch)
tree097b6b1f87310aa6bbe53b8021719d99d2605412
parent01a9fb54ba284e440cbf4799fc3b8840584471be (diff)
downloadscintilla-mirror-sciteco-rel-5-6-2.tar.gz
added SC_LINE_END_TYPE_NONE: allows ignoring all line endssciteco-rel-5-6-2
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. This patch will not be merged for the time being, so we strive to reduce the number of touched lines. See https://groups.google.com/g/scintilla-interest/c/iE6E4n9zWT4
-rw-r--r--doc/ScintillaDoc.html8
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface1
-rw-r--r--include/ScintillaTypes.h1
-rw-r--r--src/CellBuffer.cxx32
-rw-r--r--src/Document.cxx4
-rw-r--r--src/ScintillaBase.cxx2
7 files changed, 36 insertions, 13 deletions
diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html
index c21bd2e29..3c5a4ab7f 100644
--- a/doc/ScintillaDoc.html
+++ b/doc/ScintillaDoc.html
@@ -3041,15 +3041,17 @@ struct Sci_TextToFindFull {
<p><b id="SCI_GETLINEENDTYPESSUPPORTED">SCI_GETLINEENDTYPESSUPPORTED &rarr; 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 &rarr; 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 &rarr; int</b><br />
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 7f12703d3..c9180780b 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -1146,6 +1146,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 ddb025c50..4232a880c 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -3148,6 +3148,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 cc5f03815..c2facae2e 100644
--- a/include/ScintillaTypes.h
+++ b/include/ScintillaTypes.h
@@ -524,6 +524,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 1eac3f9c2..a3904094d 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -576,6 +576,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++) {
@@ -627,6 +630,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);
}
@@ -634,6 +639,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()) {
@@ -773,6 +780,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;
@@ -874,7 +886,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++;
@@ -893,7 +905,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));
@@ -902,8 +914,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;
@@ -961,7 +975,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)) {
@@ -973,7 +987,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);
@@ -1054,7 +1068,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++;
@@ -1066,6 +1080,8 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
}
}
+ if (LineEndType::None != GetLineEndTypes()) {
+
unsigned char ch = chNext;
for (Sci::Position i = 0; i < deleteLength; i++) {
chNext = substance.ValueAt(position + i + 1);
@@ -1099,6 +1115,8 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe
RemoveLine(lineRemove - 1);
plv->SetLineStart(lineRemove - 1, position + 1);
}
+
+ } /* LineEndType::None != GetLineEndTypes() */
}
substance.DeleteRange(position, deleteLength);
if (lineRecalculateStart >= 0) {
diff --git a/src/Document.cxx b/src/Document.cxx
index 289fb6731..d57fe24ec 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) {