Closed cithukyaw closed 9 years ago
Are there any steps to consistently reproduce this issue? For instance, is the file being changed from a different editor (or another instance of brackets), or after a git pull?
the file being is changed from a different editor
Yes
the file being is changed from another instance of brackets
Yes
after a git pull
Yes, when some changes made from git such as discard hunk, discard file, pull, etc.
Ok that makes sense. Since fold ranges are persisted as line numbers. The problem is that the changes made to the text sometimes invalidate the saved fold states - e.g. when new lines are added or removed. This is quite straightforward to detect and the inconsistent fold states can be cleared.
Okay. In addition to new lines or remove, It is affected by even single character change. I tested with a single space change in a line.
Thanks for the info. Can you test the latest version on master by installing manually and let me know if the issue has been resolved?
Thanks for the fix. It sounds good, but it stills have some issues. Let's say for example, I have the following saved code folding state.
1. this.create = function(req, resp, params) { <> };
2. this.read = function(req, resp, params) { <> };
3. this.update = function(req, resp, params) { <> };
Here are some test cases and their results:
update
at line 3 by adding a new line or removing a line, the code folding at line 1 and 2 are opened. (Expected: should not be opened)update
at line 3 without adding new line, e.g. adding/removing a character, all folding states remain as their previous states. (Expected: Ok)Thanks for the example. Let's make the expectations a bit more explicit (all with respect to the example you've given above).
update
at line 3 by adding a new line or removing a line, the code folding at line 1 and 2 should not be opened. Code folded at line 3 should be opened since the additional/ removed line changes the folded range that is stored in Brackets.update
at line 3 without adding new line, e.g. adding/removing a character, all folding state remains as their previous states.The main reason for these differences when editing from outside brackets is that the changeEvent in codeMirror is different when the document's entire content is being set (this is essentially what happens when the document is modified externally). The event is modelled as if the entire document content has been deleted and then replaced with new content even if one character or one line was added. This is understandable since there could have been multiple edits on various lines for the change event.
Thanks for testing! If you disagree of have ideas about how to better resolve the issue do shout. I'll push more fixes shortly.
I agree with most of your expectations except 1 and 2 of
Any folded regions below the new line however would be cleared
Let's say for example, I have a long lines of code file and it has many folded regions. If I added a new line at the top or almost top of the file, all intentional folded regions below the new line would be cleared and opened. I believe it is not a comfortable situation.
I expected to not clear them, but does it seem impossible because of the folded regions saved with line numbers and because of the line numbers changed? However, I have an idea with (may-be) less possibility to resolve it. I commented in your foldgutter.js. Please check it
Unfortunately if those changes are made from outside brackets then this is a consistent way to reflect the changes on the folded regions. See my response to your comment to see the reason why. Feel free to suggest any clean, predictable and stable workarounds.
Another problem noticed. git stash
and git stash pop
which contained the working file did not make any changes to the file unless F5 is pressed. I'm not sure if it is related to this fix.
@cithukyaw Could you further explain your latest comment? e.g., what is the expected vs actual outcome? Is the issue even related to code folding?
Sorry, I guess it is not related to code folding. The code editor is not refreshing when any change was made from outside (git in this case). I'm not sure what is related to the issue. I will remove my unrelated comments.
no problem. Depending on whether you are using the git extension or git commandline to issue the stash commands you might want a report and issue appropriately.
I'm having what appears to be a similar problem. I am not using an external editor and only "git" through Bracket's git plugin.
(Hopefully I'm not showing anything I shouldn't be here!)
You'll notice in this shot that the "var gulp ..." does not provide any folding arrow (although clicking where the arrow would be works). The "var server..." line shows itself as collapsed when it isn't. Clicking the collapse arrow collapses not just the "server." stuff but also the next 155 lines.
Let me know what else I can provide!
@nathanziarek can you install the latest version of code-folding extension from git (if you don't already have it) and let me know if the issue persists.
Having done that, I'm seeing the same thing. It saved the collapsed sections as well. Is there another preference file I should blast to see if it's just something corrupted?
I'm new to the guts of Brackets and didn't know there was a developer console ... not sure if this helps?
Exception in 'activeEditorChange' listener on Object TypeError: Cannot read property 'lastIndexOf' of undefined TypeError: Cannot read property 'lastIndexOf' of undefined
at findOpening (file:///Applications/Brackets.app/Contents/www/thirdparty/CodeMirror2/addon/fold/brace-fold.js:20:43)
at Array.<anonymous> (file:///Applications/Brackets.app/Contents/www/thirdparty/CodeMirror2/addon/fold/brace-fold.js:34:51)
at file:///Users/nathanziarek/Library/Application%20Support/Brackets/extensions/user/brackets-code-folding/foldhelpers/foldcode.js:210:33
at file:///Users/nathanziarek/Library/Application%20Support/Brackets/extensions/user/brackets-code-folding/foldhelpers/foldcode.js:132:29
at Array.forEach (native)
at null.getValidFolds (file:///Users/nathanziarek/Library/Application%20Support/Brackets/extensions/user/brackets-code-folding/foldhelpers/foldcode.js:130:22)
at restoreLineFolds (file:///Users/nathanziarek/Library/Application%20Support/Brackets/extensions/user/brackets-code-folding/main.js:123:32)
at onActiveEditorChanged (file:///Users/nathanziarek/Library/Application%20Support/Brackets/extensions/user/brackets-code-folding/main.js:263:4)
at Object.trigger (/utils/EventDispatcher.js:222:40)
at _notifyActiveEditorChanged (/editor/EditorManager.js:165:17)main.js:116 (anonymous function)
Looks like the saved fold states were being loaded. Shift-Alt-1 to clear all regions. Then try to reproduce the original issue. Please post any additional errors that appear in the console. They are useful.
Shift-Alt-1 cleared the current folding, but didn't fix the issue. Uninstalled, reinstalled from master and same weird artifacts (notice the folded triangle at the last line):
The error is different. Maybe this is an interaction between the git plugin and code folding? If so, I'm sorry to have wasted your time!
@nathanziarek could you find the state.json file in your app-data directory. It should be in the same directory as the brackets.json file opened by Debug > Open Preferences File
. To completely clear the old folded states, you need to find the code-folding.folds
key in the state.json
file and delete that. Then try to reproduce the issue. I'm not 100% convinced it is an interaction between the two extensions. I'd love to get to the bottom of it.
Cheers
That seems to have done it!
For posterity: Maybe it's obvious, but I couldn't edit the state.json
file in Brackets--any time I edited it and saved it would magically plop that key right back in there.
There is still one remaining issue: When I fold my first line, it collapses the entire document.
...becomes...
I saved the code-folding.folds
JSON if it was interesting. Nothing confidential in there I can see ... let me know if it'd be helpful.
I think your first line is being folded based on the level of indentation of the lines in the file. You can disable indentation folding in the Settings View > Code Folding Settings
and uncheck always use indent fold
. If that does not fix it we can troubleshoot further.
You should always remember to think before posting supposed bugs. I thought of that right after I posted and was just editing my message 😀
it's working great again. Thanks for the help!
no problem.
Some unexpected code folding occur at the top of the file. Although I have previously open them, they keep folding on every reload. The arrows are not appearing in some cases. Please check the following illustrations.
Here is my code folding setting:
My version is 0.2.26