Merge pull request #16518 from atom/ns-as-fix-add-selection

Don't add fully-contained selections above/below
This commit is contained in:
Nathan Sobo
2018-01-09 10:10:13 -07:00
committed by GitHub
2 changed files with 38 additions and 4 deletions

View File

@@ -2376,6 +2376,19 @@ describe('TextEditor', () => {
])
})
})
it('does not create a new selection if it would be fully contained within another selection', () => {
editor.setText('abc\ndef\nghi\njkl\nmno')
editor.setCursorBufferPosition([0, 1])
let addedSelectionCount = 0
editor.onDidAddSelection(() => { addedSelectionCount++ })
editor.addSelectionBelow()
editor.addSelectionBelow()
editor.addSelectionBelow()
expect(addedSelectionCount).toBe(3)
})
})
describe('.addSelectionAbove()', () => {
@@ -2498,6 +2511,19 @@ describe('TextEditor', () => {
])
})
})
it('does not create a new selection if it would be fully contained within another selection', () => {
editor.setText('abc\ndef\nghi\njkl\nmno')
editor.setCursorBufferPosition([4, 1])
let addedSelectionCount = 0
editor.onDidAddSelection(() => { addedSelectionCount++ })
editor.addSelectionAbove()
editor.addSelectionAbove()
editor.addSelectionAbove()
expect(addedSelectionCount).toBe(3)
})
})
describe('.splitSelectionsIntoLines()', () => {

View File

@@ -832,8 +832,12 @@ class Selection {
if (clippedRange.isEmpty()) continue
}
const selection = this.editor.addSelectionForScreenRange(clippedRange)
selection.setGoalScreenRange(range)
const containingSelections = this.editor.selectionsMarkerLayer.findMarkers({containsScreenRange: clippedRange})
if (containingSelections.length === 0) {
const selection = this.editor.addSelectionForScreenRange(clippedRange)
selection.setGoalScreenRange(range)
}
break
}
}
@@ -854,8 +858,12 @@ class Selection {
if (clippedRange.isEmpty()) continue
}
const selection = this.editor.addSelectionForScreenRange(clippedRange)
selection.setGoalScreenRange(range)
const containingSelections = this.editor.selectionsMarkerLayer.findMarkers({containsScreenRange: clippedRange})
if (containingSelections.length === 0) {
const selection = this.editor.addSelectionForScreenRange(clippedRange)
selection.setGoalScreenRange(range)
}
break
}
}