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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 class TextView extends View { | 7 class TextView extends View { |
8 constructor(id, broker, patterns, allowSpanSelection) { | 8 constructor(id, broker, patterns, allowSpanSelection) { |
9 super(id, broker); | 9 super(id, broker); |
10 let view = this; | 10 let view = this; |
(...skipping 10 matching lines...) Expand all Loading... | |
21 broker.clear(selectionHandler); | 21 broker.clear(selectionHandler); |
22 }, | 22 }, |
23 select: function(items, selected) { | 23 select: function(items, selected) { |
24 for (let i of items) { | 24 for (let i of items) { |
25 if (selected) { | 25 if (selected) { |
26 i.classList.add("selected"); | 26 i.classList.add("selected"); |
27 } else { | 27 } else { |
28 i.classList.remove("selected"); | 28 i.classList.remove("selected"); |
29 } | 29 } |
30 } | 30 } |
31 broker.clear(selectionHandler); | |
31 broker.select(selectionHandler, view.getRanges(items), selected); | 32 broker.select(selectionHandler, view.getRanges(items), selected); |
32 }, | 33 }, |
33 selectionDifference: function(span1, inclusive1, span2, inclusive2) { | 34 selectionDifference: function(span1, inclusive1, span2, inclusive2) { |
34 return null; | 35 return null; |
35 }, | 36 }, |
36 brokeredSelect: function(ranges, selected) { | 37 brokeredSelect: function(ranges, selected) { |
37 let locations = view.rangesToLocations(ranges); | 38 let locations = view.rangesToLocations(ranges); |
38 view.selectLocations(locations, selected, true); | 39 view.selectLocations(locations, selected, true); |
39 }, | 40 }, |
40 brokeredClear: function() { | 41 brokeredClear: function() { |
(...skipping 20 matching lines...) Expand all Loading... | |
61 return range; | 62 return range; |
62 } | 63 } |
63 | 64 |
64 rangesToLocations(ranges) { | 65 rangesToLocations(ranges) { |
65 let view = this; | 66 let view = this; |
66 let nodes = new Set(); | 67 let nodes = new Set(); |
67 let result = []; | 68 let result = []; |
68 for (let range of ranges) { | 69 for (let range of ranges) { |
69 let start = range[0]; | 70 let start = range[0]; |
70 let end = range[1]; | 71 let end = range[1]; |
71 let location = { pos_start: start, pos_end: end }; | 72 let block_id = range[3]; |
73 let location = { pos_start: start, pos_end: end, block_id: block_id }; | |
72 if (range[2] !== null && range[2] != -1) { | 74 if (range[2] !== null && range[2] != -1) { |
73 location.node_id = range[2]; | 75 location.node_id = range[2]; |
74 if (range[0] == -1 && range[1] == -1) { | 76 if (range[0] == -1 && range[1] == -1) { |
75 location.pos_start = view.nodePositionMap[location.node_id]; | 77 location.pos_start = view.nodePositionMap[location.node_id]; |
76 location.pos_end = location.pos_start + 1; | 78 location.pos_end = location.pos_start + 1; |
77 } | 79 } |
78 } else { | 80 } else { |
79 if (range[0] != undefined) { | 81 if (range[0] != undefined) { |
80 location.pos_start = range[0]; | 82 location.pos_start = range[0]; |
81 location.pos_end = range[1]; | 83 location.pos_end = range[1]; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 | 180 |
179 getRanges(items) { | 181 getRanges(items) { |
180 let result = []; | 182 let result = []; |
181 let lastObject = null; | 183 let lastObject = null; |
182 for (let i of items) { | 184 for (let i of items) { |
183 if (i.location) { | 185 if (i.location) { |
184 let location = i.location; | 186 let location = i.location; |
185 let start = -1; | 187 let start = -1; |
186 let end = -1; | 188 let end = -1; |
187 let node_id = -1; | 189 let node_id = -1; |
190 let block_id = -1; | |
188 if (location.node_id !== undefined) { | 191 if (location.node_id !== undefined) { |
189 node_id = location.node_id; | 192 node_id = location.node_id; |
190 } | 193 } |
194 if (location.block_id !== undefined) { | |
195 block_id = location.block_id; | |
196 } | |
191 if (location.pos_start !== undefined) { | 197 if (location.pos_start !== undefined) { |
192 start = location.pos_start; | 198 start = location.pos_start; |
193 end = location.pos_end; | 199 end = location.pos_end; |
194 } else { | 200 } else { |
195 if (this.nodePositionMap && this.nodePositionMap[node_id]) { | 201 if (this.nodePositionMap && this.nodePositionMap[node_id]) { |
196 start = this.nodePositionMap[node_id]; | 202 start = this.nodePositionMap[node_id]; |
197 end = start + 1; | 203 end = start + 1; |
198 } | 204 } |
199 } | 205 } |
200 if (lastObject == null || | 206 if (lastObject == null || |
201 (lastObject[2] != node_id || | 207 (lastObject[2] != node_id || |
202 lastObject[0] != start || | 208 lastObject[0] != start || |
203 lastObject[1] != end)) { | 209 lastObject[1] != end || |
204 lastObject = [start, end, node_id]; | 210 lastObject[3] != block_id)) { |
211 lastObject = [start, end, node_id, block_id]; | |
205 result.push(lastObject); | 212 result.push(lastObject); |
206 } | 213 } |
207 } | 214 } |
208 } | 215 } |
209 return result; | 216 return result; |
210 } | 217 } |
211 | 218 |
212 createFragment(text, style) { | 219 createFragment(text, style) { |
213 let view = this; | 220 let view = this; |
214 let span = document.createElement("SPAN"); | 221 let span = document.createElement("SPAN"); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 view.selection.select(s, selected); | 317 view.selection.select(s, selected); |
311 } | 318 } |
312 } | 319 } |
313 | 320 |
314 mouseDownLine(li, e) { | 321 mouseDownLine(li, e) { |
315 let view = this; | 322 let view = this; |
316 e.stopPropagation(); | 323 e.stopPropagation(); |
317 if (!e.shiftKey) { | 324 if (!e.shiftKey) { |
318 view.selection.clear(); | 325 view.selection.clear(); |
319 } | 326 } |
327 console.log(li.location); | |
danno
2016/07/08 11:28:07
Was adding this line intentional?
| |
320 if (li.location != undefined) { | 328 if (li.location != undefined) { |
321 view.selectLocations([li.location], true, false); | 329 view.selectLocations([li.location], true, false); |
322 } | 330 } |
323 } | 331 } |
324 | 332 |
325 mouseDownSpan(span, e) { | 333 mouseDownSpan(span, e) { |
326 let view = this; | 334 let view = this; |
327 if (view.allowSpanSelection) { | 335 if (view.allowSpanSelection) { |
328 e.stopPropagation(); | 336 e.stopPropagation(); |
329 if (!e.shiftKey) { | 337 if (!e.shiftKey) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 lineLocation(li) { | 393 lineLocation(li) { |
386 let view = this; | 394 let view = this; |
387 for (let i = 0; i < li.children.length; ++i) { | 395 for (let i = 0; i < li.children.length; ++i) { |
388 let fragment = li.children[i]; | 396 let fragment = li.children[i]; |
389 if (fragment.location != undefined && !view.allowSpanSelection) { | 397 if (fragment.location != undefined && !view.allowSpanSelection) { |
390 return fragment.location; | 398 return fragment.location; |
391 } | 399 } |
392 } | 400 } |
393 } | 401 } |
394 } | 402 } |
OLD | NEW |