Skip to content

Commit

Permalink
Merge branch 'develop' into webdriver_unit_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
byronm committed Jul 24, 2013
2 parents 2c69070 + 695c5b2 commit 0ab7000
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "scribe",
"version": "0.7.2",
"dependencies": {
"tandem-core" : "git+ssh://[email protected]:stypi/tandem-core.git#v0.3.4",
"tandem-core" : "git+ssh://[email protected]:stypi/tandem-core.git#v0.4.0",
"underscore" : "1.4.x"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions src/document.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class Scribe.Document
toDelta: ->
lines = @lines.toArray()
ops = _.flatten(_.map(lines, (line, index) ->
ops = Tandem.Delta.copy(line.delta).ops
return ops
return line.delta.ops
), true)
delta = new Tandem.Delta(0, ops)
return delta
Expand Down
16 changes: 10 additions & 6 deletions src/selection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ _nativeRangeToRange = (nativeRange) ->
start = new Scribe.Position(@editor, nativeRange.startContainer, nativeRange.startOffset)
end = new Scribe.Position(@editor, nativeRange.endContainer, nativeRange.endOffset)
if start.index <= end.index
return new Scribe.Range(@editor, start, end)
range = new Scribe.Range(@editor, start, end)
range.isBackwards = false
else
return new Scribe.Range(@editor, end, start)
range = new Scribe.Range(@editor, end, start)
range.isBackwards = true
range.isBackwards = true if nativeRange.isBackwards
return range

_preserveWithIndex = (nativeRange, index, lengthAdded, fn) ->
range = _nativeRangeToRange.call(this, nativeRange)
Expand All @@ -57,7 +61,7 @@ _preserveWithLine = (savedNativeRange, fn) ->
savedData = _.map([
{ container: savedNativeRange.startContainer, offset: savedNativeRange.startOffset }
{ container: savedNativeRange.endContainer, offset: savedNativeRange.endOffset }
], (position) ->
], (position) =>
lineNode = Scribe.Utils.findAncestor(position.container, Scribe.Line.isLineNode) or @editor.root
return {
lineNode : lineNode
Expand Down Expand Up @@ -109,6 +113,7 @@ class Scribe.Selection
@nativeSelection.refresh()
range = if @nativeSelection?.rangeCount > 0 then @nativeSelection.getRangeAt(0) else null
range = normalizeNativeRange(range) if normalize
range.isBackwards = true if @nativeSelection.isBackwards()
return range

getRange: ->
Expand All @@ -128,6 +133,7 @@ class Scribe.Selection

setRange: (range, silent = false) ->
return unless @nativeSelection?
@nativeSelection.removeAllRanges()
if range?
nativeRange = rangy.createRangyRange()
_.each([range.start, range.end], (pos, i) ->
Expand All @@ -137,9 +143,7 @@ class Scribe.Selection
fn = if i == 0 then 'setStart' else 'setEnd'
nativeRange[fn].call(nativeRange, node, offset)
)
@nativeSelection.setSingleRange(nativeRange)
else
@nativeSelection.removeAllRanges()
@nativeSelection.addRange(nativeRange, range.isBackwards)
@editor.emit(Scribe.Editor.events.SELECTION_CHANGE, range) unless silent or range == @range or @range?.equals(range)
@range = range

Expand Down

0 comments on commit 0ab7000

Please sign in to comment.