-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Conversation
@@ -2330,6 +2341,11 @@ define(function (require, exports, module) { | |||
} else if (prefName === SHOW_LINE_NUMBERS) { | |||
Editor._toggleLinePadding(!newValue); | |||
this._codeMirror.setOption(cmOptions[SHOW_LINE_NUMBERS], newValue); | |||
if (newValue) { | |||
this.registerGutter(LINE_NUMBER_GUTTER, 100); |
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.
magic number 100
, make a constant please (probably exportable)
Initial review, it's be worth exploring if |
Just some thoughts. |
registering/unregistering/getting registered gutters are now `static` objects on the editor class. modified code folding gutter to use new api.
@ficristo I could explore the consequences of a refactor which introduces a Gutter abstraction for manipulating gutter elements. Hypothetically, Gutter instances would be composed as properties of Editor instances. Registering/unregistering/listing gutters would be static properties of the Gutter class. The Gutter class would also need a reference to the Editor instance (since any modifications to the gutter are still done via the I'm not 100% in agreement with enforcing that the code-folding arrows are the rightmost in the gutter. I think we should provide a flexible API with as little exceptions and restrictions as possible. For instance a very creative designer might conjure up a wireframe where a very thin gutter element is used to render the range (i.e., start and end) that a foldable region spans. I'm sure people can come up with other examples. For now I have given the priority what I feel is a sufficiently high number (500) to push the folding gutter to the rightmost gutter. I think this is fine as long as we make the gutter priorities and how they work clear to the extension developers. I am yet to write tests for these and I will as soon as I can get the tests to run. Anyone else having issues running tests? All I see is a white screen when I try. Any known workarounds? |
For the first point I was looking both at the length of Editor and what is happening in CodeMirror where it is split in multiple files. So I was thinking to put the gutter in a new file with the idea to put/move more things in the future. For the tests I don't have problems on my Windows10 PC. Are you saying as soon as you open the test window you see only a white screen? |
@ficristo regarding tests, yes. That is correct. I only see a white screen as soon as the test windows are opened. I am on OSX El Capitan. I was just wondering if anyone has ever experienced this issue and if there were known work arounds. |
@thehogfather can you run tests now? |
@zaggino yes i can now run tests (at least selective tests) attempting to run all tests eventually gets to a white screen but I think this has always been a problem for me - even from a couple of years ago. Let me know if there are any strategies/workarounds for running all tests. |
Yeah, I don't know of any. If you build your own shell, try using the release one from pre-release. If you don't try building your own. That's pretty much all advice I have (which I know it's not a lot). |
…ather/brackets into thehogfather/gutter_apis finished gutter api tests for editor
ok - building my own shell did not make a huge difference with regards to running |
@ficristo second look? |
If someone else of @adobe/brackets-committers can review would be better, maybe @petetnt or @marcelgerber. |
As a whole the idea of adding gutter manipulation using well defined public apis sounds quite promising. I am not quite clear about the usage of language ID though as a parameter. |
@ficristo no, I haven't tried modifying any of my extensions to use the API yet |
@swmitra initially there was this #12673 which used MutationObserver. Since it caused some problems this was opened. |
@swmitra @ficristo Indeed one of the issues (#10864) that triggered this was discovered as a 'Codefolding' issue. Consequently, the original fix involved using the With the new API, I don't think there is need to watch changes to the gutter - to detect if lineNumbers are present or not. Brackets already watches changes to the preferences (one of which is whether or not to show line numbers) and the new API uses this information to ensure that the state of the gutters rendered in the editor is consistent with that of the external lineNumber preferences -- see the diffs in Perhaps one would want these level api changes in CodeMirror itself as it does not provide an API rich enough for these use cases? Finally, the usage of languageId is to allow flexibility in specifying that an extension developer would like their gutter design only for specific languages. For instance, I remember there is/was a nice extension that showed a colored square in the gutter of stylesheet files right next to lines where colors have been used. Such a gutter need not exist in javascript files. So on initialisation, the extension editor could then register gutter for specific languages. Default is all languages. |
|
||
/** |
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.
Nit: indent.
* The line number gutter is defined as { name: LINE_NUMBER_GUTTER, priority: 100 } | ||
* @type {Array.<{name: string, priority: number, languages: Array}} | ||
*/ | ||
var registeredGutters = []; | ||
var cmOptions = {}; |
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.
Add a new line before cmOptions
.
@@ -110,7 +115,8 @@ define(function (require, exports, module) { | |||
DEFAULT_SPACE_UNITS = 4, | |||
DEFAULT_TAB_SIZE = 4, | |||
MAX_SPACE_UNITS = 10, | |||
MAX_TAB_SIZE = 10; | |||
MAX_TAB_SIZE = 10, | |||
LINE_NUMBER_GUTTER_PRIORITY = 100; |
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.
Can you instead create a new var
group here with LINE_NUMBER_GUTTER?
var LINE_NUMBER_GUTTER = "CodeMirror-linenumbers",
LINE_NUMBER_GUTTER_PRIORITY = 100;
@@ -414,13 +421,16 @@ define(function (require, exports, module) { | |||
readOnly : isReadOnly | |||
}); | |||
|
|||
|
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.
revert
@@ -449,6 +459,7 @@ define(function (require, exports, module) { | |||
this._resetText(document.getText()); | |||
this._duringSync = false; | |||
|
|||
|
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.
revert
} | ||
|
||
if (!name || typeof name !== "string") { | ||
throw new Error("The name of the registered gutter must be a string."); |
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'm not sure: @zaggino do we throw exceptions on wrong parameters?
Maybe a console.error
followed by a return
is better?
@@ -73,6 +75,7 @@ define(function (require, exports, module) { | |||
|
|||
/** Set to true when init() has run; set back to false after deinit() has run */ | |||
var _isInitialized = false; |
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.
Add a new line before initialisedFiles. Can you add a comment too?
@@ -383,6 +395,7 @@ define(function (require, exports, module) { | |||
foldCode.init(); | |||
foldGutter.init(); | |||
|
|||
|
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.
Revert
|
||
// If the line numbers gutter has not been explicitly registered and the CodeMirror lineNumbes option is | ||
// set to true, we explicitly add the line numbers gutter. This case occurs the first time the editor loads | ||
// and showwLineNumbers is set to true in preferences |
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.
Nit: showLineNumbers
, only one w
rootElement = this.getRootElement(); | ||
|
||
// If the line numbers gutter has not been explicitly registered and the CodeMirror lineNumbes option is | ||
// set to true, we explicitly add the line numbers gutter. This case occurs the first time the editor loads |
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.
Nit: add the line numbers gutter
, a single space between words.
I left only nits, from the API perspective I cannot really say much. A general rule: do not touch whitespaces on code you don't touch. Maybe, as already said by @zaggino, we should exports LINE_NUMBER_GUTTER_PRIORITY and CODE_FOLDING_GUTTER_PRIORITY. @thehogfather if we can upstream some changes to CodeMirror, to me would be really nice. |
* @param {string} name The name of the gutter to be un registered. | ||
*/ | ||
Editor.unregisterGutter = function (name) { | ||
var i, gutter; |
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.
Maybe would prefer Array.prototype.filter
for simplicity over couple of possible cycles saved 🤔 😄
|
||
/** | ||
* Unregisters the gutter with the specified name and removes it from the UI. | ||
* @param {string} name The name of the gutter to be un registered. |
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.
Nitpick: "unregistered"
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.
Looks good to me and ready to be merged.
@petetnt do you want to review? Otherwise I'll merge this. |
LGTM too, merging this. |
(Review and test) @zaggino @marcelgerber @petetnt
This introduces 5 public apis on the Editor instance for manipulating gutters in an editor.
The intended workflow is that extension authors use this api to manipulate the gutter within the editor. Typically
onActiveEditorChange
, register the gutter if not already registered. UseunregisterGutter
if the extension is disabled and usesetGutterMarker
to draw things on the gutter.None of the apis could go on the
EditorManager
since EditorManager already depends onEditor.js
and we would have needed to make Editor depend onEditorManager
to be aware of registered gutters when clearing gutters or setting the gutter markers.As it stands, this will not play nicely with the current ways extensions are written since they are not been registered first and there is no clean way to allow backward compatibility for the old method of manipulation of gutters. Things appear to work correctly, until the line-number visibility is toggled (then external extension gutter disappears until it is re-rendered).
@zaggino it would be nice to know how well this plays with your extensions. I've only been able to test with two things on the gutter.
relates to #12726