OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 2242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 return; | 2253 return; |
2254 var name = data.substring(0, colonIdx).trim(); | 2254 var name = data.substring(0, colonIdx).trim(); |
2255 var value = data.substring(colonIdx + 1).trim(); | 2255 var value = data.substring(colonIdx + 1).trim(); |
2256 | 2256 |
2257 event.preventDefault(); | 2257 event.preventDefault(); |
2258 | 2258 |
2259 if (!("originalName" in context)) { | 2259 if (!("originalName" in context)) { |
2260 context.originalName = this.nameElement.textContent; | 2260 context.originalName = this.nameElement.textContent; |
2261 context.originalValue = this.valueElement.textContent; | 2261 context.originalValue = this.valueElement.textContent; |
2262 } | 2262 } |
| 2263 this.property.name = name; |
| 2264 this.property.value = value; |
2263 this.nameElement.textContent = name; | 2265 this.nameElement.textContent = name; |
2264 this.valueElement.textContent = value; | 2266 this.valueElement.textContent = value; |
2265 this.nameElement.normalize(); | 2267 this.nameElement.normalize(); |
2266 this.valueElement.normalize(); | 2268 this.valueElement.normalize(); |
2267 | 2269 |
2268 this.editingCommitted(null, event.target.textContent, context.previo
usContent, context, "forward"); | 2270 this.editingCommitted(null, event.target.textContent, context.previo
usContent, context, "forward"); |
2269 } | 2271 } |
2270 | 2272 |
2271 function blurListener(context, event) | 2273 function blurListener(context, event) |
2272 { | 2274 { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2437 }, | 2439 }, |
2438 | 2440 |
2439 editingCommitted: function(element, userInput, previousContent, context, mov
eDirection) | 2441 editingCommitted: function(element, userInput, previousContent, context, mov
eDirection) |
2440 { | 2442 { |
2441 this._removePrompt(); | 2443 this._removePrompt(); |
2442 this.editingEnded(context); | 2444 this.editingEnded(context); |
2443 var isEditingName = context.isEditingName; | 2445 var isEditingName = context.isEditingName; |
2444 | 2446 |
2445 // Determine where to move to before making changes | 2447 // Determine where to move to before making changes |
2446 var createNewProperty, moveToPropertyName, moveToSelector; | 2448 var createNewProperty, moveToPropertyName, moveToSelector; |
| 2449 var isDataPasted = "originalName" in context; |
| 2450 var isDirtyViaPaste = isDataPasted && (this.nameElement.textContent !==
context.originalName || this.valueElement.textContent !== context.originalValue)
; |
| 2451 var isPropertySplitPaste = isDataPasted && isEditingName && this.valueEl
ement.textContent !== context.originalValue; |
2447 var moveTo = this; | 2452 var moveTo = this; |
2448 var moveToOther = (isEditingName ^ (moveDirection === "forward")); | 2453 var moveToOther = (isEditingName ^ (moveDirection === "forward")); |
2449 var abandonNewProperty = this._newProperty && !userInput && (moveToOther
|| isEditingName); | 2454 var abandonNewProperty = this._newProperty && !userInput && (moveToOther
|| isEditingName); |
2450 if (moveDirection === "forward" && !isEditingName || moveDirection === "
backward" && isEditingName) { | 2455 if (moveDirection === "forward" && (!isEditingName || isPropertySplitPas
te) || moveDirection === "backward" && isEditingName) { |
2451 moveTo = moveTo._findSibling(moveDirection); | 2456 moveTo = moveTo._findSibling(moveDirection); |
2452 if (moveTo) | 2457 if (moveTo) |
2453 moveToPropertyName = moveTo.name; | 2458 moveToPropertyName = moveTo.name; |
2454 else if (moveDirection === "forward" && (!this._newProperty || userI
nput)) | 2459 else if (moveDirection === "forward" && (!this._newProperty || userI
nput)) |
2455 createNewProperty = true; | 2460 createNewProperty = true; |
2456 else if (moveDirection === "backward") | 2461 else if (moveDirection === "backward") |
2457 moveToSelector = true; | 2462 moveToSelector = true; |
2458 } | 2463 } |
2459 | 2464 |
2460 // Make the Changes and trigger the moveToNextCallback after updating. | 2465 // Make the Changes and trigger the moveToNextCallback after updating. |
2461 var moveToIndex = moveTo && this.treeOutline ? this.treeOutline.children
.indexOf(moveTo) : -1; | 2466 var moveToIndex = moveTo && this.treeOutline ? this.treeOutline.children
.indexOf(moveTo) : -1; |
2462 var blankInput = /^\s*$/.test(userInput); | 2467 var blankInput = /^\s*$/.test(userInput); |
2463 var isDataPasted = "originalName" in context; | 2468 var shouldCommitNewProperty = this._newProperty && (isPropertySplitPaste
|| moveToOther || (!moveDirection && !isEditingName) || (isEditingName && blank
Input)); |
2464 var isDirtyViaPaste = isDataPasted && (this.nameElement.textContent !==
context.originalName || this.valueElement.textContent !== context.originalValue)
; | |
2465 var shouldCommitNewProperty = this._newProperty && (moveToOther || (!mov
eDirection && !isEditingName) || (isEditingName && blankInput)); | |
2466 var section = this.section(); | 2469 var section = this.section(); |
2467 if (((userInput !== previousContent || isDirtyViaPaste) && !this._newPro
perty) || shouldCommitNewProperty) { | 2470 if (((userInput !== previousContent || isDirtyViaPaste) && !this._newPro
perty) || shouldCommitNewProperty) { |
2468 section._afterUpdate = moveToNextCallback.bind(this, this._newProper
ty, !blankInput, section); | 2471 section._afterUpdate = moveToNextCallback.bind(this, this._newProper
ty, !blankInput, section); |
2469 var propertyText; | 2472 var propertyText; |
2470 if (blankInput || (this._newProperty && /^\s*$/.test(this.valueEleme
nt.textContent))) | 2473 if (blankInput || (this._newProperty && /^\s*$/.test(this.valueEleme
nt.textContent))) |
2471 propertyText = ""; | 2474 propertyText = ""; |
2472 else { | 2475 else { |
2473 if (isEditingName) | 2476 if (isEditingName) |
2474 propertyText = userInput + ": " + this.valueElement.textCont
ent; | 2477 propertyText = userInput + ": " + this.valueElement.textCont
ent; |
2475 else | 2478 else |
(...skipping 22 matching lines...) Expand all Loading... |
2498 // Recalculate the new treeElement for the same property we were goi
ng to edit next. | 2501 // Recalculate the new treeElement for the same property we were goi
ng to edit next. |
2499 if (moveTo && !moveTo.parent) { | 2502 if (moveTo && !moveTo.parent) { |
2500 var propertyElements = section.propertiesTreeOutline.children; | 2503 var propertyElements = section.propertiesTreeOutline.children; |
2501 if (moveDirection === "forward" && blankInput && !isEditingName) | 2504 if (moveDirection === "forward" && blankInput && !isEditingName) |
2502 --moveToIndex; | 2505 --moveToIndex; |
2503 if (moveToIndex >= propertyElements.length && !this._newProperty
) | 2506 if (moveToIndex >= propertyElements.length && !this._newProperty
) |
2504 createNewProperty = true; | 2507 createNewProperty = true; |
2505 else { | 2508 else { |
2506 var treeElement = moveToIndex >= 0 ? propertyElements[moveTo
Index] : null; | 2509 var treeElement = moveToIndex >= 0 ? propertyElements[moveTo
Index] : null; |
2507 if (treeElement) { | 2510 if (treeElement) { |
2508 var elementToEdit = !isEditingName ? treeElement.nameEle
ment : treeElement.valueElement; | 2511 var elementToEdit = !isEditingName || isPropertySplitPas
te ? treeElement.nameElement : treeElement.valueElement; |
2509 if (alreadyNew && blankInput) | 2512 if (alreadyNew && blankInput) |
2510 elementToEdit = moveDirection === "forward" ? treeEl
ement.nameElement : treeElement.valueElement; | 2513 elementToEdit = moveDirection === "forward" ? treeEl
ement.nameElement : treeElement.valueElement; |
2511 treeElement.startEditing(elementToEdit); | 2514 treeElement.startEditing(elementToEdit); |
2512 return; | 2515 return; |
2513 } else if (!alreadyNew) | 2516 } else if (!alreadyNew) |
2514 moveToSelector = true; | 2517 moveToSelector = true; |
2515 } | 2518 } |
2516 } | 2519 } |
2517 | 2520 |
2518 // Create a new attribute in this section (or move to next editable
selector if possible). | 2521 // Create a new attribute in this section (or move to next editable
selector if possible). |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2730 if (!prefix && !force) | 2733 if (!prefix && !force) |
2731 return; | 2734 return; |
2732 | 2735 |
2733 var results = this._cssCompletions.startsWith(prefix); | 2736 var results = this._cssCompletions.startsWith(prefix); |
2734 var selectedIndex = this._cssCompletions.mostUsedOf(results); | 2737 var selectedIndex = this._cssCompletions.mostUsedOf(results); |
2735 completionsReadyCallback(results, selectedIndex); | 2738 completionsReadyCallback(results, selectedIndex); |
2736 }, | 2739 }, |
2737 | 2740 |
2738 __proto__: WebInspector.TextPrompt.prototype | 2741 __proto__: WebInspector.TextPrompt.prototype |
2739 } | 2742 } |
OLD | NEW |