mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Work around of the accented character suggestion feature in OS X.
On OS X, press and hold `c` could show an accent menu to replace `c` with accented ones like `ć`, there is no corresponding events in W3C, so we detected it by checking whether the text in input box are selected (this is how Chrome implemented this feature). And also note that IME inputs were handled the same way in Chrome, the compostion text would be marked as selected and got replaced with final inputs. However the compostion text won't trigger textInput event, so it's distinguished by checking whether the hiddenInput's value are changed by Chrome. Fixes atom/atom-shell#50.
This commit is contained in:
@@ -88,7 +88,7 @@ class Editor extends View
|
||||
@configure()
|
||||
@bindKeys()
|
||||
@handleEvents()
|
||||
@handleImeEvents()
|
||||
@handleInputEvents()
|
||||
@cursorViews = []
|
||||
@selectionViews = []
|
||||
@pendingChanges = []
|
||||
@@ -678,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
|
||||
@@ -697,7 +693,7 @@ class Editor extends View
|
||||
else
|
||||
@gutter.addClass('drop-shadow')
|
||||
|
||||
handleImeEvents: ->
|
||||
handleInputEvents: ->
|
||||
@on 'cursor:moved', =>
|
||||
cursorView = @getCursorView()
|
||||
@hiddenInput.offset(cursorView.offset()) if cursorView.is(':visible')
|
||||
@@ -712,6 +708,20 @@ class Editor extends View
|
||||
@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()
|
||||
position = @getCursorScreenPosition()
|
||||
position.column -= 1
|
||||
@selectToScreenPosition(position)
|
||||
|
||||
lastInput = e.originalEvent.data
|
||||
@insertText(lastInput)
|
||||
@hiddenInput.val(lastInput)
|
||||
false
|
||||
|
||||
selectOnMousemoveUntilMouseup: ->
|
||||
lastMoveEvent = null
|
||||
moveHandler = (event = lastMoveEvent) =>
|
||||
|
||||
Reference in New Issue
Block a user