Team LiB
Previous Section Next Section

Fun Pet Trick #2: Selection Preservation on View Switch

By Scott Guthrie

One of the nice new features in Visual Studio is that the cursor position is now maintained when switching views between design and source mode.

Specifically, if you have a control selected in design mode, and then switch to source mode, the cursor in source mode will automatically be positioned to the first character of the server control tag.

If you move the cursor onto another server control or HTML element, and then switch to design mode, that control will be selected by default.

If you highlight any text in source mode, and then switch to design mode, that text range will show up selected in design mode. Likewise, if you select a different block of text in design mode and then switch to source mode, that text will be highlighted in the editor.

The end result of this feature is that you can rapidly switch back and forth between design and source mode—without having to spend time scrolling or figuring out where you are in the document.

To try this out, save and load the following file inside the IDE. Move the cursor around in source mode onto the calendar, and then flip into design mode. Notice the calendar is automatically selected. Select the button, and switch into source mode. Notice the cursor position on the button. Highlight "est" from the simple test string at the top, and then switch into design mode and notice the text selection.

<%@ page language="VB" %>

<html>
<body>
    <form runat="server">
        This is a simple test of control selection<br />
        <br />
        <asp:button id="Button1" runat="server" text="Button" />
        <br />
        <br />
        <asp:calendar id="Calendar1" runat="server">
        </asp:calendar>
    </form>
</body>
</html>

A small feature, but it adds a nice touch to the editing experience.


Team LiB
Previous Section Next Section