| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var Selection = function(handler) { | 5 var Selection = function(handler) { |
| 6 this.handler = handler; | 6 this.handler = handler; |
| 7 this.selectionBase = null; | 7 this.selectionBase = null; |
| 8 this.lastSelection = null; | 8 this.lastSelection = null; |
| 9 this.selection = new Set(); | 9 this.selection = new Set(); |
| 10 } | 10 } |
| 11 | 11 |
| 12 | 12 |
| 13 Selection.prototype.isEmpty = function() { | 13 Selection.prototype.isEmpty = function() { |
| 14 return this.selection.size == 0; | 14 return this.selection.size == 0; |
| 15 } | 15 } |
| 16 | 16 |
| 17 | 17 |
| 18 Selection.prototype.clear = function() { | 18 Selection.prototype.clear = function() { |
| 19 var handler = this.handler; | 19 var handler = this.handler; |
| 20 this.selectionBase = null; | 20 this.selectionBase = null; |
| 21 this.lastSelection = null; | 21 this.lastSelection = null; |
| 22 handler.select(this.selection, false); | 22 handler.select(this.selection, false); |
| 23 handler.clear(); | 23 handler.clear(); |
| 24 this.selection = new Set(); | 24 this.selection = new Set(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 count = 0; | 28 count = 0; |
| 29 | 29 |
| 30 Selection.prototype.select = function(s, selected) { | 30 Selection.prototype.select = function(s, isSelected) { |
| 31 var handler = this.handler; | 31 var handler = this.handler; |
| 32 if (this.selection.has(s) && !selected) { | 32 if (!(Symbol.iterator in Object(s))) { s = [s]; } |
| 33 handler.select([s], false); | 33 if (isSelected) { |
| 34 this.selection.delete(s); | 34 let first = true; |
| 35 return; | 35 for (let i of s) { |
| 36 if (first) { |
| 37 this.selectionBase = i; |
| 38 this.lastSelection = i; |
| 39 first = false; |
| 40 } |
| 41 this.selection.add(i); |
| 42 } |
| 43 } else { |
| 44 let unselectSet = new Set(); |
| 45 for (let i of s) { |
| 46 if (this.selection.has(i)) { |
| 47 unselectSet.add(i); |
| 48 this.selection.delete(i); |
| 49 } |
| 50 } |
| 36 } | 51 } |
| 37 | 52 handler.select(this.selection, isSelected); |
| 38 if (selected) { | |
| 39 this.selection.add(s); | |
| 40 this.selectionBase = s; | |
| 41 this.lastSelection = s; | |
| 42 handler.select(this.selection, selected); | |
| 43 } | |
| 44 } | 53 } |
| 45 | 54 |
| 46 | 55 |
| 47 Selection.prototype.extendTo = function(pos) { | 56 Selection.prototype.extendTo = function(pos) { |
| 48 if (pos == this.lastSelection || this.lastSelection === null) return; | 57 if (pos == this.lastSelection || this.lastSelection === null) return; |
| 49 | 58 |
| 50 var handler = this.handler; | 59 var handler = this.handler; |
| 51 var pos_diff = handler.selectionDifference(pos, true, this.lastSelection, fals
e); | 60 var pos_diff = handler.selectionDifference(pos, true, this.lastSelection, fals
e); |
| 52 var unselect_diff = []; | 61 var unselect_diff = []; |
| 53 if (pos_diff.length == 0) { | 62 if (pos_diff.length == 0) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 98 |
| 90 | 99 |
| 91 Selection.prototype.detachSelection = function() { | 100 Selection.prototype.detachSelection = function() { |
| 92 var result = new Set(); | 101 var result = new Set(); |
| 93 for (var i of this.selection) { | 102 for (var i of this.selection) { |
| 94 result.add(i); | 103 result.add(i); |
| 95 } | 104 } |
| 96 this.clear(); | 105 this.clear(); |
| 97 return result; | 106 return result; |
| 98 } | 107 } |
| OLD | NEW |