| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 case "Up": | 59 case "Up": |
| 60 this._upKeyPressed(event); | 60 this._upKeyPressed(event); |
| 61 break; | 61 break; |
| 62 case "Down": | 62 case "Down": |
| 63 this._downKeyPressed(event); | 63 this._downKeyPressed(event); |
| 64 break; | 64 break; |
| 65 case "U+0009": // Tab | 65 case "U+0009": // Tab |
| 66 this._tabKeyPressed(event); | 66 this._tabKeyPressed(event); |
| 67 break; | 67 break; |
| 68 case "Right": | 68 case "Right": |
| 69 case "End": |
| 69 if (!this.acceptAutoComplete()) | 70 if (!this.acceptAutoComplete()) |
| 70 this.autoCompleteSoon(); | 71 this.autoCompleteSoon(); |
| 71 break; | 72 break; |
| 72 default: | 73 default: |
| 73 this.clearAutoComplete(); | 74 this.clearAutoComplete(); |
| 74 this.autoCompleteSoon(); | 75 this.autoCompleteSoon(); |
| 75 break; | 76 break; |
| 76 } | 77 } |
| 77 }, | 78 }, |
| 78 | 79 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 autoCompleteSoon: function() | 135 autoCompleteSoon: function() |
| 135 { | 136 { |
| 136 if (!("_completeTimeout" in this)) | 137 if (!("_completeTimeout" in this)) |
| 137 this._completeTimeout = setTimeout(this.complete.bind(this, true), 2
50); | 138 this._completeTimeout = setTimeout(this.complete.bind(this, true), 2
50); |
| 138 }, | 139 }, |
| 139 | 140 |
| 140 complete: function(auto) | 141 complete: function(auto) |
| 141 { | 142 { |
| 142 this.clearAutoComplete(true); | 143 this.clearAutoComplete(true); |
| 143 | |
| 144 var selection = window.getSelection(); | 144 var selection = window.getSelection(); |
| 145 if (!selection.rangeCount) | 145 if (!selection.rangeCount) |
| 146 return; | 146 return; |
| 147 | 147 |
| 148 var selectionRange = selection.getRangeAt(0); | 148 var selectionRange = selection.getRangeAt(0); |
| 149 if (!selectionRange.commonAncestorContainer.isDescendant(this.element)) | 149 if (!selectionRange.commonAncestorContainer.isDescendant(this.element)) |
| 150 return; | 150 return; |
| 151 if (auto && !this.isCaretAtEndOfPrompt()) | 151 if (auto && !this.isCaretAtEndOfPrompt()) |
| 152 return; | 152 return; |
| 153 var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectio
nRange.startOffset, this.completionStopCharacters, this.element, "backward"); |
| 154 this.completions(wordPrefixRange, auto, this._completionsReady.bind(this
, selection, auto, wordPrefixRange)); |
| 155 }, |
| 153 | 156 |
| 154 var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectio
nRange.startOffset, this.completionStopCharacters, this.element, "backward"); | 157 _completionsReady: function(selection, auto, originalWordPrefixRange, comple
tions) |
| 155 var completions = this.completions(wordPrefixRange, auto); | 158 { |
| 156 | |
| 157 if (!completions || !completions.length) | 159 if (!completions || !completions.length) |
| 158 return; | 160 return; |
| 159 | 161 |
| 162 var selectionRange = selection.getRangeAt(0); |
| 163 |
| 160 var fullWordRange = document.createRange(); | 164 var fullWordRange = document.createRange(); |
| 161 fullWordRange.setStart(wordPrefixRange.startContainer, wordPrefixRange.s
tartOffset); | 165 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW
ordPrefixRange.startOffset); |
| 162 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs
et); | 166 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs
et); |
| 163 | 167 |
| 168 if (originalWordPrefixRange.toString() + selectionRange.toString() != fu
llWordRange.toString()) |
| 169 return; |
| 170 |
| 164 if (completions.length === 1 || selection.isCollapsed || auto) { | 171 if (completions.length === 1 || selection.isCollapsed || auto) { |
| 165 var completionText = completions[0]; | 172 var completionText = completions[0]; |
| 166 } else { | 173 } else { |
| 167 var currentText = fullWordRange.toString(); | 174 var currentText = fullWordRange.toString(); |
| 168 | 175 |
| 169 var foundIndex = null; | 176 var foundIndex = null; |
| 170 for (var i = 0; i < completions.length; ++i) { | 177 for (var i = 0; i < completions.length; ++i) { |
| 171 if (completions[i] === currentText) | 178 if (completions[i] === currentText) |
| 172 foundIndex = i; | 179 foundIndex = i; |
| 173 } | 180 } |
| 174 | 181 |
| 175 if (foundIndex === null || (foundIndex + 1) >= completions.length) | 182 if (foundIndex === null || (foundIndex + 1) >= completions.length) |
| 176 var completionText = completions[0]; | 183 var completionText = completions[0]; |
| 177 else | 184 else |
| 178 var completionText = completions[foundIndex + 1]; | 185 var completionText = completions[foundIndex + 1]; |
| 179 } | 186 } |
| 180 | 187 |
| 181 var wordPrefixLength = wordPrefixRange.toString().length; | 188 var wordPrefixLength = originalWordPrefixRange.toString().length; |
| 182 | 189 |
| 183 this._userEnteredRange = fullWordRange; | 190 this._userEnteredRange = fullWordRange; |
| 184 this._userEnteredText = fullWordRange.toString(); | 191 this._userEnteredText = fullWordRange.toString(); |
| 185 | 192 |
| 186 fullWordRange.deleteContents(); | 193 fullWordRange.deleteContents(); |
| 187 | 194 |
| 188 var finalSelectionRange = document.createRange(); | 195 var finalSelectionRange = document.createRange(); |
| 189 | 196 |
| 190 if (auto) { | 197 if (auto) { |
| 191 var prefixText = completionText.substring(0, wordPrefixLength); | 198 var prefixText = completionText.substring(0, wordPrefixLength); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 310 |
| 304 if (this.historyOffset == 0) { | 311 if (this.historyOffset == 0) { |
| 305 this.text = this.tempSavedCommand; | 312 this.text = this.tempSavedCommand; |
| 306 delete this.tempSavedCommand; | 313 delete this.tempSavedCommand; |
| 307 return; | 314 return; |
| 308 } | 315 } |
| 309 | 316 |
| 310 this.text = this.history[this.history.length - this.historyOffset]; | 317 this.text = this.history[this.history.length - this.historyOffset]; |
| 311 } | 318 } |
| 312 } | 319 } |
| OLD | NEW |