aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/PerLine.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2023-01-19 13:28:57 +1100
committerNeil <nyamatongwe@gmail.com>2023-01-19 13:28:57 +1100
commit66f54388680a2617144e2bd3b4610f431c37fc02 (patch)
tree1bae29e1f6e25854fe5916782206a960c129a524 /src/PerLine.cxx
parent6039080cfba2b9344fa9cde2ba5688d2db590d66 (diff)
downloadscintilla-mirror-66f54388680a2617144e2bd3b4610f431c37fc02.tar.gz
Feature [feature-requests:#1444] Move GetFoldParent from Document to LineLevels
as better modularity. Add LineLevels::GetFoldLevel for better type safety. Simplify bounds checks in GetLevel and GetFoldLevel.
Diffstat (limited to 'src/PerLine.cxx')
-rw-r--r--src/PerLine.cxx23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/PerLine.cxx b/src/PerLine.cxx
index 78f7c7dc5..4d76b0b79 100644
--- a/src/PerLine.cxx
+++ b/src/PerLine.cxx
@@ -264,11 +264,28 @@ int LineLevels::SetLevel(Sci::Line line, int level, Sci::Line lines) {
}
int LineLevels::GetLevel(Sci::Line line) const noexcept {
- if (levels.Length() && (line >= 0) && (line < levels.Length())) {
+ if ((line >= 0) && (line < levels.Length())) {
return levels[line];
- } else {
- return static_cast<int>(Scintilla::FoldLevel::Base);
}
+ return static_cast<int>(Scintilla::FoldLevel::Base);
+}
+
+Scintilla::FoldLevel LineLevels::GetFoldLevel(Sci::Line line) const noexcept {
+ if ((line >= 0) && (line < levels.Length())) {
+ return static_cast<FoldLevel>(levels[line]);
+ }
+ return Scintilla::FoldLevel::Base;
+}
+
+Sci::Line LineLevels::GetFoldParent(Sci::Line line) const noexcept {
+ const FoldLevel level = LevelNumberPart(GetFoldLevel(line));
+ for (Sci::Line lineLook = line - 1; lineLook >= 0; lineLook--) {
+ const FoldLevel levelTry = GetFoldLevel(lineLook);
+ if (LevelIsHeader(levelTry) && LevelNumberPart(levelTry) < level) {
+ return lineLook;
+ }
+ }
+ return -1;
}
void LineState::Init() {