2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @param {!WebInspector.SourcesView} sourcesView
34 * @param {function():?WebInspector.SourceFrame} currentSourceFrameCallback
36 WebInspector
.EditingLocationHistoryManager = function(sourcesView
, currentSourceFrameCallback
)
38 this._sourcesView
= sourcesView
;
39 this._historyManager
= new WebInspector
.SimpleHistoryManager(WebInspector
.EditingLocationHistoryManager
.HistoryDepth
);
40 this._currentSourceFrameCallback
= currentSourceFrameCallback
;
43 WebInspector
.EditingLocationHistoryManager
.HistoryDepth
= 20;
45 WebInspector
.EditingLocationHistoryManager
.prototype = {
47 * @param {!WebInspector.UISourceCodeFrame} sourceFrame
49 trackSourceFrameCursorJumps: function(sourceFrame
)
51 sourceFrame
.addEventListener(WebInspector
.SourceFrame
.Events
.JumpHappened
, this._onJumpHappened
.bind(this));
55 * @param {!WebInspector.Event} event
57 _onJumpHappened: function(event
)
60 this._updateActiveState(event
.data
.from);
62 this._pushActiveState(event
.data
.to
);
67 this._historyManager
.rollback();
72 this._historyManager
.rollover();
75 updateCurrentState: function()
77 var sourceFrame
= this._currentSourceFrameCallback();
80 this._updateActiveState(sourceFrame
.textEditor
.selection());
83 pushNewState: function()
85 var sourceFrame
= this._currentSourceFrameCallback();
88 this._pushActiveState(sourceFrame
.textEditor
.selection());
92 * @param {!WebInspector.TextRange} selection
94 _updateActiveState: function(selection
)
96 var active
= this._historyManager
.active();
99 var sourceFrame
= this._currentSourceFrameCallback();
102 var entry
= new WebInspector
.EditingLocationHistoryEntry(this._sourcesView
, this, sourceFrame
, selection
);
107 * @param {!WebInspector.TextRange} selection
109 _pushActiveState: function(selection
)
111 var sourceFrame
= this._currentSourceFrameCallback();
114 var entry
= new WebInspector
.EditingLocationHistoryEntry(this._sourcesView
, this, sourceFrame
, selection
);
115 this._historyManager
.push(entry
);
119 * @param {!WebInspector.UISourceCode} uiSourceCode
121 removeHistoryForSourceCode: function(uiSourceCode
)
123 function filterOut(entry
)
125 return entry
._projectId
=== uiSourceCode
.project().id() && entry
._path
=== uiSourceCode
.path();
128 this._historyManager
.filterOut(filterOut
);
135 * @implements {WebInspector.HistoryEntry}
136 * @param {!WebInspector.SourcesView} sourcesView
137 * @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager
138 * @param {!WebInspector.SourceFrame} sourceFrame
139 * @param {!WebInspector.TextRange} selection
141 WebInspector
.EditingLocationHistoryEntry = function(sourcesView
, editingLocationManager
, sourceFrame
, selection
)
143 this._sourcesView
= sourcesView
;
144 this._editingLocationManager
= editingLocationManager
;
145 var uiSourceCode
= sourceFrame
.uiSourceCode();
146 this._projectId
= uiSourceCode
.project().id();
147 this._path
= uiSourceCode
.path();
149 var position
= this._positionFromSelection(selection
);
150 this._positionHandle
= sourceFrame
.textEditor
.textEditorPositionHandle(position
.lineNumber
, position
.columnNumber
);
153 WebInspector
.EditingLocationHistoryEntry
.prototype = {
155 * @param {!WebInspector.HistoryEntry} entry
157 merge: function(entry
)
159 if (this._projectId
!== entry
._projectId
|| this._path
!== entry
._path
)
161 this._positionHandle
= entry
._positionHandle
;
165 * @param {!WebInspector.TextRange} selection
166 * @return {!{lineNumber: number, columnNumber: number}}
168 _positionFromSelection: function(selection
)
171 lineNumber
: selection
.endLine
,
172 columnNumber
: selection
.endColumn
182 var position
= this._positionHandle
.resolve();
183 var uiSourceCode
= WebInspector
.workspace
.project(this._projectId
).uiSourceCode(this._path
);
184 return !!(position
&& uiSourceCode
);
192 var position
= this._positionHandle
.resolve();
193 var uiSourceCode
= WebInspector
.workspace
.project(this._projectId
).uiSourceCode(this._path
);
194 if (!position
|| !uiSourceCode
)
197 this._editingLocationManager
.updateCurrentState();
198 this._sourcesView
.showSourceLocation(uiSourceCode
, position
.lineNumber
, position
.columnNumber
);