Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed the signature of transformCursor in text

  • Loading branch information...
commit 4f01f186229f112ac8433aec2eb8979c59c3edb6 1 parent dd0fc8d
@josephg josephg authored
Showing with 14 additions and 13 deletions.
  1. +4 −3 src/types/text.coffee
  2. +10 −10 test/types/text.coffee
View
7 src/types/text.coffee
@@ -127,7 +127,8 @@ transformPosition = (pos, c, insertAfter) ->
#
# Like transformPosition above, if c is an insert, insertAfter specifies whether the cursor position
# is pushed after an insert (true) or before it (false).
-text.transformCursor = (position, op, insertAfter) ->
+text.transformCursor = (position, op, side) ->
+ insertAfter = side == 'right'
position = transformPosition position, c, insertAfter for c in op
position
@@ -135,12 +136,12 @@ text.transformCursor = (position, op, insertAfter) ->
# The result will be appended to destination.
#
# exported for use in JSON type
-text._tc = transformComponent = (dest, c, otherC, type) ->
+text._tc = transformComponent = (dest, c, otherC, side) ->
checkValidOp [c]
checkValidOp [otherC]
if c.i?
- append dest, {i:c.i, p:transformPosition(c.p, otherC, type == 'right')}
+ append dest, {i:c.i, p:transformPosition(c.p, otherC, side == 'right')}
else # Delete
if otherC.i? # delete vs insert
View
20 test/types/text.coffee
@@ -112,27 +112,27 @@ genTests = (type) ->
transformCursor:
'sanity': (test) ->
- test.strictEqual 0, type.transformCursor 0, [], true
- test.strictEqual 0, type.transformCursor 0, [], false
+ test.strictEqual 0, type.transformCursor 0, [], 'right'
+ test.strictEqual 0, type.transformCursor 0, [], 'left'
test.strictEqual 100, type.transformCursor 100, []
test.done()
'vs insert': (test) ->
- test.strictEqual 0, type.transformCursor 0, [{i:'asdf', p:100}], true
- test.strictEqual 0, type.transformCursor 0, [{i:'asdf', p:100}], false
+ test.strictEqual 0, type.transformCursor 0, [{i:'asdf', p:100}], 'right'
+ test.strictEqual 0, type.transformCursor 0, [{i:'asdf', p:100}], 'left'
- test.strictEqual 204, type.transformCursor 200, [{i:'asdf', p:100}], true
- test.strictEqual 204, type.transformCursor 200, [{i:'asdf', p:100}], false
+ test.strictEqual 204, type.transformCursor 200, [{i:'asdf', p:100}], 'right'
+ test.strictEqual 204, type.transformCursor 200, [{i:'asdf', p:100}], 'left'
- test.strictEqual 104, type.transformCursor 100, [{i:'asdf', p:100}], true
- test.strictEqual 100, type.transformCursor 100, [{i:'asdf', p:100}], false
+ test.strictEqual 104, type.transformCursor 100, [{i:'asdf', p:100}], 'right'
+ test.strictEqual 100, type.transformCursor 100, [{i:'asdf', p:100}], 'left'
test.done()
'vs delete': (test) ->
- test.strictEqual 0, type.transformCursor 0, [{d:'asdf', p:100}], true
- test.strictEqual 0, type.transformCursor 0, [{d:'asdf', p:100}], false
+ test.strictEqual 0, type.transformCursor 0, [{d:'asdf', p:100}], 'right'
+ test.strictEqual 0, type.transformCursor 0, [{d:'asdf', p:100}], 'left'
test.strictEqual 0, type.transformCursor 0, [{d:'asdf', p:100}]
test.strictEqual 196, type.transformCursor 200, [{d:'asdf', p:100}]
Please sign in to comment.
Something went wrong with that request. Please try again.