Skip to content

Commit

Permalink
workaround for forward-sexp and backward-sexp
Browse files Browse the repository at this point in the history
The cursor would skip across newlines in addition to a single word.

Root cause is an underlying bug in text-buffer where old regular
expression was considered single line.  Extra new lines can be
removed after it is fixed.

see atom/text-buffer#226
see avendael#129
  • Loading branch information
MartyGentillon committed Apr 21, 2017
1 parent 8f834ca commit f9bbd21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/emacs-cursor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class EmacsCursor
hit.stop()
result or point
else
@_locateForwardFrom(point, /\W/i)?.start or eob
@_locateForwardFrom(point, /[\W\n]/i)?.start or eob

_sexpBackwardFrom: (point) ->
point = @_locateBackwardFrom(point, /[\w()[\]{}'"]/i)?.end or BOB
Expand All @@ -426,7 +426,7 @@ class EmacsCursor
hit.stop()
result or point
else
@_locateBackwardFrom(point, /\W/i)?.end or BOB
@_locateBackwardFrom(point, /\W\n/i)?.end or BOB

_locateBackwardFrom: (point, regExp) ->
result = null
Expand Down
8 changes: 4 additions & 4 deletions spec/atomic-emacs-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ describe "AtomicEmacs", ->

describe "atomic-emacs:backward-sexp", ->
it "moves all cursors backward one symbolic expression", ->
@testEditor.setState("aa [0]\n(bb cc)[1]\n")
@testEditor.setState("(aa bb)\naa [0]\n(bb cc)[1]\n")
atom.commands.dispatch @editorView, 'atomic-emacs:backward-sexp'
expect(@testEditor.getState()).toEqual("[0]aa \n[1](bb cc)\n")
expect(@testEditor.getState()).toEqual("(aa bb)\n[0]aa \n[1](bb cc)\n")

it "merges cursors that coincide", ->
@testEditor.setState("aa[0] [1]")
Expand All @@ -133,9 +133,9 @@ describe "AtomicEmacs", ->

describe "atomic-emacs:forward-sexp", ->
it "moves all cursors forward one symbolic expression", ->
@testEditor.setState("[0] aa\n[1](bb cc)\n")
@testEditor.setState("[0]aa\n[1](bb cc)\n")
atom.commands.dispatch @editorView, 'atomic-emacs:forward-sexp'
expect(@testEditor.getState()).toEqual(" aa[0]\n(bb cc)[1]\n")
expect(@testEditor.getState()).toEqual("aa[0]\n(bb cc)[1]\n")

it "merges cursors that coincide", ->
@testEditor.setState("[0] [1]aa")
Expand Down

0 comments on commit f9bbd21

Please sign in to comment.