Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 473787 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.editor/web/orion/editor/contentAssist.js (-21 / +55 lines)
Lines 348-377 define("orion/editor/contentAssist", [ //$NON-NLS-0$ Link Here
348
			var indentation = line.substring(0, index);
348
			var indentation = line.substring(0, index);
349
			var options = textView.getOptions("tabSize", "expandTab"); //$NON-NLS-1$ //$NON-NLS-0$
349
			var options = textView.getOptions("tabSize", "expandTab"); //$NON-NLS-1$ //$NON-NLS-0$
350
			var tab = options.expandTab ? new Array(options.tabSize + 1).join(" ") : "\t"; //$NON-NLS-1$ //$NON-NLS-0$
350
			var tab = options.expandTab ? new Array(options.tabSize + 1).join(" ") : "\t"; //$NON-NLS-1$ //$NON-NLS-0$
351
			var params = {
351
			var lineDelimiter = model.getLineDelimiter();
352
				line: line,
352
			var _self = this;
353
				offset: mapOffset,
354
				prefix: model.getText(this.getPrefixStart(model, mapOffset), mapOffset),
355
				selection: sel,
356
				delimiter: model.getLineDelimiter(),
357
				tab: tab,
358
				indentation: indentation
359
			};
360
			var self = this;
361
			var promises = providerInfoArray.map(function(providerInfo) {
353
			var promises = providerInfoArray.map(function(providerInfo) {
362
				var provider = providerInfo.provider;
354
				var provider = providerInfo.provider;
355
				var computePrefixFunc = provider.computePrefix;
356
				var ecProvider = _self.editorContextProvider, editorContext = ecProvider.getEditorContext();
357
				if (computePrefixFunc) {
358
					var result = computePrefixFunc.apply(provider, [editorContext, mapOffset]);
359
					return result.then(function(prefix) {
360
						var params = {
361
							line: line,
362
							offset: mapOffset,
363
							prefix: prefix,
364
							selection: sel,
365
							delimiter: lineDelimiter,
366
							tab: tab,
367
							indentation: indentation
368
						};
369
						var proposals;
370
						try {
371
							var func, promise;
372
							if ((func = provider.computeContentAssist)) {
373
								params = objects.mixin(params, ecProvider.getOptions());
374
								promise = func.apply(provider, [editorContext, params]);
375
							} else if ((func = provider.getProposals || provider.computeProposals)) {
376
								// old API
377
								promise = func.apply(provider, [model.getText(), mapOffset, params]);
378
							}
379
							proposals = _self.progress ? _self.progress.progress(promise, "Generating content assist proposal") : promise; //$NON-NLS-0$
380
						} catch (e) {
381
							return new Deferred().reject(e);
382
						}
383
						return Deferred.when(proposals);
384
					},
385
					function(err) {
386
						return new Deferred().reject(err);
387
					});
388
				}
389
				// no computePrefix function is defined for the provider. Use the default prefix
390
				var params = {
391
					line: line,
392
					offset: mapOffset,
393
					prefix: model.getText(_self.getPrefixStart(model, mapOffset), mapOffset),
394
					selection: sel,
395
					delimiter: lineDelimiter,
396
					tab: tab,
397
					indentation: indentation
398
				};
363
				var proposals;
399
				var proposals;
364
				try {
400
				try {
365
					var func, promise;
401
					var func, promise;
366
					if ((func = provider.computeContentAssist)) {
402
					if ((func = provider.computeContentAssist)) {
367
						var ecProvider = self.editorContextProvider, editorContext = ecProvider.getEditorContext();
403
						var ecProvider = _self.editorContextProvider, editorContext = ecProvider.getEditorContext();
368
						params = objects.mixin(params, ecProvider.getOptions());
404
						params = objects.mixin(params, ecProvider.getOptions());
369
						promise = func.apply(provider, [editorContext, params]);
405
						promise = func.apply(provider, [editorContext, params]);
370
					} else if ((func = provider.getProposals || provider.computeProposals)) {
406
					} else if ((func = provider.getProposals || provider.computeProposals)) {
371
						// old API
407
						// old API
372
						promise = func.apply(provider, [model.getText(), mapOffset, params]);
408
						promise = func.apply(provider, [model.getText(), mapOffset, params]);
373
					}
409
					}
374
					proposals = self.progress ? self.progress.progress(promise, "Generating content assist proposal") : promise; //$NON-NLS-0$
410
					proposals = _self.progress ? _self.progress.progress(promise, "Generating content assist proposal") : promise; //$NON-NLS-0$
375
				} catch (e) {
411
				} catch (e) {
376
					return new Deferred().reject(e);
412
					return new Deferred().reject(e);
377
				}
413
				}
Lines 383-389 define("orion/editor/contentAssist", [ //$NON-NLS-0$ Link Here
383
			
419
			
384
			if (this.pageMessage){
420
			if (this.pageMessage){
385
				allPromises = Deferred.when(allPromises, function(proposals){
421
				allPromises = Deferred.when(allPromises, function(proposals){
386
					self.pageMessage.close();					
422
					_self.pageMessage.close();
387
					var foundProposal = false;
423
					var foundProposal = false;
388
					if (proposals && proposals.length > 0){
424
					if (proposals && proposals.length > 0){
389
						for (var i=0; i<proposals.length; i++) {
425
						for (var i=0; i<proposals.length; i++) {
Lines 394-406 define("orion/editor/contentAssist", [ //$NON-NLS-0$ Link Here
394
						}
430
						}
395
					}
431
					}
396
					if (!foundProposal){
432
					if (!foundProposal){
397
						self.pageMessage.setErrorMessage(messages["noProposals"]);
433
						_self.pageMessage.setErrorMessage(messages["noProposals"]);
398
					}
434
					}
399
					return proposals;
435
					return proposals;
400
				});
436
				});
401
				self.pageMessage.showWhile(allPromises, messages["computingProposals"]);
437
				this.pageMessage.showWhile(allPromises, messages["computingProposals"]);
402
			}
438
			}
403
			
404
			return allPromises;
439
			return allPromises;
405
		},
440
		},
406
441
Lines 441-466 define("orion/editor/contentAssist", [ //$NON-NLS-0$ Link Here
441
									return false; // unknown format
476
									return false; // unknown format
442
								}
477
								}
443
			
478
			
444
								return (0 === proposalString.indexOf(prefixText + this._filterText));
479
								return 0 === proposalString.indexOf(prefixText + this._filterText);
445
								
480
								
446
							} else if (proposal.name || proposal.proposal) {
481
							} else if (proposal.name || proposal.proposal) {
447
								var activated = false;
482
								var activated = false;
448
								// try matching name
483
								// try matching name
449
								if (proposal.name) {
484
								if (proposal.name) {
450
									activated = (0 === proposal.name.indexOf(prefixText + this._filterText));	
485
									activated = 0 === proposal.name.indexOf(prefixText + this._filterText);	
451
								}
486
								}
452
								
487
								
453
								// try matching proposal text
488
								// try matching proposal text
454
								if (!activated && proposal.proposal) {
489
								if (!activated && proposal.proposal) {
455
									activated = (0 === proposal.proposal.indexOf(this._filterText));
490
									activated = 0 === proposal.proposal.indexOf(this._filterText);
456
								}
491
								}
457
								
492
								
458
								return activated;
493
								return activated;
459
							} else if (typeof proposal === "string") { //$NON-NLS-0$
494
							} else if (typeof proposal === "string") { //$NON-NLS-0$
460
								return 0 === proposal.indexOf(this._filterText);
495
								return 0 === proposal.indexOf(this._filterText);
461
							} else {
462
								return false;
463
							}
496
							}
497
							return false;
464
						}, this);
498
						}, this);
465
						
499
						
466
						if (includedProposals.length > 0) {
500
						if (includedProposals.length > 0) {
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/contentAssist/ternAssist.js (+24 lines)
Lines 184-189 define([ Link Here
184
	Objects.mixin(TernContentAssist.prototype, {
184
	Objects.mixin(TernContentAssist.prototype, {
185
185
186
		/**
186
		/**
187
		 * @private
188
		 */
189
		_getPrefixStart: function(text, offset) {
190
			var index = offset;
191
			while (index > 0) {
192
				var char = text.substring(index - 1, index);
193
				if (/[A-Za-z0-9_]/.test(char)) {
194
					index--;
195
				} else {
196
					break;
197
				}
198
			}
199
			return index;
200
		},
201
		/**
202
		 * @callback 
203
		 */
204
		computePrefix(editorContext, offset) {
205
			var that = this;
206
			return editorContext.getText().then(function (text) {
207
				return text.substring(that._getPrefixStart(text, offset), offset);
208
			});
209
		},
210
		/**
187
		 * Called by the framework to initialize this provider before any <tt>computeContentAssist</tt> calls.
211
		 * Called by the framework to initialize this provider before any <tt>computeContentAssist</tt> calls.
188
		 */
212
		 */
189
		initialize: function() {
213
		initialize: function() {
(-)a/bundles/org.eclipse.orion.client.webtools/web/js-tests/webtools/htmlContentAssistTests.js (-63 lines)
Lines 1788-1856 define([ Link Here
1788
    			assert(knownProp, "Could not find expected proposal role");
1788
    			assert(knownProp, "Could not find expected proposal role");
1789
    		});
1789
    		});
1790
    	});
1790
    	});
1791
    	it('Tags that support the attributes of many roles: details (13). Empty prefix. <details aria->', function() {
1792
    		var _o = setup({buffer: '<html><body><details aria-></details></body></html>'});
1793
    		return assist.computeContentAssist(_o.editorContext, {offset: 26, prefix: ''}).then(function(proposals) {
1794
    			var expectedCount = 17 + 13; // "ARIA title" + 16 aria-* globals + 13 role-specific aria-* attributes
1795
    			assert(proposals.length === expectedCount, "Incorrect number of proposals for details tag attributes. Proposal count: " + proposals.length + " Expected count: " + expectedCount);
1796
    			var knownProp;
1797
    			for (var i=0; i<proposals.length; i++) {
1798
    				if (proposals[i].name === "aria-checked"){
1799
    					knownProp = proposals[i];
1800
    				}
1801
    			}
1802
    			assert(knownProp, "Could not find expected proposal aria-checked");
1803
    			knownProp = null;
1804
    			for (i=0; i<proposals.length; i++) {
1805
    				if (proposals[i].name === "aria-expanded"){
1806
    					knownProp = proposals[i];
1807
    				}
1808
    			}
1809
    			assert(knownProp, "Could not find expected proposal aria-expanded");
1810
    			knownProp = null;
1811
    			for (i=0; i<proposals.length; i++) {
1812
    				if (proposals[i].name === "aria-activedescendant"){
1813
    					knownProp = proposals[i];
1814
    				}
1815
    			}
1816
    			assert(knownProp, "Could not find expected proposal aria-activedescendant");
1817
    			knownProp = null;
1818
    			for (i=0; i<proposals.length; i++) {
1819
    				if (proposals[i].name === "aria-multiselectable"){
1820
    					knownProp = proposals[i];
1821
    				}
1822
    			}
1823
    			assert(knownProp, "Could not find expected proposal aria-multiselectable");
1824
    			knownProp = null;
1825
    			for (i=0; i<proposals.length; i++) {
1826
    				if (proposals[i].name === "aria-pressed"){
1827
    					knownProp = proposals[i];
1828
    				}
1829
    			}
1830
    			assert(knownProp, "Could not find expected proposal aria-pressed");
1831
    			knownProp = null;
1832
    			for (i=0; i<proposals.length; i++) {
1833
    				if (proposals[i].name === "aria-required"){
1834
    					knownProp = proposals[i];
1835
    				}
1836
    			}
1837
    			assert(knownProp, "Could not find expected proposal aria-required");
1838
    			knownProp = null;
1839
    			for (i=0; i<proposals.length; i++) {
1840
    				if (proposals[i].name === "aria-posinset"){
1841
    					knownProp = proposals[i];
1842
    				}
1843
    			}
1844
    			assert(knownProp, "Could not find expected proposal aria-posinset");
1845
    			knownProp = null;
1846
    			for (i=0; i<proposals.length; i++) {
1847
    				if (proposals[i].name === "aria-setsize"){
1848
    					knownProp = proposals[i];
1849
    				}
1850
    			}
1851
    			assert(knownProp, "Could not find expected proposal aria-setsize");
1852
    		});
1853
    	});
1854
    	it('Tags that support the attributes of many roles: details (13). Prefix ar. <details ar>', function() {
1791
    	it('Tags that support the attributes of many roles: details (13). Prefix ar. <details ar>', function() {
1855
    		var _o = setup({buffer: '<html><body><details ar></details></body></html>'});
1792
    		var _o = setup({buffer: '<html><body><details ar></details></body></html>'});
1856
    		return assist.computeContentAssist(_o.editorContext, {offset: 21, prefix: 'ar'}).then(function(proposals) {
1793
    		return assist.computeContentAssist(_o.editorContext, {offset: 21, prefix: 'ar'}).then(function(proposals) {
(-)a/bundles/org.eclipse.orion.client.webtools/web/webtools/htmlContentAssist.js (-17 / +25 lines)
Lines 153-158 define([ Link Here
153
	
153
	
154
	Objects.mixin(HTMLContentAssistProvider.prototype, {
154
	Objects.mixin(HTMLContentAssistProvider.prototype, {
155
		/**
155
		/**
156
		 * @private
157
		 */
158
		_getPrefixStart: function(text, offset) {
159
			var index = offset;
160
			while (index > 0) {
161
				var char = text.substring(index - 1, index);
162
				if (/[A-Za-z0-9_-]/.test(char)) {
163
					index--;
164
				} else {
165
					break;
166
				}
167
			}
168
			return index;
169
		},
170
		/**
171
		 * @callback 
172
		 */
173
		computePrefix(editorContext, offset) {
174
			var that = this;
175
			return editorContext.getText().then(function (text) {
176
				return text.substring(that._getPrefixStart(text, offset), offset);
177
			});
178
		},
179
		/**
156
		 * @callback 
180
		 * @callback 
157
		 */
181
		 */
158
		computeContentAssist: function(editorContext, params) {
182
		computeContentAssist: function(editorContext, params) {
Lines 468-490 define([ Link Here
468
			var index = params.offset - prefix.length - 1;
492
			var index = params.offset - prefix.length - 1;
469
			if (index > 0 && index < source.length) {
493
			if (index > 0 && index < source.length) {
470
				var precedingChar = source.charAt(index);
494
				var precedingChar = source.charAt(index);
471
				if (precedingChar === '-') {
495
				if (precedingChar === '=' && prefix.length === 0 && (index - 1) > 0) {
472
					index--;
473
					if (index !== 0) {
474
						// rebuild a prefix based on what characters (letter only) are before the '-'
475
						precedingChar = source.charAt(index);
476
						var currentPrefix = "-" + prefix;
477
						loop: while (index > 0 && /[A-Za-z0-9_-]/.test(precedingChar)) {
478
							index--;
479
							currentPrefix = precedingChar + currentPrefix;
480
							if (index === 0) {
481
								break loop;
482
							}
483
							precedingChar = source.charAt(index);
484
						}
485
						params.prefix = currentPrefix;
486
					}
487
				} else if (precedingChar === '=' && prefix.length === 0 && (index - 1) > 0) {
488
					precedingChar = source.charAt(index - 1);
496
					precedingChar = source.charAt(index - 1);
489
					if (/[A-Za-z0-9_]/.test(precedingChar)) {
497
					if (/[A-Za-z0-9_]/.test(precedingChar)) {
490
						proposals.push(this.makeComputedProposal("\"\"",  Messages['addQuotesToAttributes'], " - \"\"", null, prefix)); //$NON-NLS-1$ //$NON-NLS-2$
498
						proposals.push(this.makeComputedProposal("\"\"",  Messages['addQuotesToAttributes'], " - \"\"", null, prefix)); //$NON-NLS-1$ //$NON-NLS-2$

Return to bug 473787