mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
commit
e509e23a0f
@ -884,6 +884,10 @@ describe "Editor", ->
|
||||
expect(editor.getSelection().isEmpty()).toBeTruthy()
|
||||
expect(cursorView).toBeVisible()
|
||||
|
||||
it "moves the hiddenInput to the same position with cursor's view", ->
|
||||
editor.setCursorScreenPosition(row: 2, column: 2)
|
||||
expect(editor.getCursorView().offset()).toEqual(editor.hiddenInput.offset())
|
||||
|
||||
describe "when the editor is using a variable-width font", ->
|
||||
beforeEach ->
|
||||
editor.setFontFamily('sans-serif')
|
||||
|
@ -88,6 +88,7 @@ class Editor extends View
|
||||
@configure()
|
||||
@bindKeys()
|
||||
@handleEvents()
|
||||
@handleInputEvents()
|
||||
@cursorViews = []
|
||||
@selectionViews = []
|
||||
@pendingChanges = []
|
||||
@ -677,10 +678,6 @@ class Editor extends View
|
||||
|
||||
@selectOnMousemoveUntilMouseup() unless e.ctrlKey or e.originalEvent.which > 1
|
||||
|
||||
@on "textInput", (e) =>
|
||||
@insertText(e.originalEvent.data)
|
||||
false
|
||||
|
||||
unless @mini
|
||||
@scrollView.on 'mousewheel', (e) =>
|
||||
if delta = e.originalEvent.wheelDeltaY
|
||||
@ -696,6 +693,33 @@ class Editor extends View
|
||||
else
|
||||
@gutter.addClass('drop-shadow')
|
||||
|
||||
handleInputEvents: ->
|
||||
@on 'cursor:moved', =>
|
||||
cursorView = @getCursorView()
|
||||
@hiddenInput.offset(cursorView.offset()) if cursorView.is(':visible')
|
||||
|
||||
selectedText = null
|
||||
@hiddenInput.on 'compositionstart', =>
|
||||
selectedText = @getSelectedText()
|
||||
@hiddenInput.css('width', '100%')
|
||||
@hiddenInput.on 'compositionupdate', (e) =>
|
||||
@insertText(e.originalEvent.data, {select: true, skipUndo: true})
|
||||
@hiddenInput.on 'compositionend', =>
|
||||
@insertText(selectedText, {select: true, skipUndo: true})
|
||||
@hiddenInput.css('width', '1px')
|
||||
|
||||
lastInput = ''
|
||||
@on "textInput", (e) =>
|
||||
# Work around of the accented character suggestion feature in OS X.
|
||||
selectedLength = @hiddenInput[0].selectionEnd - @hiddenInput[0].selectionStart
|
||||
if selectedLength is 1 and lastInput is @hiddenInput.val()
|
||||
@selectLeft()
|
||||
|
||||
lastInput = e.originalEvent.data
|
||||
@insertText(lastInput)
|
||||
@hiddenInput.val(lastInput)
|
||||
false
|
||||
|
||||
selectOnMousemoveUntilMouseup: ->
|
||||
lastMoveEvent = null
|
||||
moveHandler = (event = lastMoveEvent) =>
|
||||
|
@ -296,6 +296,8 @@ class Selection
|
||||
# + autoDecreaseIndent:
|
||||
# if `true`, decreases indent level appropriately (for example, when a
|
||||
# closing bracket is inserted)
|
||||
# + skipUndo:
|
||||
# if `true`, skips the undo stack for this operation.
|
||||
insertText: (text, options={}) ->
|
||||
oldBufferRange = @getBufferRange()
|
||||
@editSession.destroyFoldsContainingBufferRow(oldBufferRange.end.row)
|
||||
@ -306,7 +308,7 @@ class Selection
|
||||
if options.indentBasis? and not options.autoIndent
|
||||
text = @normalizeIndents(text, options.indentBasis)
|
||||
|
||||
newBufferRange = @editSession.buffer.change(oldBufferRange, text)
|
||||
newBufferRange = @editSession.buffer.change(oldBufferRange, text, skipUndo: options.skipUndo)
|
||||
if options.select
|
||||
@setBufferRange(newBufferRange, isReversed: wasReversed)
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user