-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Adds code folding support for handlebars template files #12675
Conversation
* @author Patrick Oladimeji | ||
* @license MIT | ||
* @date 14/08/2016 22:04:21 | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to use the standard license comment of adobe on newer file now the code folding extension is in the core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem - I'll remove it -artefact of automatic templates
I don't know handlebar, so I left some general comments. |
|
||
CodeMirror.registerHelper("fold", "handlebars", handlebarsFold); | ||
CodeMirror.registerHelper("fold", "htmlhandlebars", handlebarsFold); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove space.
Another nit but in general Brackets use double quote for strings. |
@@ -0,0 +1,174 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to include the full licence comment here (like in other source files).
Beware the date has to be 2016 - present.
/*
* Copyright (c) 2016 - present Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*....
*...
* @author Patrick Oladimeji | ||
* @date 14/08/2016 22:04:21 | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ficristo BTW I notice this empty line is being introduced throughout the code base - although it conflicts with an existing recommendation in the fairly stale JS Docs guidelines. I am guessing that the guideline has simply not been updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK the guidelines are still true. But until we can have stricter rules on our linter sometimes we miss things.
CodeMirror.registerHelper("fold", "django", CodeMirror.helpers.fold.brace); | ||
CodeMirror.registerHelper("fold", "tornado", CodeMirror.helpers.fold.brace); | ||
CodeMirror.registerHelper("fold", "handlebars", handlebarsFold); | ||
CodeMirror.registerHelper("fold", "htmlhandlebars", handlebarsFold); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thehogfather is the second parameter a CodeMirror mode? Where do you use it?
It seems to me that Mustache is not part of your PR, but handlebars is a Mustache like template.
And we use Mustache in the codebase.
So if it that param is a mode, I was wondering if we can use text/x-brackets-html
or htmlmixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup that parameter is a CodeMirror mode. The name of the mode is used internally by CodeMirror to create a lookup table for the fold helper for a given mode.
define(function (require, exports, module) { | ||
"use strict"; | ||
var CodeMirror = brackets.getModule("thirdparty/CodeMirror/lib/codemirror"), | ||
endOfLineSpaceRegex = /\s$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My little mind cannot understand this: are you looking for a single space, right? For which cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks for a space that occurs at the end of a string - and I have used it to scan a line until a space is reached. Very useful in finding potential opening range tags - e.g., {{
and {{foo
in the following scenario:
{{
foo
bar=baz
var-1=goo
}}
or
{{foo
bar=baz
var-1=goo
}}
And based on what is currently on the stack of the opening tags we try to search for a closing tag. I will add better comments to these. Perhaps endOfLineSpaceRegex is actually not a good name and naming the variable might be unnecessary in this scenario as it is only used in one place.
to: found.to | ||
}; | ||
openTag = found.string.substring(0, found.string.length - 1); | ||
if (openTag[0] === "#" || openTag[0] === "~") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below I think you have to add ^
and add a test for it and for ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I was working with the handlebars page as reference. #*
should also be added.
I left a question and a request of change. |
…ced by ~, ^ or #* updated tests to capture these cases
@ficristo PR has been updated. |
@thehogfather thank you. |
On a PC where I was able to run tests I had a consistent failure on the |
@ficristo - could you clarify if this use case also fails in use - and does it fail for all three file types, |
Actually I tested it on OSX too. I'll try to understand more the issue. |
And do you get the same failure on OSX? |
yes |
Very strange. Let me know if I can help - unfortunately, I have now tried different macs and I still cannot reproduce. |
I run again the tests on OSX and there still was a failure. I tryed to add a couple of breakpoints runs(function () {
selectTextInEditor(start, end);
}); I can only guess there is some async problem, does it make sense to you? |
To be honest I"m a little baffled as to why that would fix it as the |
I had some problem with code folding tests in the past too. |
Adds a new range finder to detect foldable regions and enable code folding for blocks and helpers in handlebars template files.