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

Side by Side Diff: Source/devtools/front_end/ui/InplaceEditor.js

Issue 1200833006: DevTools: [Elements] F2 should commit changes in edit-as-html (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments Created 5 years, 6 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
« no previous file with comments | « Source/devtools/front_end/elements/ElementsTreeElement.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 */ 7 */
8 WebInspector.InplaceEditor = function() 8 WebInspector.InplaceEditor = function()
9 { 9 {
10 } 10 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 /** @this {Element} */ 164 /** @this {Element} */
165 function editingCommitted() 165 function editingCommitted()
166 { 166 {
167 cleanUpAfterEditing(); 167 cleanUpAfterEditing();
168 168
169 committedCallback(this, self.editorContent(editingContext), editingC ontext.oldText, context, moveDirection); 169 committedCallback(this, self.editorContent(editingContext), editingC ontext.oldText, context, moveDirection);
170 } 170 }
171 171
172 /**
173 * @param {!Event} event
174 * @return {string}
175 */
172 function defaultFinishHandler(event) 176 function defaultFinishHandler(event)
173 { 177 {
174 var isMetaOrCtrl = WebInspector.isMac() ? 178 var isMetaOrCtrl = WebInspector.isMac() ?
175 event.metaKey && !event.shiftKey && !event.ctrlKey && !event.alt Key : 179 event.metaKey && !event.shiftKey && !event.ctrlKey && !event.alt Key :
176 event.ctrlKey && !event.shiftKey && !event.metaKey && !event.alt Key; 180 event.ctrlKey && !event.shiftKey && !event.metaKey && !event.alt Key;
177 if (isEnterKey(event) && (event.isMetaOrCtrlForTest || !isMultiline || isMetaOrCtrl)) 181 if (isEnterKey(event) && (event.isMetaOrCtrlForTest || !isMultiline || isMetaOrCtrl))
178 return "commit"; 182 return "commit";
179 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.co de || event.keyIdentifier === "U+001B") 183 else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.co de || event.keyIdentifier === "U+001B")
180 return "cancel"; 184 return "cancel";
181 else if (!isMultiline && event.keyIdentifier === "U+0009") // Tab ke y 185 else if (!isMultiline && event.keyIdentifier === "U+0009") // Tab ke y
182 return "move-" + (event.shiftKey ? "backward" : "forward"); 186 return "move-" + (event.shiftKey ? "backward" : "forward");
187 return "";
183 } 188 }
184 189
185 function handleEditingResult(result, event) 190 function handleEditingResult(result, event)
186 { 191 {
187 if (result === "commit") { 192 if (result === "commit") {
188 editingCommitted.call(element); 193 editingCommitted.call(element);
189 event.consume(true); 194 event.consume(true);
190 } else if (result === "cancel") { 195 } else if (result === "cancel") {
191 editingCancelled.call(element); 196 editingCancelled.call(element);
192 event.consume(true); 197 event.consume(true);
193 } else if (result && result.startsWith("move-")) { 198 } else if (result && result.startsWith("move-")) {
194 moveDirection = result.substring(5); 199 moveDirection = result.substring(5);
195 if (event.keyIdentifier !== "U+0009") 200 if (event.keyIdentifier !== "U+0009")
196 blurEventListener(); 201 blurEventListener();
197 } 202 }
198 } 203 }
199 204
205 /**
206 * @param {!Event} event
207 */
200 function pasteEventListener(event) 208 function pasteEventListener(event)
201 { 209 {
202 var result = pasteCallback(event); 210 var result = pasteCallback(event);
203 handleEditingResult(result, event); 211 handleEditingResult(result, event);
204 } 212 }
205 213
214 /**
215 * @param {!Event} event
216 */
206 function keyDownEventListener(event) 217 function keyDownEventListener(event)
207 { 218 {
208 var handler = config.customFinishHandler || defaultFinishHandler; 219 var result = defaultFinishHandler(event);
209 var result = handler(event); 220 if (!result && config.postKeydownFinishHandler)
221 result = config.postKeydownFinishHandler(event);
210 handleEditingResult(result, event); 222 handleEditingResult(result, event);
211 } 223 }
212 224
213 element.addEventListener("blur", blurEventListener, isMultiline); 225 element.addEventListener("blur", blurEventListener, isMultiline);
214 element.addEventListener("keydown", keyDownEventListener, true); 226 element.addEventListener("keydown", keyDownEventListener, true);
215 if (pasteCallback) 227 if (pasteCallback)
216 element.addEventListener("paste", pasteEventListener, true); 228 element.addEventListener("paste", pasteEventListener, true);
217 229
218 var handle = { 230 var handle = {
219 cancel: editingCancelled.bind(element), 231 cancel: editingCancelled.bind(element),
(...skipping 14 matching lines...) Expand all
234 * @template T 246 * @template T
235 */ 247 */
236 WebInspector.InplaceEditor.Config = function(commitHandler, cancelHandler, conte xt, blurHandler) 248 WebInspector.InplaceEditor.Config = function(commitHandler, cancelHandler, conte xt, blurHandler)
237 { 249 {
238 this.commitHandler = commitHandler; 250 this.commitHandler = commitHandler;
239 this.cancelHandler = cancelHandler; 251 this.cancelHandler = cancelHandler;
240 this.context = context; 252 this.context = context;
241 this.blurHandler = blurHandler; 253 this.blurHandler = blurHandler;
242 254
243 /** 255 /**
244 * Handles the "paste" event, return values are the same as those for custom FinishHandler 256 * @type {function(!Event):string|undefined}
245 * @type {function(!Element)|undefined}
246 */ 257 */
247 this.pasteHandler; 258 this.pasteHandler;
248 259
249 /** 260 /**
250 * Whether the edited element is multiline
251 * @type {boolean|undefined} 261 * @type {boolean|undefined}
252 */ 262 */
253 this.multiline; 263 this.multiline;
254 264
255 /** 265 /**
256 * Custom finish handler for the editing session (invoked on keydown) 266 * @type {function(!Event):string|undefined}
257 * @type {function(!Element,*)|undefined}
258 */ 267 */
259 this.customFinishHandler; 268 this.postKeydownFinishHandler;
260 } 269 }
261 270
262 WebInspector.InplaceEditor.Config.prototype = { 271 WebInspector.InplaceEditor.Config.prototype = {
263 setPasteHandler: function(pasteHandler) 272 setPasteHandler: function(pasteHandler)
264 { 273 {
265 this.pasteHandler = pasteHandler; 274 this.pasteHandler = pasteHandler;
266 }, 275 },
267 276
268 /** 277 /**
269 * @param {string} initialValue 278 * @param {string} initialValue
270 * @param {!Object} mode 279 * @param {!Object} mode
271 * @param {string} theme 280 * @param {string} theme
272 * @param {boolean=} lineWrapping 281 * @param {boolean=} lineWrapping
273 * @param {boolean=} smartIndent 282 * @param {boolean=} smartIndent
274 */ 283 */
275 setMultilineOptions: function(initialValue, mode, theme, lineWrapping, smart Indent) 284 setMultilineOptions: function(initialValue, mode, theme, lineWrapping, smart Indent)
276 { 285 {
277 this.multiline = true; 286 this.multiline = true;
278 this.initialValue = initialValue; 287 this.initialValue = initialValue;
279 this.mode = mode; 288 this.mode = mode;
280 this.theme = theme; 289 this.theme = theme;
281 this.lineWrapping = lineWrapping; 290 this.lineWrapping = lineWrapping;
282 this.smartIndent = smartIndent; 291 this.smartIndent = smartIndent;
283 }, 292 },
284 293
285 setCustomFinishHandler: function(customFinishHandler) 294 /**
295 * @param {function(!Event):string} postKeydownFinishHandler
296 */
297 setPostKeydownFinishHandler: function(postKeydownFinishHandler)
286 { 298 {
287 this.customFinishHandler = customFinishHandler; 299 this.postKeydownFinishHandler = postKeydownFinishHandler;
288 } 300 }
289 } 301 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/elements/ElementsTreeElement.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698