Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LexProps: don't set header flag for empty section #96

Closed
zufuliu opened this issue Jul 26, 2022 · 8 comments
Closed

LexProps: don't set header flag for empty section #96

zufuliu opened this issue Jul 26, 2022 · 8 comments
Labels
committed Issue fixed in repository but not in release props Caused by the props lexer

Comments

@zufuliu
Copy link
Contributor

zufuliu commented Jul 26, 2022

To prevent FoldAction::Toggle failure and avoid showing fold display text after toggle folds.

diff --git a/lexers/LexProps.cxx b/lexers/LexProps.cxx
index 7dadb2c6..b869659a 100644
--- a/lexers/LexProps.cxx
+++ b/lexers/LexProps.cxx
@@ -154,6 +154,10 @@ static void FoldPropsDoc(Sci_PositionU startPos, Sci_Position length, int, WordL
 
 			if (headerPoint) {
 				lev |= SC_FOLDLEVELHEADERFLAG;
+				if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
+					// empty section
+					styler.SetLevel(lineCurrent - 1, SC_FOLDLEVELBASE);
+				}
 			}
 			if (lev != styler.LevelAt(lineCurrent)) {
 				styler.SetLevel(lineCurrent, lev);
zufuliu added a commit to zufuliu/notepad4 that referenced this issue Jul 26, 2022
@nyamatongwe
Copy link
Member

Is there an example file?

@nyamatongwe nyamatongwe added the props Caused by the props lexer label Jul 26, 2022
@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 26, 2022

An example, toggle folds not fails in SciTE (not sure why), fold display text can't be tested in SciTE.

; comment
[empty section]
[normal section]
@=default
key=value

Edit: updated example to list all styles.

@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 26, 2022

Full code for FoldPropsDoc(), moved levelPrevious out from the loop.
FoldPropsDoc.zip

@nyamatongwe
Copy link
Member

FoldPropsDoc.zip won't compile as lev is used in the epilogue but its declaration is now in an inner scope. I expect it would be better as:

	int lev = levelPrevious & SC_FOLDLEVELNUMBERMASK;
	if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
		lev = SC_FOLDLEVELBASE + 1;
	}

Or with another name to avoid shadowing. The inner declaration of lev could also be initialised to levelPrevious & SC_FOLDLEVELNUMBERMASK to avoid uninitialized variable warnings.

@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 26, 2022

It seems last styler.SetLevel(lineCurrent, lev | (flagsNext & ~SC_FOLDLEVELNUMBERMASK)); can be removed (change inner code to use if (atEOL || i == (endPos - 1)) {), not sure what it want archive.

@nyamatongwe
Copy link
Member

This pattern is used to avoid transient changes (and potential unfolding) due to not running the full logic past the end. It may or may not be needed in this case.

@zufuliu
Copy link
Contributor Author

zufuliu commented Jul 26, 2022

Changed to following

int level = levelPrevious & SC_FOLDLEVELNUMBERMASK;
if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
	level += 1;
}

FoldPropsDoc-0727.zip

@nyamatongwe nyamatongwe added the committed Issue fixed in repository but not in release label Jul 27, 2022
@nyamatongwe
Copy link
Member

Included in 5.1.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
committed Issue fixed in repository but not in release props Caused by the props lexer
Projects
None yet
Development

No branches or pull requests

2 participants