Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 203 lines (165 sloc) 7.727 kb
37bc2f3 Jared Parsons Added the definition for a jump list
authored
1 #light
2
3 namespace Vim
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
4 open Microsoft.VisualStudio.Text
8d632fe Jared Parsons Added support for the ' mark
authored
5 open Microsoft.VisualStudio.Text.Editor
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
6 open System.Collections.Generic
37bc2f3 Jared Parsons Added the definition for a jump list
authored
7
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
8 /// Implementation of the IJumpList. Maintains a jumpable list of points for the current
9 /// window
10 type internal JumpList
11 (
8d632fe Jared Parsons Added support for the ' mark
authored
12 _textView : ITextView,
6b64fd2 Jared Parsons Added support for gv
authored
13 _bufferTrackingService : IBufferTrackingService
8d632fe Jared Parsons Added support for the ' mark
authored
14 ) =
15
16 let _textBuffer = _textView.TextBuffer
37bc2f3 Jared Parsons Added the definition for a jump list
authored
17
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
18 /// The limit of items in the jump list is 100. See ':help jumplist'
19 let _limit = 100
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
20
6041276 Jared Parsons Fixed some bugs in JumpList
authored
21 /// This is the LinkedList containing the jump list. To keep the terminology consistent
22 /// we add new items to the end of the LinkedList and start our iteration at that point. To
23 /// do otherwise forces us to use the Next values on linked list nodes to implement
24 /// MovePrevious and that simply produces confusion
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
25 let _list = new LinkedList<ITrackingLineColumn>()
26
8d632fe Jared Parsons Added support for the ' mark
authored
27 /// Index into the linked list of values. Contains a value if we are actively traversing
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
28 let mutable _current : (LinkedListNode<ITrackingLineColumn> * int) option = None
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
29
8d632fe Jared Parsons Added support for the ' mark
authored
30 /// Last jump from location
31 let mutable _lastJumpLocation : ITrackingLineColumn option = None
32
33 /// Return the point for the caret before the most recent jump
34 member x.LastJumpLocation = _lastJumpLocation |> OptionUtil.map2 (fun trackingLineColumn -> trackingLineColumn.VirtualPoint)
35
36 /// Return the information for the current location in the list
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
37 member x.Current =
38 match _current with
39 | None -> None
40 | Some (current, _) -> current.Value.Point
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
41
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
42 /// Return the current index
43 member x.CurrentIndex =
44 match _current with
45 | None -> None
46 | Some (_, index) -> Some index
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
47
8d632fe Jared Parsons Added support for the ' mark
authored
48 member x.IsTraversing = Option.isSome _current
49
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
50 /// Returns all of the Jumps. It's technically possible for an ITrackingLineColumn to
51 /// no longer track due to an error in the tracking. If that's the case just represent
52 /// it as point 0 in the ITextSnapshot
53 member x.Jumps =
54 _list
55 |> Seq.map (fun tlc ->
56 match tlc.VirtualPoint with
57 | Some point -> point
58 | None -> VirtualSnapshotPoint(tlc.TextBuffer.CurrentSnapshot, 0))
59 |> List.ofSeq
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
60
8d632fe Jared Parsons Added support for the ' mark
authored
61 /// Find the LinkedListNode tracking the provided line number. Returns None if
62 /// one doesn't exist
63 member x.FindNodeTrackingLine lineNumber =
64 let rec inner (current : LinkedListNode<ITrackingLineColumn>) =
65
66 let currentLineNumber = current.Value.Point |> Option.map SnapshotPointUtil.GetLineNumber
67 let matches =
68 match currentLineNumber with
69 | None -> false
70 | Some currentLineNumber -> currentLineNumber = lineNumber
71 if matches then
72 Some current
73 elif current.Next = null then
74 None
75 else
76 inner current.Next
77
78 if _list.Count = 0 then
79 None
80 else
81 inner _list.First
82
83 /// Add the SnapshotPoint into the jump list and return the LinkedListNode which
84 /// it occupies
85 member x.AddCore point =
86
87 // First complete the existing traversal. Adding a new jump point ends the
88 // traversal
89 _current <- None
90
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
91 let line, column = SnapshotPointUtil.GetLineColumn point
8d632fe Jared Parsons Added support for the ' mark
authored
92
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
93 let trackingLineColumn =
8d632fe Jared Parsons Added support for the ' mark
authored
94 match x.FindNodeTrackingLine line with
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
95 | None ->
8d632fe Jared Parsons Added support for the ' mark
authored
96 // No node currently tracking that line. Create a new one
97 _bufferTrackingService.CreateLineColumn _textBuffer line column LineColumnTrackingMode.SurviveDeletes
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
98 | Some node ->
8d632fe Jared Parsons Added support for the ' mark
authored
99 // Existing node. Re-use the ITrackingLineColumn and remove the node from
100 // the list
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
101 _list.Remove(node) |> ignore
102 node.Value
103
8d632fe Jared Parsons Added support for the ' mark
authored
104 let node = _list.AddFirst(trackingLineColumn)
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
105
106 // Truncate the end of the list
107 while _list.Count > _limit do
108 _list.Last.Value.Close()
109 _list.RemoveLast()
0a71b10 Jared Parsons Added JumpList test support
authored
110
8d632fe Jared Parsons Added support for the ' mark
authored
111 node
112
113 /// Add the SnapshotPoint into the jump list. This will end the current traversal and
114 /// update the LastJumpLocation to that point
115 member x.Add point =
116
117 // First complete the existing traversal. Adding a new jump point ends the
118 // traversal
119 _current <- None
120
121 let line, column = SnapshotPointUtil.GetLineColumn point
122 x.SetLastJumpLocation line column
123
124 x.AddCore point |> ignore
125
126 /// Clear out all of the tracking data
127 member x.Clear() =
128 _current <- None
129
130 // Clear out the list of jump locations
131 _list
132 |> Seq.iter (fun trackingLineColumn -> trackingLineColumn.Close())
133 _list.Clear()
134
135 // Clear out the last jump location
136 match _lastJumpLocation with
137 | None -> ()
138 | Some trackingLineColumn -> trackingLineColumn.Close()
139 _lastJumpLocation <- None
140
d4324e1 Jared Parsons Fixed a few jump list issues
authored
141 /// Move to the newer node in the jump list.
142 member x.MoveNewer count =
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
143 match _current with
144 | None ->
8d632fe Jared Parsons Added support for the ' mark
authored
145 // Not traversing
6041276 Jared Parsons Fixed some bugs in JumpList
authored
146 false
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
147 | Some (current, index) ->
148 let rec inner (current : LinkedListNode<ITrackingLineColumn>) count =
149 if count = 0 then current, true
150 elif current.Previous = null then current, false
151 else inner current.Previous (count - 1)
152
153 let current, success = inner current count
154 if success then
155 _current <- Some (current, index - count)
156 success
6041276 Jared Parsons Fixed some bugs in JumpList
authored
157
8d632fe Jared Parsons Added support for the ' mark
authored
158 /// Move to the older node in the jump list. This will start a traversal if
159 /// we are not yet traversing the list
d4324e1 Jared Parsons Fixed a few jump list issues
authored
160 member x.MoveOlder count =
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
161 match _current with
162 | None ->
8d632fe Jared Parsons Added support for the ' mark
authored
163 // Not traversing
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
164 false
165 | Some (current, index) ->
166 let rec inner (current : LinkedListNode<ITrackingLineColumn>) count =
167 if count = 0 then current, true
168 elif current.Next = null then current, false
169 else inner current.Next (count - 1)
170 let current, success = inner current count
171 if success then
172 _current <- Some (current, index + count)
173 success
6041276 Jared Parsons Fixed some bugs in JumpList
authored
174
8d632fe Jared Parsons Added support for the ' mark
authored
175 /// Set the last jump location to the provided line and column in the ITextView
176 member x.SetLastJumpLocation line column =
177 match _lastJumpLocation with
178 | None -> ()
179 | Some trackingLineColumn -> trackingLineColumn.Close()
180
181 _lastJumpLocation <- Some (_bufferTrackingService.CreateLineColumn _textView.TextBuffer line column LineColumnTrackingMode.Default)
182
183 /// Start a traversal of the jump list
184 member x.StartTraversal() =
185 let caretPoint = TextViewUtil.GetCaretPoint _textView
186 let node = x.AddCore caretPoint
187 _current <- Some (node, 0)
188
37bc2f3 Jared Parsons Added the definition for a jump list
authored
189 interface IJumpList with
8d632fe Jared Parsons Added support for the ' mark
authored
190 member x.TextView = _textView
23c7019 Jared Parsons Implemented JumpList, now for the testing
authored
191 member x.Current = x.Current
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
192 member x.CurrentIndex = x.CurrentIndex
8d632fe Jared Parsons Added support for the ' mark
authored
193 member x.IsTraversing = x.IsTraversing
7a3a08e Jared Parsons Started out fixing jump list hookup. Ended up doing a lot of work with ...
authored
194 member x.Jumps = x.Jumps
8d632fe Jared Parsons Added support for the ' mark
authored
195 member x.LastJumpLocation = x.LastJumpLocation
196 member x.Add point = x.Add point
197 member x.Clear() = x.Clear()
d4324e1 Jared Parsons Fixed a few jump list issues
authored
198 member x.MoveNewer count = x.MoveNewer count
199 member x.MoveOlder count = x.MoveOlder count
8d632fe Jared Parsons Added support for the ' mark
authored
200 member x.SetLastJumpLocation line column = x.SetLastJumpLocation line column
201 member x.StartTraversal() = x.StartTraversal()
37bc2f3 Jared Parsons Added the definition for a jump list
authored
202
Something went wrong with that request. Please try again.