Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Conversation

@thehogfather
Copy link
Contributor

Addresses issue where line numbers appears after fold gutter if the line number visibility is toggled in the View Menu.

Uses MutationObserver to watch changes to the brackets code mirror gutters.

Was PR #11593
Addresses #11577, #10864

@ficristo I noticed that globals are no longer placed in files, I've used globals here for MutationObserver (since it isn't used anywhere else) - but open to moving to a more central location if needed.

…ine number visibility is toggled in the View Menu.

Uses MutationObserver  (https://developer.mozilla.org/en/docs/Web/API/MutationObserver) to watch changes to the brackets code mirror gutters.

Was PR adobe#11593
Addresses adobe#11577, adobe#10864
…ine number visibility is toggled in the View Menu.

Uses MutationObserver  (https://developer.mozilla.org/en/docs/Web/API/MutationObserver) to watch changes to the brackets code mirror gutters.

Was PR adobe#11593
Addresses adobe#11577, adobe#10864
…r/brackets into fold-gutter-position

# Conflicts:
#	src/extensions/default/CodeFolding/main.js
@ficristo
Copy link
Collaborator

@thehogfather thank you for the PR.
In general, from now onwards, the inline directives are mostly forbidden (there are still some exceptions).
In this case you can put MutationObserver after ArrayBuffer both in .eslintrc.json and .brackets.json.

@ficristo
Copy link
Collaborator

I think @marcelgerber or @petetnt are better to review this one.

@marcelgerber
Copy link
Contributor

Looks like #10864 is fixed now, but I still see the other issue with the active line highlight
image
(This is Brackets running without extensions on the preinstalled Brackets Dark theme)

@thehogfather
Copy link
Contributor Author

@marcelgerber could you share a link to the active line highlight issue? This PR only addresses the issues mentioned in the description. Neither of those have anything to do with active line highlights.

@marcelgerber
Copy link
Contributor

Ah, I see now. #11577 mentions the issue, but I thought it's all about it.
This may not even be the fault of this extension.

var lnIndex = gutters.indexOf("CodeMirror-linenumbers");
var lineNumberIndex = gutters.indexOf("CodeMirror-linenumbers");
if (lineNumberIndex < 0) {
$(editor.getRootElement()).addClass("linenumber-disabled");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also go well here:

brackets/src/editor/Editor.js

Lines 2324 to 2328 in 7814da1

} else if (prefName === SHOW_LINE_NUMBERS) {
Editor._toggleLinePadding(!newValue);
this._codeMirror.setOption(cmOptions[SHOW_LINE_NUMBERS], newValue);
this.refreshAll();
} else {

That way, stylesheets and other extension have an easy way to reuse this state.
cc @nethip

@thehogfather
Copy link
Contributor Author

No I don't think the extension introduced the issue - although to be honest I am not actually sure what the expectation is here - so a little difficult to explore a solution.

lineNumberIndex,
foldGutterIndex,
cm = editor._codeMirror,
guttersContainer = $(".CodeMirror-gutters", editor.getRootElement()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editor.getRootElement() is used here, on L342, L344 and L346 so it could / should be saved to an variable

@petetnt
Copy link
Collaborator

petetnt commented Aug 14, 2016

Small general nit: Would be nice if all the magic strings would be moved to constants in the file, would make modifications somewhat easier / safer (can be done in another PR too though)!

Good job @thehogfather once again 👍

gutters.splice(lnIndex + 1, 0, GUTTER_NAME);
var lineNumberIndex = gutters.indexOf(LINE_NUMBER_GUTTER);
if (lineNumberIndex < 0) {
$(rootElement).addClass("linenumber-disabled");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelgerber originally wrote :

This might also go well here:

brackets/src/editor/Editor.js

Lines 2324 to 2328 in 7814da1

} else if (prefName === SHOW_LINE_NUMBERS) {
Editor._toggleLinePadding(!newValue);
this._codeMirror.setOption(cmOptions[SHOW_LINE_NUMBERS], newValue);
this.refreshAll();
} else {

That way, stylesheets and other extension have an easy way to reuse this state.
cc @nethip

@zaggino
Copy link
Contributor

zaggino commented Aug 25, 2016

Is this waiting for anything @petetnt ?

@petetnt
Copy link
Collaborator

petetnt commented Aug 26, 2016

I'll try to test this out once more and run the tests ASAP and merge this in if all is good.

@petetnt
Copy link
Collaborator

petetnt commented Aug 27, 2016

There are some failing Code Folding tests which are unrelated to this PR which are being tracked in #12724.

This PR LGTM, merging.

@zaggino
Copy link
Contributor

zaggino commented Aug 27, 2016

Getting back to this, related to #12726 (comment) I believe this should be reverted, using MutationObserver is not a good thing. Especially if some other extensions tries to do the same thing, I expect we start to get infinite loops?

cc @marcelgerber @petetnt @thehogfather

@thehogfather
Copy link
Contributor Author

This is a symptom of an underlying limitation (within the core libraries CodeMirror and brackets) - i.e., the absence of a rich API for manipulating the gutter in the editor.

At the moment, every extension (that requires the gutter) splices and directly manipulates the gutter without regard for how any other extension might be using the gutter wrt relative position / placement etc. Indeed it is difficult to preempt how many different ways the gutter might be used by other extensions.

What might be immediately useful in a hypothetical API would be the notion of an anchor gutter or gutters (say the line numbers gutter) such that placement of other gutters are requested relative to said anchor gutter(s). So one might say insert the code-folding gutter after the line-numbers, insert the git gutter before the line-numbers, insert theseus-gutter after git, before line numbers etc.

If such an API (or a much refined variation) existed, then there wouldn't be need for the MutationObserver (since all requests to manipulate would go through said API).

Re: infinite loops,
Totally possible if different extensions decided to use mutationobservers directly as well. The implementation in this PR itself should not cause infinite loops as it disconnects the observer while updating the gutter.

cc @zaggino @marcelgerber @petetnt
ref #12726

@zaggino
Copy link
Contributor

zaggino commented Aug 28, 2016

We should definitely set up an API in brackets, make this work with that API and let authors fix their extensions to use the API. Current state is not maintenable, and if we add this, another authors will do the same for their purposes and then we'll have a hell around a simple feature.

@petetnt
Copy link
Collaborator

petetnt commented Aug 28, 2016

Haven't/didn't run to #12726 but let's revert this one and let's think of a nicer API for doing this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants