Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: Source/devtools/front_end/EditingLocationHistoryManager.js

Issue 23474010: DevTools: "Jump between editing locations" experiment (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline this patch Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31 /**
32 * @constructor
33 * @param {!WebInspector.SourcesPanel} sourcesPanel
34 * @param {!function():!WebInspector.SourceFrame} currentSourceFrameCallback
35 */
36 WebInspector.EditingLocationHistoryManager = function(sourcesPanel, currentSourc eFrameCallback)
37 {
38 this._sourcesPanel = sourcesPanel;
39 this._historyManager = new WebInspector.SimpleHistoryManager(WebInspector.Ed itingLocationHistoryManager.HistoryDepth);
40 this._currentSourceFrameCallback = currentSourceFrameCallback;
41 }
42
43 WebInspector.EditingLocationHistoryManager.HistoryDepth = 20;
44
45 WebInspector.EditingLocationHistoryManager.prototype = {
46 /**
47 * @param {!WebInspector.UISourceCodeFrame} sourceFrame
48 */
49 trackSourceFrameCursorJumps: function(sourceFrame)
50 {
51 sourceFrame.addEventListener(WebInspector.SourceFrame.Events.JumpHappene d, this._onJumpHappened.bind(this));
52 },
53
54 /**
55 * @param {!WebInspector.Event} event
56 */
57 _onJumpHappened: function(event)
58 {
59 if (event.data.from)
60 this._updateActiveState(event.data.from);
61 if (event.data.to)
62 this._pushActiveState(event.data.to);
63 },
64
65 rollback: function()
66 {
67 this._historyManager.rollback();
68 },
69
70 rollover: function()
71 {
72 this._historyManager.rollover();
73 },
74
75 updateCurrentState: function()
76 {
77 var sourceFrame = this._currentSourceFrameCallback();
78 if (!sourceFrame)
79 return;
80 this._updateActiveState(sourceFrame.textEditor.selection());
81 },
82
83 pushNewState: function()
84 {
85 var sourceFrame = this._currentSourceFrameCallback();
86 if (!sourceFrame)
87 return;
88 this._pushActiveState(sourceFrame.textEditor.selection());
89 },
90
91 /**
92 * @param {!WebInspector.TextRange} selection
93 */
94 _updateActiveState: function(selection)
95 {
96 var active = this._historyManager.active();
97 if (!active)
98 return;
99 var sourceFrame = this._currentSourceFrameCallback();
100 if (!sourceFrame)
101 return;
102 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesPa nel, this, sourceFrame, selection);
103 active.merge(entry);
104 },
105
106 /**
107 * @param {!WebInspector.TextRange} selection
108 */
109 _pushActiveState: function(selection)
110 {
111 var sourceFrame = this._currentSourceFrameCallback();
112 if (!sourceFrame)
113 return;
114 var entry = new WebInspector.EditingLocationHistoryEntry(this._sourcesPa nel, this, sourceFrame, selection);
115 this._historyManager.push(entry);
116 },
117
118 /**
119 * @param {!WebInspector.UISourceCode} uiSourceCode
120 */
121 removeHistoryForSourceCode: function(uiSourceCode)
122 {
123 function filterOut(entry)
124 {
125 return entry._projectId === uiSourceCode.project().id() && entry._pa th === uiSourceCode.path();
126 }
127
128 this._historyManager.filterOut(filterOut);
129 },
130 }
131
132
133 /**
134 * @constructor
135 * @implements {WebInspector.HistoryEntry}
136 * @param {!WebInspector.SourcesPanel} sourcesPanel
137 * @param {!WebInspector.EditingLocationHistoryManager} editingLocationManager
138 * @param {!WebInspector.SourceFrame} sourceFrame
139 * @param {!WebInspector.TextRange} selection
140 */
141 WebInspector.EditingLocationHistoryEntry = function(sourcesPanel, editingLocatio nManager, sourceFrame, selection)
142 {
143 this._sourcesPanel = sourcesPanel;
144 this._editingLocationManager = editingLocationManager;
145 var uiSourceCode = sourceFrame.uiSourceCode();
146 this._projectId = uiSourceCode.project().id();
147 this._path = uiSourceCode.path();
148
149 var position = this._positionFromSelection(selection);
150 this._positionHandle = sourceFrame.textEditor.textEditorPositionHandle(posit ion.lineNumber, position.columnNumber);
151 }
152
153 WebInspector.EditingLocationHistoryEntry.prototype = {
154 /**
155 * @param {!WebInspector.HistoryEntry} entry
156 */
157 merge: function(entry)
158 {
159 if (this._projectId !== entry._projectId || this._path !== entry._path)
160 return;
161 this._positionHandle = entry._positionHandle;
162 },
163
164 /**
165 * @param {!WebInspector.TextRange} selection
166 * @return {!{lineNumber: number, columnNumber: number}}
167 */
168 _positionFromSelection: function(selection)
169 {
170 return {
171 lineNumber: selection.endLine,
172 columnNumber: selection.endColumn
173 };
174 },
175
176 /**
177 * @return {boolean}
178 */
179 valid: function()
180 {
181 var position = this._positionHandle.resolve();
182 var uiSourceCode = WebInspector.workspace.project(this._projectId).uiSou rceCode(this._path);
183 return !!(position && uiSourceCode);
184 },
185
186 reveal: function()
187 {
188 var position = this._positionHandle.resolve();
189 var uiSourceCode = WebInspector.workspace.project(this._projectId).uiSou rceCode(this._path);
190 if (!position || !uiSourceCode)
191 return;
192
193 this._editingLocationManager.updateCurrentState();
194 this._sourcesPanel.showUISourceCode(uiSourceCode, position.lineNumber, p osition.columnNumber);
195 }
196 };
OLDNEW
« no previous file with comments | « Source/devtools/front_end/CodeMirrorTextEditor.js ('k') | Source/devtools/front_end/SimpleHistoryManager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698