OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var Selection = function(handler) { |
| 6 this.handler = handler; |
| 7 this.selectionBase = null; |
| 8 this.lastSelection = null; |
| 9 this.selection = new Set(); |
| 10 } |
| 11 |
| 12 |
| 13 Selection.prototype.isEmpty = function() { |
| 14 return this.selection.size == 0; |
| 15 } |
| 16 |
| 17 |
| 18 Selection.prototype.clear = function() { |
| 19 var handler = this.handler; |
| 20 this.selectionBase = null; |
| 21 this.lastSelection = null; |
| 22 handler.select(this.selection, false); |
| 23 handler.clear(); |
| 24 this.selection = new Set(); |
| 25 } |
| 26 |
| 27 |
| 28 count = 0; |
| 29 |
| 30 Selection.prototype.select = function(s, selected) { |
| 31 var handler = this.handler; |
| 32 if (this.selection.has(s) && !selected) { |
| 33 handler.select([s], false); |
| 34 this.selection.delete(s); |
| 35 return; |
| 36 } |
| 37 |
| 38 if (selected) { |
| 39 this.selection.add(s); |
| 40 this.selectionBase = s; |
| 41 this.lastSelection = s; |
| 42 handler.select(this.selection, selected); |
| 43 } |
| 44 } |
| 45 |
| 46 |
| 47 Selection.prototype.extendTo = function(pos) { |
| 48 if (pos == this.lastSelection || this.lastSelection === null) return; |
| 49 |
| 50 var handler = this.handler; |
| 51 var pos_diff = handler.selectionDifference(pos, true, this.lastSelection, fals
e); |
| 52 var unselect_diff = []; |
| 53 if (pos_diff.length == 0) { |
| 54 pos_diff = handler.selectionDifference(this.selectionBase, false, pos, true)
; |
| 55 if (pos_diff.length != 0) { |
| 56 unselect_diff = handler.selectionDifference(this.lastSelection, true, this
.selectionBase, false); |
| 57 this.selection = new Set(); |
| 58 this.selection.add(this.selectionBase); |
| 59 for (var d of pos_diff) { |
| 60 this.selection.add(d); |
| 61 } |
| 62 } else { |
| 63 unselect_diff = handler.selectionDifference(this.lastSelection, true, pos,
false); |
| 64 for (var d of unselect_diff) { |
| 65 this.selection.delete(d); |
| 66 } |
| 67 } |
| 68 } else { |
| 69 unselect_diff = handler.selectionDifference(this.selectionBase, false, this.
lastSelection, true); |
| 70 if (unselect_diff != 0) { |
| 71 pos_diff = handler.selectionDifference(pos, true, this.selectionBase, fals
e); |
| 72 if (pos_diff.length == 0) { |
| 73 unselect_diff = handler.selectionDifference(pos, false, this.lastSelecti
on, true); |
| 74 } |
| 75 for (var d of unselect_diff) { |
| 76 this.selection.delete(d); |
| 77 } |
| 78 } |
| 79 if (pos_diff.length != 0) { |
| 80 for (var d of pos_diff) { |
| 81 this.selection.add(d); |
| 82 } |
| 83 } |
| 84 } |
| 85 handler.select(unselect_diff, false); |
| 86 handler.select(pos_diff, true); |
| 87 this.lastSelection = pos; |
| 88 } |
| 89 |
| 90 |
| 91 Selection.prototype.detachSelection = function() { |
| 92 var result = new Set(); |
| 93 for (var i of this.selection) { |
| 94 result.add(i); |
| 95 } |
| 96 this.clear(); |
| 97 return result; |
| 98 } |
OLD | NEW |