mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Lowercase current word/selection with meta-U
This commit is contained in:
@@ -1871,6 +1871,23 @@ describe "EditSession", ->
|
||||
expect(editSession.lineForBufferRow(0)).toBe 'ABc'
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[0, 0], [0, 2]]
|
||||
|
||||
describe ".lowerCase()", ->
|
||||
describe "when there is no selection", ->
|
||||
it "lower cases the current word", ->
|
||||
editSession.buffer.setText("aBC")
|
||||
editSession.setCursorScreenPosition([0, 1])
|
||||
editSession.lowerCase()
|
||||
expect(editSession.lineForBufferRow(0)).toBe 'abc'
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[0, 1], [0, 1]]
|
||||
|
||||
describe "when there is a selection", ->
|
||||
it "lower cases the current selection", ->
|
||||
editSession.buffer.setText("ABC")
|
||||
editSession.setSelectedBufferRange([[0,0], [0,2]])
|
||||
editSession.lowerCase()
|
||||
expect(editSession.lineForBufferRow(0)).toBe 'abC'
|
||||
expect(editSession.getSelectedBufferRange()).toEqual [[0, 0], [0, 2]]
|
||||
|
||||
describe "soft-tabs detection", ->
|
||||
it "assign soft / hard tabs based on the contents of the buffer, or uses the default if unknown", ->
|
||||
editSession = fixturesProject.buildEditSessionForPath('sample.js', softTabs: false)
|
||||
|
||||
@@ -314,6 +314,17 @@ class EditSession
|
||||
mutateSelectedText: (fn) ->
|
||||
@transact => fn(selection) for selection in @getSelections()
|
||||
|
||||
replaceSelectedText: (options={}, fn) ->
|
||||
{selectWordIfEmpty} = options
|
||||
@mutateSelectedText (selection) =>
|
||||
range = selection.getBufferRange()
|
||||
if selectWordIfEmpty and selection.isEmpty()
|
||||
selection.selectWord()
|
||||
text = selection.getText()
|
||||
selection.delete()
|
||||
selection.insertText(fn(text))
|
||||
selection.setBufferRange(range)
|
||||
|
||||
pushOperation: (operation) ->
|
||||
@buffer.pushOperation(operation, this)
|
||||
|
||||
@@ -553,14 +564,10 @@ class EditSession
|
||||
selection.insertText selection.getText().split('').reverse().join('')
|
||||
|
||||
upperCase: ->
|
||||
@mutateSelectedText (selection) =>
|
||||
range = selection.getBufferRange()
|
||||
if selection.isEmpty()
|
||||
selection.selectWord()
|
||||
text = selection.getText()
|
||||
selection.delete()
|
||||
selection.insertText text.toUpperCase()
|
||||
selection.setBufferRange(range) if range
|
||||
@replaceSelectedText selectWordIfEmpty:true, (text) => text.toUpperCase()
|
||||
|
||||
lowerCase: ->
|
||||
@replaceSelectedText selectWordIfEmpty:true, (text) => text.toLowerCase()
|
||||
|
||||
expandLastSelectionOverLine: ->
|
||||
@getLastSelection().expandOverLine()
|
||||
|
||||
@@ -134,6 +134,7 @@ class Editor extends View
|
||||
'editor:select-to-beginning-of-word': @selectToBeginningOfWord
|
||||
'editor:transpose': @transpose
|
||||
'editor:upper-case': @upperCase
|
||||
'editor:lower-case': @lowerCase
|
||||
|
||||
unless @mini
|
||||
_.extend editorBindings,
|
||||
@@ -228,6 +229,7 @@ class Editor extends View
|
||||
selectToScreenPosition: (position) -> @activeEditSession.selectToScreenPosition(position)
|
||||
transpose: -> @activeEditSession.transpose()
|
||||
upperCase: -> @activeEditSession.upperCase()
|
||||
lowerCase: -> @activeEditSession.lowerCase()
|
||||
clearSelections: -> @activeEditSession.clearSelections()
|
||||
|
||||
backspace: -> @activeEditSession.backspace()
|
||||
|
||||
@@ -32,3 +32,4 @@
|
||||
'ctrl-W': 'editor:select-word'
|
||||
'meta-alt-p': 'editor:log-cursor-scope'
|
||||
'meta-u': 'editor:upper-case'
|
||||
'meta-U': 'editor:lower-case'
|
||||
|
||||
Reference in New Issue
Block a user