SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

David Alpert

  • Code Navigation History

    Support for a basic Code Navigation History has been added to SharpDevelop 2.1 as of revision 1569.  Built to enable "Navigate Back" and "Navigate Forward" with respect to major changes in cursor position, such as that resulting from a "Goto Definition  Ctrl-Enter" command or jumping to the position of an Error in the Error log.

    This feature set is a work in progress; basic functionality is enabled but check the Known issues and Future improvement sections below before posting a Bug Report to the forums.

    Feature summary

    • Two new toolbar buttons provide backwards & forwards navigation through visited positions in the editor windows;
    • Navigating backwards & forwards resets the active file & cursor position to the specified point, effectively "undoing" major cursor position changes;
    • When adding a cursor position to the history, recent similar cursor positions in the same method are removed;

    The NavigationService that lies underneath this feature set has been built for extensibility, delegating the management and navigation of cursor positions to individual IViewContent implementations.  This means that #develop developers can provide backwards/forwards functionality that is tailored to a specific view; for example:

    1. backwards/forwards in a source code file might refer to classes and methods visited rather than specific line numbers;
    2. backwards/forwards in Design view might refer to a list of controls selected while designing;
    3. backwards/forwards in an XML document might refer to nodes in a tree representation;
    At the moment, however, only navigation by filename and line number is supported.  Text file positions are considered the "same" if the difference in line numbers is less than 5, which helps weed out multiple consecutive positions travelled when scrolling via the cusor keys.

    Feature tour

    1. The toolbar buttons appear in the toolbar, disabled when the navigation history is empty:

    2. Navigation points are stored when significant changes are made to the cursor position, most notably via jumps such as using the "Goto Definition" command:

    3. Having clicked "Goto Definition" and jumped to a new position in the source code, notice that the "Navigate Back" button is enabled:

    4. We can now click on the "Navigate Back" button to return to the code position we just left:

    5. Now that we've gone back, notice that the "Navigate Forward" button is also enabled:

    6. Clicking the "Navigate Forward" button returns us forward along the code path to the cursor position from which we navigated back:

    7. Now that we have returned forward to the end of our history (the place where we first clicked "Navigate Back") the "Navigate Forward" button is disabled, as expected:

    8. Using the drop-down portion of the "Navigate Back" split button control, we can open a list of all cursor positions stored in our history.  This list is grouped by file (while only the name of each file appears at the top menu, sorting is done on complete file path):

    9. Pulling open each file name's submenu opens a list of positions in that file, each represented by the line number and a snip of text from that line:

    10. The last item in the "Navigate Back" drop-down menu allows you to empty the navigation history:

    11. And we see that both buttons are disabled, as expected:

    Technically, the history is not actually empty at this point, as the current cursor position is stored against the possiblity of future position changes.  The buttons are disabled because, although this current position is still stored, forwards and backwards are meaningless when only one position exists.

    Known issues 

    • Navigation history is not stored between sessions - the navigation history is built from scratch on startup as previously open files are reopened;
    • Navigation that involves opening a previously closed file tends to log an unintended "initial" file position (at line 1, column 1) in addition to the desired editor position;
    • Going "forward" to the end of the navigation path correctly disables the "Navigate Forward" button, but going "backward" to the beginning of the path does not disable the "Navigate Back" button; at present this is by design to allow direct navigation to any stored point via the "Navigate Back" button's dropdown.

    Future improvements

    • Filename changes and document operations (insertions/deletions) will be tracked and navigation points automatically updated accordingly;
    • Class & method info will be stored alongside the filename and line number so that the dropdown menu can be organized by class as well as filename;
    • When adding a cursor position to the history, all other cursor positions in the same method are removed.

This Blog




Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this ( email address.