mirror of
https://github.com/atom/atom.git
synced 2026-02-09 06:05:11 -05:00
Outdent works with Ace's Mode classes
This commit is contained in:
@@ -105,5 +105,14 @@ class Buffer
|
||||
|
||||
@mode = new (require("ace/mode/#{modeName}").Mode)
|
||||
|
||||
# API to match Ace's Document class
|
||||
findMatchingBracket: ({row, column}) ->
|
||||
{row: 0, column: 0}
|
||||
|
||||
replace:(range, text) ->
|
||||
# Only used to outdent lines
|
||||
start = range.start
|
||||
end = {row: range.start.row, column: range.start.column + atom.tabText.length}
|
||||
@change(new Range(start, end), "")
|
||||
|
||||
_.extend(Buffer.prototype, EventEmitter)
|
||||
|
||||
@@ -31,6 +31,8 @@ class Editor extends View
|
||||
highlighter: null
|
||||
lineWrapper: null
|
||||
undoManager: null
|
||||
autoIndent: null
|
||||
|
||||
|
||||
initialize: () ->
|
||||
requireStylesheet 'editor.css'
|
||||
@@ -39,6 +41,7 @@ class Editor extends View
|
||||
@buildCursorAndSelection()
|
||||
@handleEvents()
|
||||
@setBuffer(new Buffer)
|
||||
@autoIndent = false
|
||||
|
||||
bindKeys: ->
|
||||
window.keymap.bindKeys '*:not(.editor *)',
|
||||
@@ -301,14 +304,24 @@ class Editor extends View
|
||||
@selection.selectToBufferPosition(position)
|
||||
|
||||
insertText: (text) ->
|
||||
if not @autoIndent
|
||||
@selection.insertText(text)
|
||||
return
|
||||
|
||||
state = @lineWrapper.lineForScreenRow(@getCursorRow()).state
|
||||
shouldOutdent = false
|
||||
|
||||
if text[0] == "\n"
|
||||
tab = " "
|
||||
state = @lineWrapper.lineForScreenRow(@getRow).state
|
||||
indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), tab)
|
||||
indent = @buffer.mode.getNextLineIndent(state, @getCurrentLine(), atom.tabText)
|
||||
text = text[0] + indent + text[1..]
|
||||
else if @buffer.mode.checkOutdent(state, @getCurrentLine(), text)
|
||||
shouldOutdent = true
|
||||
|
||||
@selection.insertText(text)
|
||||
|
||||
if shouldOutdent
|
||||
@buffer.mode.autoOutdent(state, @buffer, @getCursorRow())
|
||||
|
||||
cutSelection: -> @selection.cut()
|
||||
copySelection: -> @selection.copy()
|
||||
paste: -> @selection.insertText($native.readFromPasteboard())
|
||||
|
||||
Reference in New Issue
Block a user