CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Ensures fold-gutter is always inserted after the line-number gutter (if it exists) #12673
Conversation
…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
@thehogfather thank you for the PR. |
I think @marcelgerber or @petetnt are better to review this one. |
Looks like #10864 is fixed now, but I still see the other issue with the active line highlight |
@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. |
Ah, I see now. #11577 mentions the issue, but I thought it's all about it. |
var lnIndex = gutters.indexOf("CodeMirror-linenumbers"); | ||
var lineNumberIndex = gutters.indexOf("CodeMirror-linenumbers"); | ||
if (lineNumberIndex < 0) { | ||
$(editor.getRootElement()).addClass("linenumber-disabled"); |
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 might also go well here:
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
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()), |
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.
editor.getRootElement()
is used here, on L342, L344 and L346 so it could / should be saved to an variable
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"); |
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.
@marcelgerber originally wrote :
This might also go well here:
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
Is this waiting for anything @petetnt ? |
I'll try to test this out once more and run the tests ASAP and merge this in if all is good. |
There are some failing Code Folding tests which are unrelated to this PR which are being tracked in #12724. This PR LGTM, merging. |
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? |
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 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, cc @zaggino @marcelgerber @petetnt |
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. |
Haven't/didn't run to #12726 but let's revert this one and let's think of a nicer API for doing this. |
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.