diff --git a/scintilla/gtk/ScintillaGTK.cxx b/scintilla/gtk/ScintillaGTK.cxx index 92fc064a..88d91167 100644 --- a/scintilla/gtk/ScintillaGTK.cxx +++ b/scintilla/gtk/ScintillaGTK.cxx @@ -1747,7 +1747,7 @@ void ScintillaGTK::Resize(int width, int height) { minVScrollBarHeight = minimum.height; verticalScrollBarWidth = requisition.width; gtk_widget_get_preferred_size(PWidget(scrollbarh), &minimum, &requisition); - minHScrollBarWidth = minimum.height; + minHScrollBarWidth = minimum.width; horizontalScrollBarHeight = requisition.height; #else minVScrollBarHeight = minHScrollBarWidth = 1; diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index 99bc6e7b..8f0cd44b 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -895,6 +895,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCVS_NONE 0 #define SCVS_RECTANGULARSELECTION 1 #define SCVS_USERACCESSIBLE 2 +#define SCVS_NOWRAPLINESTART 4 #define SCI_SETVIRTUALSPACEOPTIONS 2596 #define SCI_GETVIRTUALSPACEOPTIONS 2597 #define SCI_SETRECTANGULARSELECTIONMODIFIER 2598 diff --git a/scintilla/include/Scintilla.iface b/scintilla/include/Scintilla.iface index 310d877a..140cb70f 100644 --- a/scintilla/include/Scintilla.iface +++ b/scintilla/include/Scintilla.iface @@ -2331,6 +2331,7 @@ enu VirtualSpace=SCVS_ val SCVS_NONE=0 val SCVS_RECTANGULARSELECTION=1 val SCVS_USERACCESSIBLE=2 +val SCVS_NOWRAPLINESTART=4 set void SetVirtualSpaceOptions=2596(int virtualSpaceOptions,) get int GetVirtualSpaceOptions=2597(,) diff --git a/scintilla/lexers/LexAbaqus.cxx b/scintilla/lexers/LexAbaqus.cxx index 509d89a0..5f265c72 100644 --- a/scintilla/lexers/LexAbaqus.cxx +++ b/scintilla/lexers/LexAbaqus.cxx @@ -581,14 +581,14 @@ WordList *[], Accessor &styler) { for ( Sci_Position ll = beginData; ll < beginComment; ll++ ) SafeSetLevel(ll, datLevel, styler) ; - if ( prvKeyLineTp == 5 ) { - level += 1 ; - } + if ( prvKeyLineTp == 5 ) { + level += 1 ; + } - if ( prvKeyLineTp == 6 ) { - level -= 1 ; - } - for ( Sci_Position m = beginComment; m <= endLine; m++ ) + if ( prvKeyLineTp == 6 ) { + level -= 1 ; + } + for ( Sci_Position m = beginComment; m <= endLine; m++ ) SafeSetLevel(m, level, styler) ; } diff --git a/scintilla/lexers/LexCPP.cxx b/scintilla/lexers/LexCPP.cxx index 4261084d..64387a08 100644 --- a/scintilla/lexers/LexCPP.cxx +++ b/scintilla/lexers/LexCPP.cxx @@ -229,7 +229,7 @@ struct PPDefinition { std::string value; bool isUndef; std::string arguments; - PPDefinition(Sci_Position line_, const std::string &key_, const std::string &value_, bool isUndef_ = false, std::string arguments_="") : + PPDefinition(Sci_Position line_, const std::string &key_, const std::string &value_, bool isUndef_ = false, const std::string &arguments_="") : line(line_), key(key_), value(value_), isUndef(isUndef_), arguments(arguments_) { } }; @@ -320,6 +320,7 @@ struct OptionsCPP { std::string foldExplicitEnd; bool foldExplicitAnywhere; bool foldPreprocessor; + bool foldPreprocessorAtElse; bool foldCompact; bool foldAtElse; OptionsCPP() { @@ -341,6 +342,7 @@ struct OptionsCPP { foldExplicitEnd = ""; foldExplicitAnywhere = false; foldPreprocessor = false; + foldPreprocessorAtElse = false; foldCompact = false; foldAtElse = false; } @@ -411,6 +413,9 @@ struct OptionSetCPP : public OptionSet { DefineProperty("fold.cpp.explicit.anywhere", &OptionsCPP::foldExplicitAnywhere, "Set this property to 1 to enable explicit fold points anywhere, not just in line comments."); + + DefineProperty("fold.cpp.preprocessor.at.else", &OptionsCPP::foldPreprocessorAtElse, + "This option enables folding on a preprocessor #else or #endif line of an #if statement."); DefineProperty("fold.preprocessor", &OptionsCPP::foldPreprocessor, "This option enables folding preprocessor directives when using the C++ lexer. " @@ -1349,13 +1354,17 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int } else if (styler.Match(j, "end")) { levelNext--; } + + if (options.foldPreprocessorAtElse && (styler.Match(j, "else") || styler.Match(j, "elif"))) { + levelMinCurrent--; + } } } if (options.foldSyntaxBased && (style == SCE_C_OPERATOR)) { if (ch == '{' || ch == '[' || ch == '(') { // Measure the minimum before a '{' to allow // folding on "} else {" - if (levelMinCurrent > levelNext) { + if (options.foldAtElse && levelMinCurrent > levelNext) { levelMinCurrent = levelNext; } levelNext++; @@ -1367,7 +1376,9 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int visibleChars++; if (atEOL || (i == endPos-1)) { int levelUse = levelCurrent; - if (options.foldSyntaxBased && options.foldAtElse) { + if ((options.foldSyntaxBased && options.foldAtElse) || + (options.foldPreprocessor && options.foldPreprocessorAtElse) + ) { levelUse = levelMinCurrent; } int lev = levelUse | levelNext << 16; diff --git a/scintilla/lexers/LexHTML.cxx b/scintilla/lexers/LexHTML.cxx index 43f51de6..bd14534d 100644 --- a/scintilla/lexers/LexHTML.cxx +++ b/scintilla/lexers/LexHTML.cxx @@ -610,6 +610,17 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } styler.StartAt(startPos); + /* Nothing handles getting out of these, so we need not start in any of them. + * As we're at line start and they can't span lines, we'll re-detect them anyway */ + switch (state) { + case SCE_H_QUESTION: + case SCE_H_XMLSTART: + case SCE_H_XMLEND: + case SCE_H_ASP: + state = SCE_H_DEFAULT; + break; + } + Sci_Position lineCurrent = styler.GetLine(startPos); int lineState; if (lineCurrent > 0) { @@ -898,7 +909,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i ///////////////////////////////////// // handle the start of PHP pre-processor = Non-HTML else if ((state != SCE_H_ASPAT) && - !isPHPStringState(state) && + !isStringState(state) && (state != SCE_HPHP_COMMENT) && (state != SCE_HPHP_COMMENTLINE) && (ch == '<') && diff --git a/scintilla/src/CharClassify.cxx b/scintilla/src/CharClassify.cxx index 595b0da3..8678e6d6 100644 --- a/scintilla/src/CharClassify.cxx +++ b/scintilla/src/CharClassify.cxx @@ -44,7 +44,7 @@ void CharClassify::SetCharClasses(const unsigned char *chars, cc newCharClass) { } } -int CharClassify::GetCharsOfClass(cc characterClass, unsigned char *buffer) { +int CharClassify::GetCharsOfClass(cc characterClass, unsigned char *buffer) const { // Get characters belonging to the given char class; return the number // of characters (if the buffer is NULL, don't write to it). int count = 0; diff --git a/scintilla/src/CharClassify.h b/scintilla/src/CharClassify.h index 5d2734c0..63e8e8be 100644 --- a/scintilla/src/CharClassify.h +++ b/scintilla/src/CharClassify.h @@ -19,7 +19,7 @@ public: enum cc { ccSpace, ccNewLine, ccWord, ccPunctuation }; void SetDefaultCharClasses(bool includeWordClass); void SetCharClasses(const unsigned char *chars, cc newCharClass); - int GetCharsOfClass(cc charClass, unsigned char *buffer); + int GetCharsOfClass(cc charClass, unsigned char *buffer) const; cc GetClass(unsigned char ch) const { return static_cast(charClass[ch]);} bool IsWord(unsigned char ch) const { return static_cast(charClass[ch]) == ccWord;} diff --git a/scintilla/src/Document.cxx b/scintilla/src/Document.cxx index d96a889b..f10e40aa 100644 --- a/scintilla/src/Document.cxx +++ b/scintilla/src/Document.cxx @@ -1823,7 +1823,7 @@ void Document::SetCharClasses(const unsigned char *chars, CharClassify::cc newCh charClass.SetCharClasses(chars, newCharClass); } -int Document::GetCharsOfClass(CharClassify::cc characterClass, unsigned char *buffer) { +int Document::GetCharsOfClass(CharClassify::cc characterClass, unsigned char *buffer) const { return charClass.GetCharsOfClass(characterClass, buffer); } diff --git a/scintilla/src/Document.h b/scintilla/src/Document.h index d82aa46b..d31465f6 100644 --- a/scintilla/src/Document.h +++ b/scintilla/src/Document.h @@ -401,7 +401,7 @@ public: void SetDefaultCharClasses(bool includeWordClass); void SetCharClasses(const unsigned char *chars, CharClassify::cc newCharClass); - int GetCharsOfClass(CharClassify::cc characterClass, unsigned char *buffer); + int GetCharsOfClass(CharClassify::cc characterClass, unsigned char *buffer) const; void SCI_METHOD StartStyling(Sci_Position position, char mask); bool SCI_METHOD SetStyleFor(Sci_Position length, char style); bool SCI_METHOD SetStyles(Sci_Position length, const char *styles); diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 12539962..f9ac97b4 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/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()); @@ -3283,7 +3293,7 @@ int Editor::HorizontalMove(unsigned int iMessage) { case SCI_CHARLEFTRECTEXTEND: if (pdoc->IsLineEndPosition(spCaret.Position()) && spCaret.VirtualSpace()) { spCaret.SetVirtualSpace(spCaret.VirtualSpace() - 1); - } else { + } else if ((virtualSpaceOptions & SCVS_NOWRAPLINESTART) == 0 || pdoc->GetColumn(spCaret.Position()) > 0) { spCaret = SelectionPosition(spCaret.Position() - 1); } break; @@ -3328,7 +3338,7 @@ int Editor::HorizontalMove(unsigned int iMessage) { case SCI_CHARLEFTEXTEND: if (spCaret.VirtualSpace()) { spCaret.SetVirtualSpace(spCaret.VirtualSpace() - 1); - } else { + } else if ((virtualSpaceOptions & SCVS_NOWRAPLINESTART) == 0 || pdoc->GetColumn(spCaret.Position()) > 0) { spCaret = SelectionPosition(spCaret.Position() - 1); } break; @@ -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(convertedText.length())); if (lengthInserted > 0) { @@ -5293,6 +5303,9 @@ void Editor::FoldExpand(int line, int action, int level) { if (action == SC_FOLDACTION_TOGGLE) { expanding = !cs.GetExpanded(line); } + // Ensure child lines lexed and fold information extracted before + // flipping the state. + pdoc->GetLastChild(line, LevelNumber(level)); SetFoldExpanded(line, expanding); if (expanding && (cs.HiddenLines() == 0)) // Nothing to do diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index 93a86fa3..72d4719e 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/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/scintilla/src/ScintillaBase.cxx b/scintilla/src/ScintillaBase.cxx index b6e2fb33..92605d9b 100644 --- a/scintilla/src/ScintillaBase.cxx +++ b/scintilla/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); diff --git a/scintilla/src/XPM.cxx b/scintilla/src/XPM.cxx index 20e6c8bf..4841e4ff 100644 --- a/scintilla/src/XPM.cxx +++ b/scintilla/src/XPM.cxx @@ -22,13 +22,13 @@ using namespace Scintilla; static const char *NextField(const char *s) { // In case there are leading spaces in the string - while (*s && *s == ' ') { + while (*s == ' ') { s++; } while (*s && *s != ' ') { s++; } - while (*s && *s == ' ') { + while (*s == ' ') { s++; } return s; diff --git a/scintilla/version.txt b/scintilla/version.txt index 4203007d..526204c8 100644 --- a/scintilla/version.txt +++ b/scintilla/version.txt @@ -1 +1 @@ -366 +367