mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-22 00:19:24 +03:00
Outdent works with Ace's Mode classes
This commit is contained in:
parent
79edb3fcdf
commit
668022fb3b
@ -441,13 +441,23 @@ describe "Editor", ->
|
||||
expect(editor.getSelectedText()).toBe " if (items.length <= 1) return items;"
|
||||
|
||||
describe "auto indent/outdent", ->
|
||||
beforeEach ->
|
||||
editor.autoIndent = true
|
||||
|
||||
describe "when newline is inserted", ->
|
||||
it "indents cursor based on the indentation of previous line", ->
|
||||
editor.setCursorBufferPosition([4, 29])
|
||||
editor.insertText("\n")
|
||||
|
||||
expect(editor.buffer.getLine(5)).toEqual(" ")
|
||||
|
||||
describe "when text that closes a scope entered", ->
|
||||
it "outdents the text", ->
|
||||
editor.setCursorBufferPosition([1, 30])
|
||||
editor.insertText("\n")
|
||||
expect(editor.buffer.getLine(2)).toEqual(" ")
|
||||
editor.insertText("}")
|
||||
expect(editor.buffer.getLine(2)).toEqual(" }")
|
||||
|
||||
describe "selection", ->
|
||||
selection = null
|
||||
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user