diff --git a/scintilla/Scintilla.vcxproj b/scintilla/Scintilla.vcxproj index 329943977..70bbfe9c5 100644 --- a/scintilla/Scintilla.vcxproj +++ b/scintilla/Scintilla.vcxproj @@ -129,6 +129,7 @@ true StreamingSIMDExtensions2 Fast + stdcpplatest true @@ -151,6 +152,7 @@ false true Fast + stdcpplatest MachineX64 @@ -175,6 +177,7 @@ true Fast + stdcpplatest true @@ -193,6 +196,7 @@ true true Fast + stdcpplatest MachineX64 diff --git a/scintilla/doc/ScintillaDoc.html b/scintilla/doc/ScintillaDoc.html index dae820f45..37125ff8d 100644 --- a/scintilla/doc/ScintillaDoc.html +++ b/scintilla/doc/ScintillaDoc.html @@ -119,7 +119,7 @@

Scintilla Documentation

-

Last edited 11 August 2017 NH

+

Last edited 1 February 2018 NH

There is an overview of the internal design of Scintilla.
@@ -3595,6 +3595,10 @@ struct Sci_TextToFind { SCI_GETCODEPAGE → int
SCI_SETIMEINTERACTION(int imeInteraction)
SCI_GETIMEINTERACTION → int
+

SCI_GRABFOCUS
SCI_SETFOCUS(bool focus)
SCI_GETFOCUS → bool
@@ -3719,6 +3723,27 @@ struct Sci_TextToFind { and the inline behaviour with SCI_SETIMEINTERACTION(SC_IME_INLINE). Scintilla may ignore this call in some cases. For example, the inline behaviour might only be supported for some languages.

+
+ These bidirectional features are not yet implemented and the API is provisional
+

SCI_SETBIDIRECTIONAL(int bidirectional)
+ SCI_GETBIDIRECTIONAL → int
+ Some languages, like Arabic and Hebrew, are written from right to left instead of from left to right as English is. + Documents that use multiple languages may contain both directions and this is termed "bidirectional". + The default text direction may be right to left or left to right. + Scintilla only correctly displays bidirectional text on some platforms and there can be additional processing and storage + costs to this. + Currently, bidirectional text only works on Win32 using DirectWrite. + As some applications may not want to pay the costs, bidirectional support must be explicitly enabled by calling + SCI_SETBIDIRECTIONAL(SC_BIDIRECTIONAL_L2R) (1) which chooses left to right as the default direction or + SCI_SETBIDIRECTIONAL(SC_BIDIRECTIONAL_R2L) (2) for default right to left. + This should be done after setting the technology to SC_TECHNOLOGY_DIRECTWRITE, + SC_TECHNOLOGY_DIRECTWRITERETAIN, or + SC_TECHNOLOGY_DIRECTWRITEDC.

+

If the call succeeded SCI_GETBIDIRECTIONAL will return the same value otherwise + SC_BIDIRECTIONAL_DISABLED (0) is returned. +

+
+

SCI_GRABFOCUS
SCI_SETFOCUS(bool focus)
SCI_GETFOCUS → bool
@@ -5687,7 +5712,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ SCI_GETDOCPOINTER → document *
SCI_SETDOCPOINTER(<unused>, document *doc)
- SCI_CREATEDOCUMENT → document *
+ SCI_CREATEDOCUMENT(int bytes, int documentOption) → document *
SCI_ADDREFDOCUMENT(<unused>, document *doc)
SCI_RELEASEDOCUMENT(<unused>, document @@ -5708,13 +5733,49 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ window.
6. If doc was not 0, its reference count is increased by 1.

-

SCI_CREATEDOCUMENT → document *
+

SCI_CREATEDOCUMENT(int bytes, int documentOption) → document *
This message creates a new, empty document and returns a pointer to it. This document is not - selected into the editor and starts with a reference count of 1. This means that you have - ownership of it and must either reduce its reference count by 1 after using + selected into the editor and starts with a reference count of 1. This means that you have + ownership of it and must either reduce its reference count by 1 after using SCI_SETDOCPOINTER so that the Scintilla window owns it or you must make sure that - you reduce the reference count by 1 with SCI_RELEASEDOCUMENT before you close the - application to avoid memory leaks.

+ you reduce the reference count by 1 with SCI_RELEASEDOCUMENT before you close the + application to avoid memory leaks. The bytes argument determines + the initial memory allocation for the document as it is more efficient + to allocate once rather than rely on the buffer growing as data is added. + If SCI_CREATEDOCUMENT fails then 0 is returned.

+ +

The documentOption argument + chooses between different document capabilities which affect memory allocation and performance with + SC_DOCUMENTOPTION_DEFAULT (0) choosing standard options. + SC_DOCUMENTOPTION_STYLES_NONE (1) stops allocation of memory to style characters + which saves significant memory, often 40% with the whole document treated as being style 0. + Lexers may still produce visual styling by using indicators.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
SymbolValueEffect
SC_DOCUMENTOPTION_DEFAULT0Standard behaviour
SC_DOCUMENTOPTION_STYLES_NONE1Stop allocation of memory for styles and treat all text as style 0.

SCI_ADDREFDOCUMENT(<unused>, document *doc)
This increases the reference count of a document by 1. If you want to replace the current @@ -5741,7 +5802,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){

Loading in the background

-
SCI_CREATELOADER(int bytes) → int
+ SCI_CREATELOADER(int bytes, int documentOption) → int

An application can load all of a file into a buffer it allocates on a background thread and then add the data in that buffer @@ -5750,13 +5811,16 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){

To avoid these issues, a loader object may be created and used to load the file. The loader object supports the ILoader interface.

-

SCI_CREATELOADER(int bytes) → int
+

SCI_CREATELOADER(int bytes, int documentOption) → int
Create an object that supports the ILoader interface which can be used to load data and then be turned into a Scintilla document object for attachment to a view object. The bytes argument determines the initial memory allocation for the document as it is more efficient to allocate once rather than rely on the buffer growing as data is added. If SCI_CREATELOADER fails then 0 is returned.

+

The documentOption argument + is described in the SCI_CREATEDOCUMENT section.

+

ILoader

@@ -6549,7 +6613,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){ On GTK+, there are storage and performance costs to accessibility, so it can be disabled by calling SCI_SETACCESSIBILITY.

- + @@ -6579,7 +6643,7 @@ sptr_t CallScintilla(unsigned int iMessage, uptr_t wParam, sptr_t lParam){
- +

Lexer

If you define the symbol SCI_LEXER when building Scintilla, (this is sometimes @@ -6870,7 +6934,7 @@ With Scintilla 4, 64-bit builds define these as 64-bit types to allow future imp

Methods that return strings as const char * are not required to maintain separate allocations indefinitely: lexer implementations may own a single buffer that is reused for each call. -Callers should make an immediate copy of returned strings. +Callers should make an immediate copy of returned strings.

@@ -8074,8 +8138,6 @@ for line = lineStart to lineEnd do SCI_ENSUREVISIBLE(line) next

Provisional features are displayed in this document with a distinctive background colour.

-

There are currently no provisional messages or values.

-

Some developers may want to only use features that are stable and have graduated from provisional status. To avoid using provisional messages compile with the symbol SCI_DISABLE_PROVISIONAL defined.

diff --git a/scintilla/doc/ScintillaHistory.html b/scintilla/doc/ScintillaHistory.html index c7c74204c..6abca8d23 100644 --- a/scintilla/doc/ScintillaHistory.html +++ b/scintilla/doc/ScintillaHistory.html @@ -516,6 +516,10 @@ Jannick Zufu Liu Simon Sobisch + + Georger Araújo + Tobias Kühne + Dimitar Radev

@@ -535,17 +539,52 @@ Released 26 October 2017.

  • + SCI_CREATEDOCUMENT adds a bytes argument to allocate memory for an initial size. + SCI_CREATELOADER and SCI_CREATEDOCUMENT add a documentOption argument to + allow choosing different document capabilities. +
  • +
  • + Add SC_DOCUMENTOPTION_STYLES_NONE option to stop allocating memory for styles. +
  • +
  • Add SCI_GETMOVEEXTENDSSELECTION to allow applications to add more complex selection commands.
  • + SciTE property bookmark.symbol allows choosing symbol used for bookmarks. + Feature #1208. +
  • +
  • Improve VHDL lexer's handling of character literals and escape characters in strings.
  • + Fix double tap word selection on Windows 10 1709 Fall Creators Update. + Bug #1983. +
  • +
  • Fix closing autocompletion lists on Cocoa for macOS 10.13 where the window was emptying but staying visible. Bug #1981.
  • +
  • + Fix drawing failure on Cocoa with animated find indicator in large files with macOS 10.12 + by disabling animation. +
  • +
  • + SciTE on GTK+ installs its desktop file as non-executable and supports the common + LDLIBS make variable. + Bug #1989, + Bug #1990. +
  • +
  • + SciTE shows correct column number when caret in virtual space. + Bug #1991. +
  • +
  • + SciTE preserves selection positions when saving with strip.trailing.spaces + and virtual space turned on. + Bug #1992. +
  • Release 4.0.2 diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index c7dd9d545..cae3046ca 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -690,6 +690,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SELECTIONISRECTANGLE 2372 #define SCI_SETZOOM 2373 #define SCI_GETZOOM 2374 +#define SC_DOCUMENTOPTION_DEFAULT 0 +#define SC_DOCUMENTOPTION_STYLES_NONE 1 #define SCI_CREATEDOCUMENT 2375 #define SCI_ADDREFDOCUMENT 2376 #define SCI_RELEASEDOCUMENT 2377 @@ -1104,6 +1106,13 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_AUTOCCOMPLETED 2030 #define SCN_MARGINRIGHTCLICK 2031 #define SCN_AUTOCSELECTIONCHANGE 2032 +#ifndef SCI_DISABLE_PROVISIONAL +#define SC_BIDIRECTIONAL_DISABLED 0 +#define SC_BIDIRECTIONAL_L2R 1 +#define SC_BIDIRECTIONAL_R2L 2 +#define SCI_GETBIDIRECTIONAL 2708 +#define SCI_SETBIDIRECTIONAL 2709 +#endif /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ /* These structures are defined to be exactly the same shape as the Win32 diff --git a/scintilla/include/Scintilla.iface b/scintilla/include/Scintilla.iface index 4a833edad..3677414f0 100644 --- a/scintilla/include/Scintilla.iface +++ b/scintilla/include/Scintilla.iface @@ -1771,9 +1771,13 @@ set void SetZoom=2373(int zoomInPoints,) # Retrieve the zoom level. get int GetZoom=2374(,) +enu DocumentOption=SC_DOCUMENTOPTION_ +val SC_DOCUMENTOPTION_DEFAULT=0 +val SC_DOCUMENTOPTION_STYLES_NONE=1 + # Create a new document object. # Starts with reference count of 1 and not selected into editor. -fun int CreateDocument=2375(,) +fun int CreateDocument=2375(int bytes, int documentOption) # Extend life of document. fun void AddRefDocument=2376(, int doc) # Release a reference to the document, deleting document if it fades to black. @@ -2540,7 +2544,7 @@ set void SetTechnology=2630(int technology,) get int GetTechnology=2631(,) # Create an ILoader*. -fun int CreateLoader=2632(int bytes,) +fun int CreateLoader=2632(int bytes, int documentOption) # On OS X, show a find indicator. fun void FindIndicatorShow=2640(position start, position end) @@ -2918,7 +2922,6 @@ val SCLEX_JSON=120 val SCLEX_EDIFACT=121 val SCLEX_INDENT=122 val SCLEX_AHK=200 -val SCLEX_NIM=201 # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -4863,10 +4866,19 @@ evt void AutoCCompleted=2030(string text, int position, int ch, CompletionMethod evt void MarginRightClick=2031(int modifiers, int position, int margin) evt void AutoCSelectionChange=2032(int listType, string text, int position) -# There are no provisional APIs currently. - cat Provisional +enu Bidirectional=SC_BIDIRECTIONAL_ +val SC_BIDIRECTIONAL_DISABLED=0 +val SC_BIDIRECTIONAL_L2R=1 +val SC_BIDIRECTIONAL_R2L=2 + +# Retrieve bidirectional text display state. +get int GetBidirectional=2708(,) + +# Set bidirectional text display state. +set void SetBidirectional=2709(int bidirectional,) + cat Deprecated # Divide each styling byte into lexical class bits (default: 5) and indicator diff --git a/scintilla/lexlib/WordList.cxx b/scintilla/lexlib/WordList.cxx index f65b5ed48..425bcc01a 100644 --- a/scintilla/lexlib/WordList.cxx +++ b/scintilla/lexlib/WordList.cxx @@ -10,6 +10,7 @@ #include #include +#include #include "StringCopy.h" #include "WordList.h" @@ -128,7 +129,7 @@ void WordList::Set(const char *s) { #else SortWordList(words, len); #endif - std::fill(starts, starts + ELEMENTS(starts), -1); + std::fill(starts, std::end(starts), -1); for (int l = len - 1; l >= 0; l--) { unsigned char indexChar = words[l][0]; starts[indexChar] = l; diff --git a/scintilla/scripts/HeaderOrder.txt b/scintilla/scripts/HeaderOrder.txt index c16b7bdff..5eeb320eb 100644 --- a/scintilla/scripts/HeaderOrder.txt +++ b/scintilla/scripts/HeaderOrder.txt @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include diff --git a/scintilla/src/CellBuffer.cxx b/scintilla/src/CellBuffer.cxx index e87c5c305..513c9a9b8 100644 --- a/scintilla/src/CellBuffer.cxx +++ b/scintilla/src/CellBuffer.cxx @@ -342,7 +342,8 @@ void UndoHistory::CompletedRedoStep() { currentAction++; } -CellBuffer::CellBuffer() { +CellBuffer::CellBuffer(bool hasStyles_) : + hasStyles(hasStyles_) { readOnly = false; utf8LineEnds = 0; collectingUndo = true; @@ -369,7 +370,7 @@ void CellBuffer::GetCharRange(char *buffer, Sci::Position position, Sci::Positio } char CellBuffer::StyleAt(Sci::Position position) const { - return style.ValueAt(position); + return hasStyles ? style.ValueAt(position) : 0; } void CellBuffer::GetStyleRange(unsigned char *buffer, Sci::Position position, Sci::Position lengthRetrieve) const { @@ -377,6 +378,10 @@ void CellBuffer::GetStyleRange(unsigned char *buffer, Sci::Position position, Sc return; if (position < 0) return; + if (!hasStyles) { + std::fill(buffer, buffer + lengthRetrieve, static_cast(0)); + return; + } if ((position + lengthRetrieve) > style.Length()) { Platform::DebugPrintf("Bad GetStyleRange %d for %d of %d\n", position, lengthRetrieve, style.Length()); @@ -394,7 +399,7 @@ const char *CellBuffer::RangePointer(Sci::Position position, Sci::Position range } Sci::Position CellBuffer::GapPosition() const { - return substance.GapPosition(); + return static_cast(substance.GapPosition()); } // The char* returned is to an allocation owned by the undo history @@ -414,6 +419,9 @@ const char *CellBuffer::InsertString(Sci::Position position, const char *s, Sci: } bool CellBuffer::SetStyleAt(Sci::Position position, char styleValue) { + if (!hasStyles) { + return false; + } const char curVal = style.ValueAt(position); if (curVal != styleValue) { style.SetValueAt(position, styleValue); @@ -424,6 +432,9 @@ bool CellBuffer::SetStyleAt(Sci::Position position, char styleValue) { } bool CellBuffer::SetStyleFor(Sci::Position position, Sci::Position lengthStyle, char styleValue) { + if (!hasStyles) { + return false; + } bool changed = false; PLATFORM_ASSERT(lengthStyle == 0 || (lengthStyle > 0 && lengthStyle + position <= style.Length())); @@ -457,12 +468,14 @@ const char *CellBuffer::DeleteChars(Sci::Position position, Sci::Position delete } Sci::Position CellBuffer::Length() const { - return substance.Length(); + return static_cast(substance.Length()); } void CellBuffer::Allocate(Sci::Position newSize) { substance.ReAllocate(newSize); - style.ReAllocate(newSize); + if (hasStyles) { + style.ReAllocate(newSize); + } } void CellBuffer::SetLineEndTypes(int utf8LineEnds_) { @@ -608,7 +621,9 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P } substance.InsertFromArray(position, s, 0, insertLength); - style.InsertValue(position, insertLength, 0); + if (hasStyles) { + style.InsertValue(position, insertLength, 0); + } Sci::Line lineInsert = lv.LineFromPosition(position) + 1; bool atLineStart = lv.LineStart(lineInsert-1) == position; @@ -738,7 +753,9 @@ void CellBuffer::BasicDeleteChars(Sci::Position position, Sci::Position deleteLe } } substance.DeleteRange(position, deleteLength); - style.DeleteRange(position, deleteLength); + if (hasStyles) { + style.DeleteRange(position, deleteLength); + } } bool CellBuffer::SetUndoCollection(bool collectUndo) { diff --git a/scintilla/src/CellBuffer.h b/scintilla/src/CellBuffer.h index 784716ca4..0f4a009df 100644 --- a/scintilla/src/CellBuffer.h +++ b/scintilla/src/CellBuffer.h @@ -26,7 +26,7 @@ public: */ class LineVector { - Partitioning starts; + Partitioning starts; PerLine *perLine; public: @@ -135,6 +135,7 @@ public: */ class CellBuffer { private: + bool hasStyles; SplitVector substance; SplitVector style; bool readOnly; @@ -153,7 +154,7 @@ private: public: - CellBuffer(); + CellBuffer(bool hasStyles_); // Deleted so CellBuffer objects can not be copied. CellBuffer(const CellBuffer &) = delete; void operator=(const CellBuffer &) = delete; diff --git a/scintilla/src/ContractionState.cxx b/scintilla/src/ContractionState.cxx index 3c76d40d1..8777e4af9 100644 --- a/scintilla/src/ContractionState.cxx +++ b/scintilla/src/ContractionState.cxx @@ -35,11 +35,11 @@ ContractionState::~ContractionState() { void ContractionState::EnsureData() { if (OneToOne()) { - visible.reset(new RunStyles()); - expanded.reset(new RunStyles()); - heights.reset(new RunStyles()); + visible.reset(new RunStyles()); + expanded.reset(new RunStyles()); + heights.reset(new RunStyles()); foldDisplayTexts.reset(new SparseVector()); - displayLines.reset(new Partitioning(4)); + displayLines.reset(new Partitioning(4)); InsertLines(0, linesInDocument); } } diff --git a/scintilla/src/ContractionState.h b/scintilla/src/ContractionState.h index 517bf6258..7f11196ea 100644 --- a/scintilla/src/ContractionState.h +++ b/scintilla/src/ContractionState.h @@ -17,11 +17,11 @@ class SparseVector; */ class ContractionState { // These contain 1 element for every document line. - std::unique_ptr visible; - std::unique_ptr expanded; - std::unique_ptr heights; + std::unique_ptr> visible; + std::unique_ptr> expanded; + std::unique_ptr> heights; std::unique_ptr> foldDisplayTexts; - std::unique_ptr displayLines; + std::unique_ptr> displayLines; Sci::Line linesInDocument; void EnsureData(); diff --git a/scintilla/src/Decoration.h b/scintilla/src/Decoration.h index ab9912935..79ee9ef73 100644 --- a/scintilla/src/Decoration.h +++ b/scintilla/src/Decoration.h @@ -12,7 +12,7 @@ namespace Scintilla { class Decoration { int indicator; public: - RunStyles rs; + RunStyles rs; explicit Decoration(int indicator_); ~Decoration(); diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index 81d022097..a6f408f3e 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -89,7 +90,8 @@ int LexInterface::LineEndTypesSupported() { return 0; } -Document::Document() { +Document::Document(int options) : + cb((options & SC_DOCUMENTOPTION_STYLES_NONE) == 0) { refCount = 0; #ifdef _WIN32 eolMode = SC_EOL_CRLF; @@ -559,7 +561,7 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sc } Sci::Position Document::ClampPositionIntoDocument(Sci::Position pos) const { - return Sci::clamp(pos, 0, static_cast(Length())); + return std::clamp(pos, static_cast(0), static_cast(Length())); } bool Document::IsCrLf(Sci::Position pos) const { @@ -877,7 +879,7 @@ Sci::Position Document::GetRelativePositionUTF16(Sci::Position positionStart, Sc const Sci::Position posNext = NextPosition(pos, increment); if (posNext == pos) return INVALID_POSITION; - if (abs(pos-posNext) > 3) // 4 byte character = 2*UTF16. + if (std::abs(pos-posNext) > 3) // 4 byte character = 2*UTF16. characterOffset -= increment; pos = posNext; characterOffset -= increment; diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index ef8a14a38..3ad9b3715 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -267,7 +267,7 @@ public: DecorationList decorations; - Document(); + Document(int options); // Deleted so Document objects can not be copied. Document(const Document &) = delete; void operator=(const Document &) = delete; diff --git a/scintilla/src/EditModel.cxx b/scintilla/src/EditModel.cxx index 7dfd90e37..08888ba38 100644 --- a/scintilla/src/EditModel.cxx +++ b/scintilla/src/EditModel.cxx @@ -63,12 +63,13 @@ EditModel::EditModel() { highlightGuideColumn = 0; primarySelection = true; imeInteraction = imeWindowed; + bidirectional = Bidirectional::bidiDisabled; foldFlags = 0; foldDisplayTextStyle = SC_FOLDDISPLAYTEXT_HIDDEN; hotspot = Range(Sci::invalidPosition); hoverIndicatorPos = Sci::invalidPosition; wrapWidth = LineLayout::wrapWidthInfinite; - pdoc = new Document(); + pdoc = new Document(SC_DOCUMENTOPTION_DEFAULT); pdoc->AddRef(); } diff --git a/scintilla/src/EditModel.h b/scintilla/src/EditModel.h index 773309d45..6e4919bd5 100644 --- a/scintilla/src/EditModel.h +++ b/scintilla/src/EditModel.h @@ -38,6 +38,8 @@ public: enum IMEInteraction { imeWindowed, imeInline } imeInteraction; + enum class Bidirectional { bidiDisabled, bidiL2R, bidiR2L } bidirectional; + int foldFlags; int foldDisplayTextStyle; ContractionState cs; diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 816b50534..2a9b0ae95 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -11,8 +11,8 @@ #include #include #include - #include + #include #include #include @@ -900,11 +900,11 @@ SelectionPosition Editor::MovePositionSoVisible(SelectionPosition pos, int moveD Sci::Line lineDisplay = cs.DisplayFromDoc(lineDoc); if (moveDir > 0) { // lineDisplay is already line before fold as lines in fold use display line of line after fold - lineDisplay = Sci::clamp(lineDisplay, 0, cs.LinesDisplayed()); + lineDisplay = std::clamp(lineDisplay, static_cast(0), cs.LinesDisplayed()); return SelectionPosition(static_cast( pdoc->LineStart(cs.DocFromDisplay(lineDisplay)))); } else { - lineDisplay = Sci::clamp(lineDisplay - 1, 0, cs.LinesDisplayed()); + lineDisplay = std::clamp(lineDisplay - 1, static_cast(0), cs.LinesDisplayed()); return SelectionPosition(static_cast( pdoc->LineEnd(cs.DocFromDisplay(lineDisplay)))); } @@ -929,12 +929,12 @@ void Editor::SetLastXChosen() { } void Editor::ScrollTo(Sci::Line line, bool moveThumb) { - const Sci::Line topLineNew = Sci::clamp(line, 0, MaxScrollPos()); + const Sci::Line topLineNew = std::clamp(line, static_cast(0), MaxScrollPos()); if (topLineNew != topLine) { // Try to optimise small scrolls #ifndef UNDER_CE const Sci::Line linesToMove = topLine - topLineNew; - const bool performBlit = (abs(linesToMove) <= 10) && (paintState == notPainting); + const bool performBlit = (std::abs(linesToMove) <= 10) && (paintState == notPainting); willRedrawAll = !performBlit; #endif SetTopLine(topLineNew); @@ -1169,7 +1169,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } else { // yMarginT must equal to caretYSlop, with a minimum of 1 and // a maximum of slightly less than half the heigth of the text area. - yMarginT = Sci::clamp(caretYSlop, 1, halfScreen); + yMarginT = std::clamp(static_cast(caretYSlop), static_cast(1), halfScreen); if (bEven) { yMarginB = yMarginT; } else { @@ -1179,7 +1179,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran yMoveT = yMarginT; if (bEven) { if (bJump) { - yMoveT = Sci::clamp(caretYSlop * 3, 1, halfScreen); + yMoveT = std::clamp(static_cast(caretYSlop * 3), static_cast(1), halfScreen); } yMoveB = yMoveT; } else { @@ -1194,7 +1194,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } } else { // Not strict yMoveT = bJump ? caretYSlop * 3 : caretYSlop; - yMoveT = Sci::clamp(yMoveT, 1, halfScreen); + yMoveT = std::clamp(yMoveT, static_cast(1), halfScreen); if (bEven) { yMoveB = yMoveT; } else { @@ -1244,7 +1244,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran newXY.topLine = std::min(newXY.topLine, lineCaret); } } - newXY.topLine = Sci::clamp(newXY.topLine, 0, MaxScrollPos()); + newXY.topLine = std::clamp(newXY.topLine, static_cast(0), MaxScrollPos()); } // Horizontal positioning @@ -1266,7 +1266,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } else { // xMargin must equal to caretXSlop, with a minimum of 2 and // a maximum of slightly less than half the width of the text area. - xMarginR = Sci::clamp(caretXSlop, 2, halfScreen); + xMarginR = std::clamp(caretXSlop, 2, halfScreen); if (bEven) { xMarginL = xMarginR; } else { @@ -1275,7 +1275,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } if (bJump && bEven) { // Jump is used only in even mode - xMoveL = xMoveR = Sci::clamp(caretXSlop * 3, 1, halfScreen); + xMoveL = xMoveR = std::clamp(caretXSlop * 3, 1, halfScreen); } else { xMoveL = xMoveR = 0; // Not used, avoid a warning } @@ -1298,7 +1298,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran } } else { // Not strict xMoveR = bJump ? caretXSlop * 3 : caretXSlop; - xMoveR = Sci::clamp(xMoveR, 1, halfScreen); + xMoveR = std::clamp(xMoveR, 1, halfScreen); if (bEven) { xMoveL = xMoveR; } else { @@ -1510,7 +1510,7 @@ bool Editor::WrapLines(WrapScope ws) { const Sci::Line lineDocTop = cs.DocFromDisplay(topLine); const int subLineTop = topLine - cs.DisplayFromDoc(lineDocTop); if (ws == WrapScope::wsVisible) { - lineToWrap = Sci::clamp(lineDocTop-5, wrapPending.start, pdoc->LinesTotal()); + lineToWrap = std::clamp(lineDocTop-5, wrapPending.start, pdoc->LinesTotal()); // Priority wrap to just after visible area. // Since wrapping could reduce display lines, treat each // as taking only one display line. @@ -1566,7 +1566,7 @@ bool Editor::WrapLines(WrapScope ws) { if (wrapOccurred) { SetScrollBars(); - SetTopLine(Sci::clamp(goodTopLine, 0, MaxScrollPos())); + SetTopLine(std::clamp(goodTopLine, static_cast(0), MaxScrollPos())); SetVerticalScrollPos(); } @@ -1819,7 +1819,7 @@ void Editor::SetScrollBars() { // TODO: ensure always showing as many lines as possible // May not be, if, for example, window made larger if (topLine > MaxScrollPos()) { - SetTopLine(Sci::clamp(topLine, 0, MaxScrollPos())); + SetTopLine(std::clamp(topLine, static_cast(0), MaxScrollPos())); SetVerticalScrollPos(); Redraw(); } @@ -2623,7 +2623,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) { if (mh.linesAdded != 0) { // Avoid scrolling of display if change before current display if (mh.position < posTopLine && !CanDeferToLastStep(mh)) { - Sci::Line newTop = Sci::clamp(topLine + mh.linesAdded, 0, MaxScrollPos()); + Sci::Line newTop = std::clamp(topLine + mh.linesAdded, static_cast(0), MaxScrollPos()); if (newTop != topLine) { SetTopLine(newTop); SetVerticalScrollPos(); @@ -2859,8 +2859,8 @@ void Editor::PageMove(int direction, Selection::selTypes selt, bool stuttered) { } else { Point pt = LocationFromPosition(sel.MainCaret()); - topLineNew = Sci::clamp( - topLine + direction * LinesToScroll(), 0, MaxScrollPos()); + topLineNew = std::clamp( + topLine + direction * LinesToScroll(), static_cast(0), MaxScrollPos()); newPos = SPositionFromLocation( Point::FromInts(lastXChosen - xOffset, static_cast(pt.y) + direction * (vs.lineHeight * LinesToScroll())), false, false, UserVirtualSpace()); @@ -4455,7 +4455,7 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie if (shift && !inSelMargin) { SetSelection(newPos); } - if (((curTime - lastClickTime) < Platform::DoubleClickTime()) && Close(pt, lastClick, doubleClickCloseThreshold)) { + if ((curTime < (lastClickTime+Platform::DoubleClickTime())) && Close(pt, lastClick, doubleClickCloseThreshold)) { //Platform::DebugPrintf("Double click %d %d = %d\n", curTime, lastClickTime, curTime - lastClickTime); SetMouseCapture(true); FineTickerStart(tickScroll, 100, 10); @@ -5011,7 +5011,7 @@ Sci::Position Editor::PositionAfterMaxStyling(Sci::Position posMax, bool scrolli // When scrolling, allow less time to ensure responsive const double secondsAllowed = scrolling ? 0.005 : 0.02; - const Sci::Line linesToStyle = Sci::clamp(static_cast(secondsAllowed / pdoc->durationStyleOneLine), + const Sci::Line linesToStyle = std::clamp(static_cast(secondsAllowed / pdoc->durationStyleOneLine), 10, 0x10000); const Sci::Line stylingMaxLine = std::min( static_cast(pdoc->LineFromPosition(pdoc->GetEndStyled()) + linesToStyle), @@ -5165,7 +5165,7 @@ void Editor::SetDocPointer(Document *document) { pdoc->RemoveWatcher(this, 0); pdoc->Release(); if (document == NULL) { - pdoc = new Document(); + pdoc = new Document(SC_DOCUMENTOPTION_DEFAULT); } else { pdoc = document; } @@ -5362,18 +5362,18 @@ void Editor::EnsureLineVisible(Sci::Line lineDoc, bool enforcePolicy) { const Sci::Line lineDisplay = cs.DisplayFromDoc(lineDoc); if (visiblePolicy & VISIBLE_SLOP) { if ((topLine > lineDisplay) || ((visiblePolicy & VISIBLE_STRICT) && (topLine + visibleSlop > lineDisplay))) { - SetTopLine(Sci::clamp(lineDisplay - visibleSlop, 0, MaxScrollPos())); + SetTopLine(std::clamp(lineDisplay - visibleSlop, static_cast(0), MaxScrollPos())); SetVerticalScrollPos(); Redraw(); } else if ((lineDisplay > topLine + LinesOnScreen() - 1) || ((visiblePolicy & VISIBLE_STRICT) && (lineDisplay > topLine + LinesOnScreen() - 1 - visibleSlop))) { - SetTopLine(Sci::clamp(lineDisplay - LinesOnScreen() + 1 + visibleSlop, 0, MaxScrollPos())); + SetTopLine(std::clamp(lineDisplay - LinesOnScreen() + 1 + visibleSlop, static_cast(0), MaxScrollPos())); SetVerticalScrollPos(); Redraw(); } } else { if ((topLine > lineDisplay) || (lineDisplay > topLine + LinesOnScreen() - 1) || (visiblePolicy & VISIBLE_STRICT)) { - SetTopLine(Sci::clamp(lineDisplay - LinesOnScreen() / 2 + 1, 0, MaxScrollPos())); + SetTopLine(std::clamp(lineDisplay - LinesOnScreen() / 2 + 1, static_cast(0), MaxScrollPos())); SetVerticalScrollPos(); Redraw(); } @@ -5978,7 +5978,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return pdoc->MovePositionOutsideChar(static_cast(wParam) + 1, 1, true); case SCI_POSITIONRELATIVE: - return Sci::clamp(static_cast(pdoc->GetRelativePosition(static_cast(wParam), static_cast(lParam))), + return std::clamp(static_cast(pdoc->GetRelativePosition(static_cast(wParam), static_cast(lParam))), 0, static_cast(pdoc->Length())); case SCI_LINESCROLL: @@ -6739,6 +6739,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETIMEINTERACTION: return imeInteraction; + case SCI_SETBIDIRECTIONAL: + // SCI_SETBIDIRECTIONAL is implemented on platform subclasses if they support bidirectional text. + break; + + case SCI_GETBIDIRECTIONAL: + return static_cast(bidirectional); + // Marker definition and setting case SCI_MARKERDEFINE: if (wParam <= MARKER_MAX) { @@ -7550,8 +7557,9 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return 0; case SCI_CREATEDOCUMENT: { - Document *doc = new Document(); + Document *doc = new Document(static_cast(lParam)); doc->AddRef(); + doc->Allocate(static_cast(wParam)); return reinterpret_cast(doc); } @@ -7564,7 +7572,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; case SCI_CREATELOADER: { - Document *doc = new Document(); + Document *doc = new Document(static_cast(lParam)); doc->AddRef(); doc->Allocate(static_cast(wParam)); doc->SetUndoCollection(false); diff --git a/scintilla/src/Partitioning.h b/scintilla/src/Partitioning.h index 5835fc051..33eb15dc1 100644 --- a/scintilla/src/Partitioning.h +++ b/scintilla/src/Partitioning.h @@ -16,32 +16,33 @@ namespace Scintilla { /// in a range. /// Used by the Partitioning class. -class SplitVectorWithRangeAdd : public SplitVector { +template +class SplitVectorWithRangeAdd : public SplitVector { public: - explicit SplitVectorWithRangeAdd(int growSize_) { - SetGrowSize(growSize_); - ReAllocate(growSize_); + explicit SplitVectorWithRangeAdd(ptrdiff_t growSize_) { + this->SetGrowSize(growSize_); + this->ReAllocate(growSize_); } // Deleted so SplitVectorWithRangeAdd objects can not be copied. SplitVectorWithRangeAdd(const SplitVectorWithRangeAdd &) = delete; void operator=(const SplitVectorWithRangeAdd &) = delete; ~SplitVectorWithRangeAdd() { } - void RangeAddDelta(int start, int end, int delta) { + void RangeAddDelta(ptrdiff_t start, ptrdiff_t end, T delta) { // end is 1 past end, so end-start is number of elements to change - int i = 0; - const int rangeLength = end - start; - int range1Length = rangeLength; - const int part1Left = part1Length - start; + ptrdiff_t i = 0; + const ptrdiff_t rangeLength = end - start; + ptrdiff_t range1Length = rangeLength; + const ptrdiff_t part1Left = this->part1Length - start; if (range1Length > part1Left) range1Length = part1Left; while (i < range1Length) { - body[start++] += delta; + this->body[start++] += delta; i++; } - start += gapLength; + start += this->gapLength; while (i < rangeLength) { - body[start++] += delta; + this->body[start++] += delta; i++; } } @@ -54,36 +55,37 @@ public: /// When needed, positions after the interval are considered part of the last partition /// but the end of the last partition can be found with PositionFromPartition(last+1). +template class Partitioning { private: // To avoid calculating all the partition positions whenever any text is inserted // there may be a step somewhere in the list. - int stepPartition; - int stepLength; - std::unique_ptr body; + T stepPartition; + T stepLength; + std::unique_ptr> body; // Move step forward - void ApplyStep(int partitionUpTo) { + void ApplyStep(T partitionUpTo) { if (stepLength != 0) { body->RangeAddDelta(stepPartition+1, partitionUpTo + 1, stepLength); } stepPartition = partitionUpTo; if (stepPartition >= body->Length()-1) { - stepPartition = body->Length()-1; + stepPartition = Partitions(); stepLength = 0; } } // Move step backward - void BackStep(int partitionDownTo) { + void BackStep(T partitionDownTo) { if (stepLength != 0) { body->RangeAddDelta(partitionDownTo+1, stepPartition+1, -stepLength); } stepPartition = partitionDownTo; } - void Allocate(int growSize) { - body.reset(new SplitVectorWithRangeAdd(growSize)); + void Allocate(ptrdiff_t growSize) { + body.reset(new SplitVectorWithRangeAdd(growSize)); stepPartition = 0; stepLength = 0; body->Insert(0, 0); // This value stays 0 for ever @@ -102,11 +104,11 @@ public: ~Partitioning() { } - int Partitions() const { - return body->Length()-1; + T Partitions() const { + return static_cast(body->Length())-1; } - void InsertPartition(int partition, int pos) { + void InsertPartition(T partition, T pos) { if (stepPartition < partition) { ApplyStep(partition); } @@ -114,7 +116,7 @@ public: stepPartition++; } - void SetPartitionStartPosition(int partition, int pos) { + void SetPartitionStartPosition(T partition, T pos) { ApplyStep(partition+1); if ((partition < 0) || (partition > body->Length())) { return; @@ -122,7 +124,7 @@ public: body->SetValueAt(partition, pos); } - void InsertText(int partitionInsert, int delta) { + void InsertText(T partitionInsert, T delta) { // Point all the partitions after the insertion point further along in the buffer if (stepLength != 0) { if (partitionInsert >= stepPartition) { @@ -134,7 +136,7 @@ public: BackStep(partitionInsert); stepLength += delta; } else { - ApplyStep(body->Length()-1); + ApplyStep(Partitions()); stepPartition = partitionInsert; stepLength = delta; } @@ -144,7 +146,7 @@ public: } } - void RemovePartition(int partition) { + void RemovePartition(T partition) { if (partition > stepPartition) { ApplyStep(partition); stepPartition--; @@ -154,29 +156,29 @@ public: body->Delete(partition); } - int PositionFromPartition(int partition) const { + T PositionFromPartition(T partition) const { PLATFORM_ASSERT(partition >= 0); PLATFORM_ASSERT(partition < body->Length()); if ((partition < 0) || (partition >= body->Length())) { return 0; } - int pos = body->ValueAt(partition); + T pos = body->ValueAt(partition); if (partition > stepPartition) pos += stepLength; return pos; } /// Return value in range [0 .. Partitions() - 1] even for arguments outside interval - int PartitionFromPosition(int pos) const { + T PartitionFromPosition(T pos) const { if (body->Length() <= 1) return 0; - if (pos >= (PositionFromPartition(body->Length()-1))) - return body->Length() - 1 - 1; - int lower = 0; - int upper = body->Length()-1; + if (pos >= (PositionFromPartition(Partitions()))) + return Partitions() - 1; + T lower = 0; + T upper = Partitions(); do { - const int middle = (upper + lower + 1) / 2; // Round high - int posMiddle = body->ValueAt(middle); + const T middle = (upper + lower + 1) / 2; // Round high + T posMiddle = body->ValueAt(middle); if (middle > stepPartition) posMiddle += stepLength; if (pos < posMiddle) { diff --git a/scintilla/src/PerLine.cxx b/scintilla/src/PerLine.cxx index 5a213f719..2afbf3161 100644 --- a/scintilla/src/PerLine.cxx +++ b/scintilla/src/PerLine.cxx @@ -135,7 +135,7 @@ int LineMarkers::MarkValue(Sci::Line line) { Sci::Line LineMarkers::MarkerNext(Sci::Line lineStart, int mask) const { if (lineStart < 0) lineStart = 0; - const Sci::Line length = markers.Length(); + const Sci::Line length = static_cast(markers.Length()); for (Sci::Line iLine = lineStart; iLine < length; iLine++) { const MarkerHandleSet *onLine = markers[iLine].get(); if (onLine && ((onLine->MarkValue() & mask) != 0)) @@ -281,7 +281,7 @@ int LineState::GetLineState(Sci::Line line) { } Sci::Line LineState::GetMaxLineState() const { - return lineStates.Length(); + return static_cast(lineStates.Length()); } static int NumberLines(const char *text) { diff --git a/scintilla/src/Position.h b/scintilla/src/Position.h index 258eb177f..557655a5d 100644 --- a/scintilla/src/Position.h +++ b/scintilla/src/Position.h @@ -11,6 +11,7 @@ /** * A Position is a position within a document between two characters or at the beginning or end. * Sometimes used as a character index where it identifies the character after the position. + * A Line is a document or screen line. */ namespace Sci { @@ -25,14 +26,6 @@ typedef int Line; const Position invalidPosition = -1; -inline int clamp(int val, int minVal, int maxVal) { - if (val > maxVal) - val = maxVal; - if (val < minVal) - val = minVal; - return val; -} - } #endif diff --git a/scintilla/src/PositionCache.cxx b/scintilla/src/PositionCache.cxx index 0b563f525..99e3c4d56 100644 --- a/scintilla/src/PositionCache.cxx +++ b/scintilla/src/PositionCache.cxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "Platform.h" @@ -378,7 +379,7 @@ static inline int KeyFromString(const char *charBytes, size_t len) { } SpecialRepresentations::SpecialRepresentations() { - std::fill(startByteHasReprs, startByteHasReprs+0x100, static_cast(0)); + std::fill(startByteHasReprs, std::end(startByteHasReprs), static_cast(0)); } void SpecialRepresentations::SetRepresentation(const char *charBytes, const char *value) { @@ -419,7 +420,7 @@ bool SpecialRepresentations::Contains(const char *charBytes, size_t len) const { void SpecialRepresentations::Clear() { mapReprs.clear(); - std::fill(startByteHasReprs, startByteHasReprs+0x100, static_cast(0)); + std::fill(startByteHasReprs, std::end(startByteHasReprs), static_cast(0)); } void BreakFinder::Insert(int val) { diff --git a/scintilla/src/RESearch.cxx b/scintilla/src/RESearch.cxx index 31ee9aaac..f7ae04974 100644 --- a/scintilla/src/RESearch.cxx +++ b/scintilla/src/RESearch.cxx @@ -205,6 +205,7 @@ #include #include #include +#include #include "Position.h" #include "CharClassify.h" @@ -254,9 +255,9 @@ RESearch::RESearch(CharClassify *charClassTable) { charClass = charClassTable; sta = NOP; /* status of lastpat */ bol = 0; - std::fill(bittab, bittab + BITBLK, static_cast(0)); - std::fill(tagstk, tagstk + MAXTAG, 0); - std::fill(nfa, nfa + MAXNFA, '\0'); + std::fill(bittab, std::end(bittab), static_cast(0)); + std::fill(tagstk, std::end(tagstk), 0); + std::fill(nfa, std::end(nfa), '\0'); Clear(); } diff --git a/scintilla/src/RunStyles.cxx b/scintilla/src/RunStyles.cxx index f6d3d413b..f3939bbd2 100644 --- a/scintilla/src/RunStyles.cxx +++ b/scintilla/src/RunStyles.cxx @@ -26,8 +26,9 @@ using namespace Scintilla; // Find the first run at a position -int RunStyles::RunFromPosition(int position) const { - int run = starts->PartitionFromPosition(position); +template +DISTANCE RunStyles::RunFromPosition(DISTANCE position) const { + DISTANCE run = starts->PartitionFromPosition(position); // Go to first element with this position while ((run > 0) && (position == starts->PositionFromPartition(run-1))) { run--; @@ -36,11 +37,12 @@ int RunStyles::RunFromPosition(int position) const { } // If there is no run boundary at position, insert one continuing style. -int RunStyles::SplitRun(int position) { - int run = RunFromPosition(position); - const int posRun = starts->PositionFromPartition(run); +template +DISTANCE RunStyles::SplitRun(DISTANCE position) { + DISTANCE run = RunFromPosition(position); + const DISTANCE posRun = starts->PositionFromPartition(run); if (posRun < position) { - int runStyle = ValueAt(position); + STYLE runStyle = ValueAt(position); run++; starts->InsertPartition(run, position); styles->InsertValue(run, 1, runStyle); @@ -48,12 +50,14 @@ int RunStyles::SplitRun(int position) { return run; } -void RunStyles::RemoveRun(int run) { +template +void RunStyles::RemoveRun(DISTANCE run) { starts->RemovePartition(run); styles->DeleteRange(run, 1); } -void RunStyles::RemoveRunIfEmpty(int run) { +template +void RunStyles::RemoveRunIfEmpty(DISTANCE run) { if ((run < starts->Partitions()) && (starts->Partitions() > 1)) { if (starts->PositionFromPartition(run) == starts->PositionFromPartition(run+1)) { RemoveRun(run); @@ -61,7 +65,8 @@ void RunStyles::RemoveRunIfEmpty(int run) { } } -void RunStyles::RemoveRunIfSameAsPrevious(int run) { +template +void RunStyles::RemoveRunIfSameAsPrevious(DISTANCE run) { if ((run > 0) && (run < starts->Partitions())) { if (styles->ValueAt(run-1) == styles->ValueAt(run)) { RemoveRun(run); @@ -69,30 +74,35 @@ void RunStyles::RemoveRunIfSameAsPrevious(int run) { } } -RunStyles::RunStyles() { - starts.reset(new Partitioning(8)); - styles.reset(new SplitVector()); +template +RunStyles::RunStyles() { + starts.reset(new Partitioning(8)); + styles.reset(new SplitVector