Skip to content

Reset cursor to approximate source position after reformatting in SSMS, VS and NPP #96

TaoK opened this Issue Apr 9, 2013 · 1 comment

2 participants

TaoK commented Apr 9, 2013

Algorithm something like this:

  • Determine the position of the start of the selection (start point)
  • Determine the position of the end of the selection (end point)
  • Determine the length of the selection (end point - start point = original length)
  • Determine the position of the cursor within the selection, in characters (original pos)
  • Get the formatted content to replace the selection
  • Determine the length of the new content (new length)
  • Determine the new position within the selection (new length * original pos / original length = new pos)
  • Replace the selection
  • Place the cursor at the required position (adding the "start point" to the "new pos" value to get the absolute position within the window content)

Suggested by Paul



  • go to end of current line
  • put in a special comment saving the your current cursor position--$$PoorMansBookmark@Colum-nn$$
  • Format the document
  • go to the special comment and get the cursor column position
  • remove the special comment
  • go to your previous column
@TaoK TaoK added a commit that referenced this issue Oct 20, 2013
@TaoK Issue #96: Part 2 (final): Return to (approximate) previous cursor po…
…sition after a full document reformat in SSMS / VS
@TaoK TaoK closed this Oct 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.