aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorZufu Liu <unknown>2021-06-04 20:27:18 +1000
committerZufu Liu <unknown>2021-06-04 20:27:18 +1000
commit879f0c4c60bd3ba9c75a0f83495eebc7aee66860 (patch)
tree7aa7a1d1485a0ccd131c428d28400a1f4b2dabe0 /src
parentb88a820dee352c68e1bf9616d54c1804bf8a15a0 (diff)
downloadscintilla-mirror-879f0c4c60bd3ba9c75a0f83495eebc7aee66860.tar.gz
Bug [#2260]. Fix bug with SCI_GETLASTCHILD when lParam is -1.
Fixed cast on SCI_FOLDCHILDREN to use correct type.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx5
-rw-r--r--src/Editor.cxx4
-rw-r--r--src/Editor.h7
3 files changed, 11 insertions, 5 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 74701bd8c..6531ad264 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -525,14 +525,13 @@ static bool IsSubordinate(FoldLevel levelStart, FoldLevel levelTry) noexcept {
}
Sci::Line Document::GetLastChild(Sci::Line lineParent, std::optional<FoldLevel> level, Sci::Line lastLine) {
- if (!level)
- level = LevelNumberPart(GetFoldLevel(lineParent));
+ const FoldLevel levelStart = level.value_or(LevelNumberPart(GetFoldLevel(lineParent)));
const Sci::Line maxLine = LinesTotal();
const Sci::Line lookLastLine = (lastLine != -1) ? std::min(LinesTotal() - 1, lastLine) : -1;
Sci::Line lineMaxSubord = lineParent;
while (lineMaxSubord < maxLine - 1) {
EnsureStyledTo(LineStart(lineMaxSubord + 2));
- if (!IsSubordinate(*level, GetFoldLevel(lineMaxSubord + 1)))
+ if (!IsSubordinate(levelStart, GetFoldLevel(lineMaxSubord + 1)))
break;
if ((lookLastLine != -1) && (lineMaxSubord >= lookLastLine) && !LevelIsWhitespace(GetFoldLevel(lineMaxSubord)))
break;
diff --git a/src/Editor.cxx b/src/Editor.cxx
index e208260ab..f59eb5785 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -7363,7 +7363,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
return pdoc->GetLevel(static_cast<Sci::Line>(wParam));
case Message::GetLastChild:
- return pdoc->GetLastChild(static_cast<Sci::Line>(wParam), static_cast<FoldLevel>(lParam));
+ return pdoc->GetLastChild(static_cast<Sci::Line>(wParam), OptionalFoldLevel(lParam));
case Message::GetFoldParent:
return pdoc->GetFoldParent(static_cast<Sci::Line>(wParam));
@@ -7436,7 +7436,7 @@ sptr_t Editor::WndProc(Message iMessage, uptr_t wParam, sptr_t lParam) {
break;
case Message::FoldChildren:
- FoldExpand(static_cast<Sci::Line>(wParam), static_cast<FoldAction>(lParam), pdoc->GetFoldLevel(static_cast<int>(wParam)));
+ FoldExpand(static_cast<Sci::Line>(wParam), static_cast<FoldAction>(lParam), pdoc->GetFoldLevel(static_cast<Sci::Line>(wParam)));
break;
case Message::FoldAll:
diff --git a/src/Editor.h b/src/Editor.h
index 08e7d134b..9af2add43 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -624,6 +624,13 @@ protected: // ScintillaBase subclass needs access to much of Editor
return static_cast<const char *>(PtrFromUPtr(wParam));
}
+ constexpr std::optional<FoldLevel> OptionalFoldLevel(Scintilla::sptr_t lParam) {
+ if (lParam >= 0) {
+ return static_cast<FoldLevel>(lParam);
+ }
+ return std::nullopt;
+ }
+
static Scintilla::sptr_t StringResult(Scintilla::sptr_t lParam, const char *val) noexcept;
static Scintilla::sptr_t BytesResult(Scintilla::sptr_t lParam, const unsigned char *val, size_t len) noexcept;