Add has-selection class to editors with non-empty selections

This commit is contained in:
Nathan Sobo
2017-04-15 12:30:24 -06:00
committed by Antonio Scandurra
parent f83ad6bb7c
commit bfa410b114
2 changed files with 26 additions and 0 deletions

View File

@@ -466,6 +466,25 @@ describe('TextEditorComponent', () => {
await component.getNextUpdatePromise()
expect(element.dataset.encoding).toBe('ascii')
})
it('adds the has-selection class when the editor has a non-empty selection', async () => {
const {editor, element, component} = buildComponent()
expect(element.classList.contains('has-selection')).toBe(false)
editor.setSelectedBufferRanges([
[[0, 0], [0, 0]],
[[1, 0], [1, 10]]
])
await component.getNextUpdatePromise()
expect(element.classList.contains('has-selection')).toBe(true)
editor.setSelectedBufferRanges([
[[0, 0], [0, 0]],
[[1, 0], [1, 0]]
])
await component.getNextUpdatePromise()
expect(element.classList.contains('has-selection')).toBe(false)
})
})
describe('mini editors', () => {

View File

@@ -365,6 +365,13 @@ class TextEditorComponent {
className = className + ' mini'
}
for (var i = 0; i < model.selections.length; i++) {
if (!model.selections[i].isEmpty()) {
className += ' has-selection'
break
}
}
const dataset = {encoding: model.getEncoding()}
const grammar = model.getGrammar()
if (grammar && grammar.scopeName) {