278 } |
278 } |
279 } |
279 } |
280 } |
280 } |
281 |
281 |
282 override def hyperlink_command( |
282 override def hyperlink_command( |
283 focus: Boolean, snapshot: Document.Snapshot, command: Command, offset: Symbol.Offset = 0) |
283 focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic, offset: Symbol.Offset = 0) |
284 : Option[Hyperlink] = |
284 : Option[Hyperlink] = |
285 { |
285 { |
286 if (snapshot.is_outdated) None |
286 if (snapshot.is_outdated) None |
287 else { |
287 else { |
288 snapshot.state.find_command(snapshot.version, command.id) match { |
288 snapshot.state.find_command(snapshot.version, id) match { |
289 case None => None |
289 case None => None |
290 case Some((node, _)) => |
290 case Some((node, command)) => |
291 val name = command.node_name.node |
291 val name = command.node_name.node |
292 val sources_iterator = |
292 val sources_iterator = |
293 node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
293 node.commands.iterator.takeWhile(_ != command).map(_.source) ++ |
294 (if (offset == 0) Iterator.empty |
294 (if (offset == 0) Iterator.empty |
295 else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset))))) |
295 else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset))))) |
296 val pos = (Line.Position.zero /: sources_iterator)(_.advance(_)) |
296 val pos = (Line.Position.zero /: sources_iterator)(_.advance(_)) |
297 Some(hyperlink_file(focus, Line.Node_Position(name, pos))) |
297 Some(hyperlink_file(focus, Line.Node_Position(name, pos))) |
298 } |
298 } |
299 } |
|
300 } |
|
301 |
|
302 def hyperlink_command_id( |
|
303 focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic, offset: Symbol.Offset = 0) |
|
304 : Option[Hyperlink] = |
|
305 { |
|
306 snapshot.state.find_command(snapshot.version, id) match { |
|
307 case Some((node, command)) => hyperlink_command(focus, snapshot, command, offset) |
|
308 case None => None |
|
309 } |
299 } |
310 } |
300 } |
311 |
301 |
312 def is_hyperlink_position(snapshot: Document.Snapshot, |
302 def is_hyperlink_position(snapshot: Document.Snapshot, |
313 text_offset: Text.Offset, pos: Position.T): Boolean = |
303 text_offset: Text.Offset, pos: Position.T): Boolean = |
330 : Option[Hyperlink] = |
320 : Option[Hyperlink] = |
331 pos match { |
321 pos match { |
332 case Position.Item_File(name, line, offset) => |
322 case Position.Item_File(name, line, offset) => |
333 hyperlink_source_file(focus, name, line, offset) |
323 hyperlink_source_file(focus, name, line, offset) |
334 case Position.Item_Id(id, offset) => |
324 case Position.Item_Id(id, offset) => |
335 hyperlink_command_id(focus, snapshot, id, offset) |
325 hyperlink_command(focus, snapshot, id, offset) |
336 case _ => None |
326 case _ => None |
337 } |
327 } |
338 |
328 |
339 def hyperlink_def_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
329 def hyperlink_def_position(focus: Boolean, snapshot: Document.Snapshot, pos: Position.T) |
340 : Option[Hyperlink] = |
330 : Option[Hyperlink] = |
341 pos match { |
331 pos match { |
342 case Position.Item_Def_File(name, line, offset) => |
332 case Position.Item_Def_File(name, line, offset) => |
343 hyperlink_source_file(focus, name, line, offset) |
333 hyperlink_source_file(focus, name, line, offset) |
344 case Position.Item_Def_Id(id, offset) => |
334 case Position.Item_Def_Id(id, offset) => |
345 hyperlink_command_id(focus, snapshot, id, offset) |
335 hyperlink_command(focus, snapshot, id, offset) |
346 case _ => None |
336 case _ => None |
347 } |
337 } |
348 } |
338 } |