Skip to content

Commit 5cdf99d

Browse files
author
Petro Salema
committed
Remove aloha.ranges from API
1 parent 4d26d64 commit 5cdf99d

File tree

18 files changed

+796
-892
lines changed

18 files changed

+796
-892
lines changed

src/api.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ define([
1515
'boromir',
1616
'boundaries',
1717
'browsers',
18+
'carets',
1819
'colors',
1920
'content',
2021
'delayed-map',
@@ -38,7 +39,6 @@ define([
3839
'overrides',
3940
'paste',
4041
'paths',
41-
'ranges',
4242
'record',
4343
'selection-change',
4444
'selections',
@@ -55,6 +55,7 @@ define([
5555
Boromir,
5656
Boundaries,
5757
Browsers,
58+
Carets,
5859
Colors,
5960
Content,
6061
DelayedMap,
@@ -78,7 +79,6 @@ define([
7879
Overrides,
7980
Paste,
8081
Paths,
81-
Ranges,
8282
Record,
8383
SelectionChange,
8484
Selections,
@@ -453,30 +453,16 @@ define([
453453
exports['overrides']['nodeToState'] = Overrides.nodeToState;
454454

455455
exports['paste'] = new Object();
456-
exports['handle'] = Paste.handle;
456+
exports['paste']['handle'] = Paste.handle;
457457

458458
exports['paths'] = new Object();
459459
exports['paths']['toBoundary'] = Paths.toBoundary;
460460
exports['paths']['fromBoundary'] = Paths.fromBoundary;
461461

462-
exports['ranges'] = new Object();
463-
exports['ranges']['box'] = Ranges.box;
464-
exports['ranges']['get'] = Ranges.get;
465-
exports['ranges']['create'] = Ranges.create;
466-
exports['ranges']['equals'] = Ranges.equals;
467-
exports['ranges']['collapseToEnd'] = Ranges.collapseToEnd;
468-
exports['ranges']['collapseToStart'] = Ranges.collapseToStart;
469-
exports['ranges']['trim'] = Ranges.trim;
470-
exports['ranges']['trimClosingOpening'] = Ranges.trimClosingOpening;
471-
exports['ranges']['trimBoundaries'] = Ranges.trimBoundaries;
472-
exports['ranges']['expandBoundaries'] = Ranges.expandBoundaries;
473-
exports['ranges']['nearestEditingHost'] = Ranges.nearestEditingHost;
474-
exports['ranges']['expand'] = Ranges.expand;
475-
exports['ranges']['envelopeInvisibleCharacters'] = Ranges.envelopeInvisibleCharacters;
476-
exports['ranges']['fromPosition'] = Ranges.fromPosition;
477-
exports['ranges']['fromBoundaries'] = Ranges.fromBoundaries;
478-
exports['ranges']['showHint'] = Ranges.showHint;
479-
exports['ranges']['hideHint'] = Ranges.hideHint;
462+
exports['carets'] = new Object();
463+
exports['carets']['box'] = Carets.box;
464+
exports['carets']['showHint'] = Carets.showHint;
465+
exports['carets']['hideHint'] = Carets.hideHint;
480466

481467
exports['selectionchange'] = new Object();
482468
exports['selectionchange']['handler'] = SelectionChange.handler;

src/autoformat.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ define([
1010
'dom',
1111
'maps',
1212
'keys',
13-
'ranges',
1413
'editing',
1514
'mutation',
1615
'searching',
@@ -21,7 +20,6 @@ define([
2120
Dom,
2221
Maps,
2322
Keys,
24-
Ranges,
2523
Editing,
2624
Mutation,
2725
Searching,
@@ -68,11 +66,8 @@ define([
6866
}
6967

7068
function ascii(symbol, start, end) {
71-
var range = Ranges.fromBoundaries(start, end);
72-
var boundaries = Boundaries.fromRange(
73-
Ranges.envelopeInvisibleCharacters(range)
74-
);
75-
var boundary = Editing.remove(boundaries[0], boundaries[1])[0];
69+
end = Traversing.envelopeInvisibleCharacters(end);
70+
var boundary = Editing.remove(start, end)[0];
7671
return Mutation.insertTextAtBoundary(symbol, boundary, true);
7772
}
7873

@@ -163,7 +158,7 @@ define([
163158
}
164159
if (handler) {
165160
boundary = handler(start, boundary);
166-
event.range = Ranges.fromBoundaries(boundary, boundary);
161+
event.range = Boundaries.range(boundary, boundary);
167162
}
168163
return event;
169164
}

src/boundaries.js

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
*/
88
define([
99
'dom',
10+
'ranges',
1011
'arrays',
1112
'assert'
1213
], function (
1314
Dom,
15+
Ranges,
1416
Arrays,
1517
Assert
1618
) {
@@ -531,31 +533,6 @@ define([
531533
}
532534
}
533535

534-
/**
535-
* Calculates the cumulative length of contiguous text nodes immediately
536-
* preceding the given boundary.
537-
*
538-
* @param {Boundary} boundary
539-
* @return {number}
540-
*/
541-
function precedingTextLength(boundary) {
542-
var node;
543-
var len;
544-
boundary = normalize(boundary);
545-
if (isNodeBoundary(boundary)) {
546-
len = 0;
547-
node = nodeBefore(boundary);
548-
} else {
549-
len = offset(boundary);
550-
node = container(boundary).previousSibling;
551-
}
552-
while (node && Dom.isTextNode(node)) {
553-
len += Dom.nodeLength(node);
554-
node = node.previousSibling;
555-
}
556-
return len;
557-
}
558-
559536
/**
560537
* Gets the boundaries of the currently selected range from the given
561538
* document element.
@@ -570,6 +547,22 @@ define([
570547
: null;
571548
}
572549

550+
/**
551+
* Creates a range based on the given start and end boundaries.
552+
*
553+
* @param {Boundary} start
554+
* @param {Boundary} end
555+
* @return {Range}
556+
*/
557+
function toRange(start, end) {
558+
return Ranges.create(
559+
container(start),
560+
offset(start),
561+
container(end),
562+
offset(end)
563+
);
564+
}
565+
573566
/**
574567
* Sets the a range to the browser selection according to the given start
575568
* and end boundaries. This operation will cause the selection to be
@@ -582,15 +575,9 @@ define([
582575
if (!end) {
583576
end = start;
584577
}
585-
var sc = container(start);
586-
var so = offset(start);
587-
var ec = container(end);
588-
var eo = offset(end);
589-
var doc = sc.ownerDocument;
578+
var range = toRange(start, end);
579+
var doc = range.commonAncestorContainer.ownerDocument;
590580
var selection = doc.getSelection();
591-
var range = doc.createRange();
592-
range.setStart(sc, so);
593-
range.setEnd(ec, eo);
594581
selection.removeAllRanges();
595582
selection.addRange(range);
596583
}
@@ -603,18 +590,17 @@ define([
603590
* @return {Node}
604591
*/
605592
function commonContainer(start, end) {
606-
var sc = container(start);
607-
var so = offset(start);
608-
var ec = container(end);
609-
var eo = offset(end);
610-
var doc = Dom.Nodes.DOCUMENT === sc.nodeType ? sc : sc.ownerDocument;
611-
var range = doc.createRange();
612-
range.setStart(sc, so);
613-
range.setEnd(ec, eo);
614-
return range.commonAncestorContainer;
593+
return toRange(start, end).commonAncestorContainer;
594+
}
595+
596+
function fromPosition(x, y, doc) {
597+
var range = Ranges.fromPosition(x, y, doc);
598+
return range || fromRange(range);
615599
}
616600

617601
return {
602+
fromPosition : fromPosition,
603+
618604
get : get,
619605
select : select,
620606

@@ -641,6 +627,8 @@ define([
641627
setRangeStart : setRangeStart,
642628
setRangeEnd : setRangeEnd,
643629

630+
range : toRange,
631+
644632
isAtStart : isAtStart,
645633
isAtEnd : isAtEnd,
646634
isAtRawStart : isAtRawStart,
@@ -665,8 +653,6 @@ define([
665653
nodeAfter : nodeAfter,
666654
nodeBefore : nodeBefore,
667655

668-
precedingTextLength : precedingTextLength,
669-
670656
commonContainer : commonContainer
671657
};
672658
});

0 commit comments

Comments
 (0)