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.
- 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:
- backwards/forwards in a source code file might refer to classes and methods visited rather than specific line numbers;
- backwards/forwards in Design view might refer to a list of controls selected while designing;
- 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.
- The toolbar buttons appear in the toolbar, disabled when the navigation history is empty:
- Navigation points are stored when significant changes are made to the cursor position, most notably via jumps such as using the "Goto Definition" command:
- Having clicked "Goto Definition" and jumped to a new position in the source code, notice that the "Navigate Back" button is enabled:
- We can now click on the "Navigate Back" button to return to the code position we just left:
- Now that we've gone back, notice that the "Navigate Forward" button is also enabled:
- Clicking the "Navigate Forward" button returns us forward along the code path to the cursor position from which we navigated back:
- 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:
- 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):
- 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:
- The last item in the "Navigate Back" drop-down menu allows you to empty the navigation history:
- 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.
- 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.
- 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.