| 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 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 if (isSelected) { | 33 if (isSelected) { |
| 34 let first = true; | 34 let first = true; |
| 35 for (let i of s) { | 35 for (let i of s) { |
| 36 if (first) { | 36 if (first) { |
| 37 this.selectionBase = i; | 37 this.selectionBase = i; |
| 38 this.lastSelection = i; | 38 this.lastSelection = i; |
| 39 first = false; | 39 first = false; |
| 40 } | 40 } |
| 41 this.selection.add(i); | 41 this.selection.add(i); |
| 42 } | 42 } |
| 43 handler.select(this.selection, true); |
| 43 } else { | 44 } else { |
| 44 let unselectSet = new Set(); | 45 let unselectSet = new Set(); |
| 45 for (let i of s) { | 46 for (let i of s) { |
| 46 if (this.selection.has(i)) { | 47 if (this.selection.has(i)) { |
| 47 unselectSet.add(i); | 48 unselectSet.add(i); |
| 48 this.selection.delete(i); | 49 this.selection.delete(i); |
| 49 } | 50 } |
| 50 } | 51 } |
| 52 handler.select(unselectSet, false); |
| 51 } | 53 } |
| 52 handler.select(this.selection, isSelected); | |
| 53 } | 54 } |
| 54 | 55 |
| 55 | 56 |
| 56 Selection.prototype.extendTo = function(pos) { | 57 Selection.prototype.extendTo = function(pos) { |
| 57 if (pos == this.lastSelection || this.lastSelection === null) return; | 58 if (pos == this.lastSelection || this.lastSelection === null) return; |
| 58 | 59 |
| 59 var handler = this.handler; | 60 var handler = this.handler; |
| 60 var pos_diff = handler.selectionDifference(pos, true, this.lastSelection, fals
e); | 61 var pos_diff = handler.selectionDifference(pos, true, this.lastSelection, fals
e); |
| 61 var unselect_diff = []; | 62 var unselect_diff = []; |
| 62 if (pos_diff.length == 0) { | 63 if (pos_diff.length == 0) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 99 |
| 99 | 100 |
| 100 Selection.prototype.detachSelection = function() { | 101 Selection.prototype.detachSelection = function() { |
| 101 var result = new Set(); | 102 var result = new Set(); |
| 102 for (var i of this.selection) { | 103 for (var i of this.selection) { |
| 103 result.add(i); | 104 result.add(i); |
| 104 } | 105 } |
| 105 this.clear(); | 106 this.clear(); |
| 106 return result; | 107 return result; |
| 107 } | 108 } |
| OLD | NEW |