mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Clear line numbers from previous usages of the gutter element
In adding custom gutter APIs, I suggested to @jssln that we associate the gutter model objects with DOM nodes in the view registry to make it easy for package authors to get at the view layer for a particular gutter. She also applied this treatment to the line numbers gutter, which makes sense. However, using the view registry opened up an unexpected wrinkle… When you detach an editor, we need to tear down all the associated view logic because at that point, we don’t know whether the element is about to be reattached or whether it’s going to get garbage collected. In the case where we reattach, we end up constructing a new TextEditorComponent for the element. When this happens, the gutter component requests a DOM node for the gutter from the view registry. Except in this case the DOM element isn’t empty because it was already used by a different component for the same element before it was detached. The fix is simply to always clear out the line numbers to ensure we start in a clean state. @jssln: You should apply this same fix to custom gutters or we’ll see the same issues.
This commit is contained in:
@@ -65,6 +65,20 @@ describe "TextEditorElement", ->
|
||||
element.getModel().destroy()
|
||||
expect(component.mounted).toBe false
|
||||
|
||||
describe "when the editor is detached from the DOM and then reattached", ->
|
||||
it "does not render duplicate line numbers", ->
|
||||
editor = new TextEditor
|
||||
editor.setText('1\n2\n3')
|
||||
element = atom.views.getView(editor)
|
||||
|
||||
jasmine.attachToDOM(element)
|
||||
|
||||
initialCount = element.shadowRoot.querySelectorAll('.line-number').length
|
||||
|
||||
element.remove()
|
||||
jasmine.attachToDOM(element)
|
||||
expect(element.shadowRoot.querySelectorAll('.line-number').length).toBe initialCount
|
||||
|
||||
describe "focus and blur handling", ->
|
||||
describe "when the editor.useShadowDOM config option is true", ->
|
||||
it "proxies focus/blur events to/from the hidden input inside the shadow root", ->
|
||||
|
||||
@@ -13,6 +13,7 @@ class LineNumberGutterComponent
|
||||
|
||||
@domNode = atom.views.getView(@gutter)
|
||||
@lineNumbersNode = @domNode.firstChild
|
||||
@lineNumbersNode.innerHTML = ''
|
||||
|
||||
@domNode.addEventListener 'click', @onClick
|
||||
@domNode.addEventListener 'mousedown', @onMouseDown
|
||||
|
||||
Reference in New Issue
Block a user