From 3ed10ffea009315da6de1ce3b7bdd707efec7305 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Sat, 12 Apr 2014 08:17:36 -0700 Subject: [PATCH 1/9] insert folders; replace files --- src/extensions/default/UrlCodeHints/main.js | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/main.js b/src/extensions/default/UrlCodeHints/main.js index eaf8400f5eb..35b51088f84 100644 --- a/src/extensions/default/UrlCodeHints/main.js +++ b/src/extensions/default/UrlCodeHints/main.js @@ -656,8 +656,10 @@ define(function (require, exports, module) { hasClosingParen = (closingPos.index !== -1); } - // Adjust insert char positions to replace existing value, if there is a closing paren - if (closingPos.index !== -1) { + // Insert folder names, but replace file names, so if a file is selected + // (i.e. closeOnSelect === true), then adjust insert char positions to + // replace existing value, if there is a closing paren + if (this.closeOnSelect && closingPos.index !== -1) { end.ch += this.getCharOffset(this.info.values, this.info, closingPos); } if (this.info.filter.length > 0) { @@ -721,15 +723,16 @@ define(function (require, exports, module) { charCount = 0, replaceExistingOne = tagInfo.attr.valueAssigned, endQuote = "", - shouldReplace = true; + shouldReplace = false; if (tokenType === HTMLUtils.ATTR_VALUE) { - charCount = tagInfo.attr.value.length; - // Special handling for URL hinting -- if the completion is a file name // and not a folder, then close the code hint list. if (!this.closeOnSelect && completion.match(/\/$/) === null) { this.closeOnSelect = true; + + // Insert folder names, but replace file names + shouldReplace = true; } if (!tagInfo.attr.hasEndQuote) { @@ -742,19 +745,16 @@ define(function (require, exports, module) { } else if (completion === tagInfo.attr.value) { shouldReplace = false; } + + // Replace entire value, otherwise just queryDir (to insert new selection) + charCount = (shouldReplace) ? tagInfo.attr.value.length : this.cachedHints.queryDir.length; } end.line = start.line = cursor.line; start.ch = cursor.ch - tagInfo.position.offset; end.ch = start.ch + charCount; - if (shouldReplace) { - if (start.ch !== end.ch) { - this.editor.document.replaceRange(completion, start, end); - } else { - this.editor.document.replaceRange(completion, start); - } - } + this.editor.document.replaceRange(completion, start, end); if (!this.closeOnSelect) { // If we append the missing quote, then we need to adjust the cursor postion From b92e89efa9c30940f495438d362bef2a4641721c Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Sat, 12 Apr 2014 09:37:30 -0700 Subject: [PATCH 2/9] add units tests --- .../default/UrlCodeHints/testfiles/test.html | 2 + .../default/UrlCodeHints/unittests.js | 190 ++++++++++++++++-- 2 files changed, 172 insertions(+), 20 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/testfiles/test.html b/src/extensions/default/UrlCodeHints/testfiles/test.html index 0272bd904f6..8388fb7f622 100644 --- a/src/extensions/default/UrlCodeHints/testfiles/test.html +++ b/src/extensions/default/UrlCodeHints/testfiles/test.html @@ -7,6 +7,7 @@ background-image: url(); border-image: url(''); list-style-image: url(""); + background-image: url(dummy.jpg); background-image: } @@ -19,5 +20,6 @@ Results Page relative: up 1 folder Site-root relative: root folder + Results diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index 148a45ed81c..1f1908203f8 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -145,7 +145,7 @@ define(function (require, exports, module) { it("should hint for href attribute", function () { runs(function () { - testEditor.setCursorPos({ line: 12, ch: 12 }); + testEditor.setCursorPos({ line: 13, ch: 12 }); // Must reset hintsObj before every call to expectAsyncHints() hintsObj = null; @@ -159,7 +159,7 @@ define(function (require, exports, module) { it("should hint for src attribute", function () { runs(function () { - testEditor.setCursorPos({ line: 13, ch: 13 }); + testEditor.setCursorPos({ line: 14, ch: 13 }); hintsObj = null; expectAsyncHints(UrlCodeHints.hintProvider); }); @@ -171,21 +171,21 @@ define(function (require, exports, module) { it("should not hint for type attribute", function () { runs(function () { - testEditor.setCursorPos({ line: 13, ch: 21 }); + testEditor.setCursorPos({ line: 14, ch: 21 }); expectNoHints(UrlCodeHints.hintProvider); }); }); it("should not hint in query part of url", function () { runs(function () { - testEditor.setCursorPos({ line: 18, ch: 31 }); + testEditor.setCursorPos({ line: 19, ch: 31 }); expectNoHints(UrlCodeHints.hintProvider); }); }); it("should hint up 1 folder for '../'", function () { runs(function () { - testEditor.setCursorPos({ line: 19, ch: 14 }); + testEditor.setCursorPos({ line: 20, ch: 14 }); hintsObj = null; expectAsyncHints(UrlCodeHints.hintProvider); }); @@ -264,7 +264,7 @@ define(function (require, exports, module) { it("should not hint for background-image outside of url()", function () { runs(function () { - testEditor.setCursorPos({ line: 9, ch: 20 }); + testEditor.setCursorPos({ line: 10, ch: 20 }); expectNoHints(UrlCodeHints.hintProvider); }); }); @@ -339,7 +339,7 @@ define(function (require, exports, module) { runs(function () { DocumentManager.setCurrentDocument(testDocument); testEditor = EditorManager.getCurrentFullEditor(); - testEditor.setCursorPos({ line: 20, ch: 12 }); + testEditor.setCursorPos({ line: 21, ch: 12 }); CommandManager.execute(Commands.SHOW_CODE_HINTS); }); @@ -378,9 +378,9 @@ define(function (require, exports, module) { }); it("should handle unclosed url(", function () { - var pos1 = { line: 9, ch: 20 }, - pos2 = { line: 9, ch: 24 }, - pos3 = { line: 9, ch: 34 }; + var pos1 = { line: 10, ch: 20 }, + pos2 = { line: 10, ch: 24 }, + pos3 = { line: 10, ch: 34 }; runs(function () { testEditor.setCursorPos(pos1); @@ -406,9 +406,9 @@ define(function (require, exports, module) { }); it("should handle unclosed url( with unclosed single-quote", function () { - var pos1 = { line: 9, ch: 20 }, - pos2 = { line: 9, ch: 25 }, - pos3 = { line: 9, ch: 36 }; + var pos1 = { line: 10, ch: 20 }, + pos2 = { line: 10, ch: 25 }, + pos3 = { line: 10, ch: 36 }; runs(function () { testEditor.setCursorPos(pos1); @@ -435,12 +435,64 @@ define(function (require, exports, module) { }); }); - it("should keep hints open after inserting folder", function () { - var pos1 = { line: 9, ch: 20 }, - pos2 = { line: 9, ch: 25 }, - pos3 = { line: 9, ch: 35 }, - pos4 = { line: 9, ch: 37 }, - pos5 = { line: 9, ch: 48 }; + it("should keep hints open after inserting folder in HTML", function () { + var pos1 = { line: 17, ch: 12 }, + pos2 = { line: 17, ch: 22 }, + pos3 = { line: 17, ch: 33 }, + pos4 = { line: 17, ch: 34 }; + + runs(function () { + testEditor.setCursorPos(pos1); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(2); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // True indicates hints were remain open after insertion of folder + // (i.e. showing contents of inserted folder) + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true); + + // Hint was added with closing double-quote and closing paren + expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/"); + + // Cursor remains inside quote + expect(testEditor.getCursorPos()).toEqual(pos2); + + // Get hints of inserted folder + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(3); + + // Complete path is displayed + expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); + + // False indicates hints were closed after insertion + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false); + + // Hint was added + expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/chevron.png"); + + // Cursor was moved past closing double-quote and closing paren + expect(testEditor.getCursorPos()).toEqual(pos4); + }); + }); + + it("should keep hints open after inserting folder in CSS", function () { + var pos1 = { line: 10, ch: 20 }, + pos2 = { line: 10, ch: 25 }, + pos3 = { line: 10, ch: 35 }, + pos4 = { line: 10, ch: 37 }, + pos5 = { line: 10, ch: 48 }; runs(function () { testEditor.setCursorPos(pos1); @@ -475,7 +527,7 @@ define(function (require, exports, module) { expect(hintsObj).toBeTruthy(); expect(hintsObj.hints).toBeTruthy(); expect(hintsObj.hints.length).toBe(3); - + // Complete path is displayed expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); @@ -489,6 +541,104 @@ define(function (require, exports, module) { expect(testEditor.getCursorPos()).toEqual(pos5); }); }); + + it("should insert folder and replace file in HTML", function () { + var pos1 = { line: 22, ch: 11 }, + pos2 = { line: 22, ch: 21 }, + pos3 = { line: 22, ch: 31 }, + pos4 = { line: 22, ch: 32 }; + + runs(function () { + testEditor.setCursorPos(pos1); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(2); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // True indicates hints were remain open after insertion of folder + // (i.e. showing contents of inserted folder) + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true); + + // Folder was inserted (i.e. filename was not removed) + expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/test2.html"); + + // Cursor is at end of inserted folder + expect(testEditor.getCursorPos()).toEqual(pos2); + + // Get hints of inserted folder + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(3); + + // Complete path is displayed + expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); + + // False indicates hints were closed after insertion + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false); + + // Filename was replaced + expect(testDocument.getRange(pos1, pos4)).toEqual("subfolder/chevron.png"); + }); + }); + + it("should insert folder and replace file in CSS", function () { + var pos1 = { line: 9, ch: 24 }, + pos2 = { line: 9, ch: 34 }, + pos3 = { line: 9, ch: 43 }, + pos4 = { line: 9, ch: 45 }; + + runs(function () { + testEditor.setCursorPos(pos1); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(2); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // True indicates hints were remain open after insertion of folder + // (i.e. showing contents of inserted folder) + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true); + + // Folder was inserted (i.e. filename was not removed) + expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/dummy.jpg"); + + // Cursor is at end of inserted folder + expect(testEditor.getCursorPos()).toEqual(pos2); + + // Get hints of inserted folder + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(3); + + // Complete path is displayed + expect(hintsObj.hints[0]).toBe("subfolder/chevron.png"); + + // False indicates hints were closed after insertion + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(false); + + // Filename was replaced + expect(testDocument.getRange(pos1, pos4)).toEqual("subfolder/chevron.png"); + }); + }); }); }); // describe("Url Code Hinting" From 233aa5367bb4210840b4164cedda9354437b1a62 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Tue, 29 Apr 2014 14:07:06 -0700 Subject: [PATCH 3/9] list case insensitve files/folders --- src/extensions/default/UrlCodeHints/main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/main.js b/src/extensions/default/UrlCodeHints/main.js index 35b51088f84..1184c982acb 100644 --- a/src/extensions/default/UrlCodeHints/main.js +++ b/src/extensions/default/UrlCodeHints/main.js @@ -479,9 +479,10 @@ define(function (require, exports, module) { if (hints instanceof Array && hints.length) { // Array was returned + var lowerCaseFilter = filter.toLowerCase(); console.assert(!result.length); result = $.map(hints, function (item) { - if (item.indexOf(filter) === 0) { + if (item.toLowerCase().indexOf(lowerCaseFilter) === 0) { return item; } }).sort(sortFunc); @@ -497,8 +498,9 @@ define(function (require, exports, module) { // Deferred hints were returned var deferred = $.Deferred(); hints.done(function (asyncHints) { + var lowerCaseFilter = filter.toLowerCase(); result = $.map(asyncHints, function (item) { - if (item.indexOf(filter) === 0) { + if (item.toLowerCase().indexOf(lowerCaseFilter) === 0) { return item; } }).sort(sortFunc); From de3952866aba8492159d7ffc87e7ea42f68a3cf7 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Tue, 29 Apr 2014 15:09:07 -0700 Subject: [PATCH 4/9] when inserting a folder, detect consecutive path separators --- src/extensions/default/UrlCodeHints/main.js | 26 +++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/main.js b/src/extensions/default/UrlCodeHints/main.js index 1184c982acb..fada7617baa 100644 --- a/src/extensions/default/UrlCodeHints/main.js +++ b/src/extensions/default/UrlCodeHints/main.js @@ -661,8 +661,16 @@ define(function (require, exports, module) { // Insert folder names, but replace file names, so if a file is selected // (i.e. closeOnSelect === true), then adjust insert char positions to // replace existing value, if there is a closing paren - if (this.closeOnSelect && closingPos.index !== -1) { - end.ch += this.getCharOffset(this.info.values, this.info, closingPos); + if (this.closeOnSelect) { + if (closingPos.index !== -1) { + end.ch += this.getCharOffset(this.info.values, this.info, closingPos); + } + } else { + // If next char is "/", then overwrite it since we're inserting a "/" + var nextSlash = this.findNextPosInArray(this.info.values, "/", this.info); + if (nextSlash.index === this.info.index && nextSlash.offset === this.info.offset) { + end.ch += 1; + } } if (this.info.filter.length > 0) { start.ch -= this.info.filter.length; @@ -748,8 +756,18 @@ define(function (require, exports, module) { shouldReplace = false; } - // Replace entire value, otherwise just queryDir (to insert new selection) - charCount = (shouldReplace) ? tagInfo.attr.value.length : this.cachedHints.queryDir.length; + if (shouldReplace) { + // Replace entire value + charCount = tagInfo.attr.value.length; + } else { + // Replace queryDir what's been typed (to insert new selection) + charCount = this.cachedHints.queryDir.length + this.info.filter.length; + + // If next char is "/", then overwrite it since we're inserting a "/" + if (this.info.attr.value.length > charCount && this.info.attr.value[charCount] === "/") { + charCount += 1; + } + } } end.line = start.line = cursor.line; From b29150879ef30827b8baccd4f8c4dd5e99edfc85 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Tue, 29 Apr 2014 15:18:38 -0700 Subject: [PATCH 5/9] fix multiple fodler case --- src/extensions/default/UrlCodeHints/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/main.js b/src/extensions/default/UrlCodeHints/main.js index fada7617baa..243944d1ec1 100644 --- a/src/extensions/default/UrlCodeHints/main.js +++ b/src/extensions/default/UrlCodeHints/main.js @@ -760,8 +760,8 @@ define(function (require, exports, module) { // Replace entire value charCount = tagInfo.attr.value.length; } else { - // Replace queryDir what's been typed (to insert new selection) - charCount = this.cachedHints.queryDir.length + this.info.filter.length; + // Replace filter (to insert new selection) + charCount = this.info.filter.length; // If next char is "/", then overwrite it since we're inserting a "/" if (this.info.attr.value.length > charCount && this.info.attr.value[charCount] === "/") { From 0f9ef6b0bb5c6aa3fe531ba2bc4103c21ad71b78 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 1 May 2014 08:26:01 -0700 Subject: [PATCH 6/9] unit tests for collapsing path separators --- .../default/UrlCodeHints/testfiles/test.html | 2 +- .../default/UrlCodeHints/unittests.js | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/extensions/default/UrlCodeHints/testfiles/test.html b/src/extensions/default/UrlCodeHints/testfiles/test.html index 8388fb7f622..add4d0e6fed 100644 --- a/src/extensions/default/UrlCodeHints/testfiles/test.html +++ b/src/extensions/default/UrlCodeHints/testfiles/test.html @@ -6,7 +6,7 @@ body { background-image: url(); border-image: url(''); - list-style-image: url(""); + list-style-image: url("/"); background-image: url(dummy.jpg); background-image: } diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index 1f1908203f8..04927d5fb26 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -639,6 +639,56 @@ define(function (require, exports, module) { expect(testDocument.getRange(pos1, pos4)).toEqual("subfolder/chevron.png"); }); }); + + it("should collapse consecutive path separators when inserting folder in HTML", function () { + var pos1 = { line: 21, ch: 11 }, + pos2 = { line: 21, ch: 22 }; + + runs(function () { + testEditor.setCursorPos(pos1); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(2); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // True indicates hints were remain open after insertion of folder + // (i.e. showing contents of inserted folder) + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true); + + // Folder was inserted and there's only 1 slash afterwards + expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/'"); + }); + }); + + it("should collapse consecutive path separators when inserting folder in CSS", function () { + var pos1 = { line: 8, ch: 25 }, + pos2 = { line: 8, ch: 36 }; + + runs(function () { + testEditor.setCursorPos(pos1); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(2); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // True indicates hints were remain open after insertion of folder + // (i.e. showing contents of inserted folder) + expect(UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0])).toBe(true); + + // Folder was inserted and there's only 1 slash afterwards + expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/\""); + }); + }); }); }); // describe("Url Code Hinting" From 536643d528aba0b439c8d4372bcbf0c477458d62 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Thu, 1 May 2014 09:12:18 -0700 Subject: [PATCH 7/9] fix case sensitivity bug; add tests --- src/extensions/default/UrlCodeHints/main.js | 9 ++-- .../default/UrlCodeHints/unittests.js | 52 +++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/main.js b/src/extensions/default/UrlCodeHints/main.js index 243944d1ec1..4e4178803b3 100644 --- a/src/extensions/default/UrlCodeHints/main.js +++ b/src/extensions/default/UrlCodeHints/main.js @@ -358,17 +358,20 @@ define(function (require, exports, module) { query = ""; } - var hintsAndSortFunc = this._getUrlHints({queryStr: query}); - var hints = hintsAndSortFunc.hints; + var hintsAndSortFunc = this._getUrlHints({queryStr: query}), + hints = hintsAndSortFunc.hints; + if (hints instanceof Array) { // If we got synchronous hints, check if we have something we'll actually use var i, foundPrefix = false; + query = query.toLowerCase(); for (i = 0; i < hints.length; i++) { - if (hints[i].indexOf(query) === 0) { + if (hints[i].toLowerCase().indexOf(query) === 0) { foundPrefix = true; break; } } + if (!foundPrefix) { query = null; } diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index 04927d5fb26..c2bc182d8f4 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -689,6 +689,58 @@ define(function (require, exports, module) { expect(testDocument.getRange(pos1, pos2)).toEqual("subfolder/\""); }); }); + + it("should show & insert case insensitive hints in HTML", function () { + var pos1 = { line: 17, ch: 12 }, + pos2 = { line: 17, ch: 13 }, + pos3 = { line: 17, ch: 21 }; + + runs(function () { + // Insert letter that matches filename, but with different case + testDocument.replaceRange("T", pos1, pos1); + testEditor.setCursorPos(pos2); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(1); + expect(hintsObj.hints[0]).toBe("test.html"); + + UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]); + + // Filename case from list was inserted (overriding case inserted in page) + expect(testDocument.getRange(pos1, pos3)).toEqual("test.html"); + }); + }); + + it("should show & insert case insensitive hints in CSS", function () { + var pos1 = { line: 6, ch: 24 }, + pos2 = { line: 6, ch: 25 }, + pos3 = { line: 6, ch: 33 }; + + runs(function () { + // Insert letter that matches filename, but with different case + testDocument.replaceRange("T", pos1, pos1); + testEditor.setCursorPos(pos2); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(1); + expect(hintsObj.hints[0]).toBe("test.html"); + + UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]); + + // Filename case from list was inserted (overriding case inserted in page) + expect(testDocument.getRange(pos1, pos3)).toEqual("test.html"); + }); + }); }); }); // describe("Url Code Hinting" From 6d6bfc9641215f25f18e4cb64c851717d4f55aa9 Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Sat, 3 May 2014 10:23:13 -0700 Subject: [PATCH 8/9] add new declaration to test HTML path separator collapsing --- .../default/UrlCodeHints/testfiles/test.html | 3 +- .../default/UrlCodeHints/unittests.js | 74 +++++++++---------- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/extensions/default/UrlCodeHints/testfiles/test.html b/src/extensions/default/UrlCodeHints/testfiles/test.html index add4d0e6fed..0ae92ef50ce 100644 --- a/src/extensions/default/UrlCodeHints/testfiles/test.html +++ b/src/extensions/default/UrlCodeHints/testfiles/test.html @@ -6,7 +6,8 @@ body { background-image: url(); border-image: url(''); - list-style-image: url("/"); + list-style-image: url(""); + filter: url("/"); background-image: url(dummy.jpg); background-image: } diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index c2bc182d8f4..b1aafd769a7 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -145,7 +145,7 @@ define(function (require, exports, module) { it("should hint for href attribute", function () { runs(function () { - testEditor.setCursorPos({ line: 13, ch: 12 }); + testEditor.setCursorPos({ line: 14, ch: 12 }); // Must reset hintsObj before every call to expectAsyncHints() hintsObj = null; @@ -159,7 +159,7 @@ define(function (require, exports, module) { it("should hint for src attribute", function () { runs(function () { - testEditor.setCursorPos({ line: 14, ch: 13 }); + testEditor.setCursorPos({ line: 15, ch: 13 }); hintsObj = null; expectAsyncHints(UrlCodeHints.hintProvider); }); @@ -171,21 +171,21 @@ define(function (require, exports, module) { it("should not hint for type attribute", function () { runs(function () { - testEditor.setCursorPos({ line: 14, ch: 21 }); + testEditor.setCursorPos({ line: 15, ch: 21 }); expectNoHints(UrlCodeHints.hintProvider); }); }); it("should not hint in query part of url", function () { runs(function () { - testEditor.setCursorPos({ line: 19, ch: 31 }); + testEditor.setCursorPos({ line: 20, ch: 31 }); expectNoHints(UrlCodeHints.hintProvider); }); }); it("should hint up 1 folder for '../'", function () { runs(function () { - testEditor.setCursorPos({ line: 20, ch: 14 }); + testEditor.setCursorPos({ line: 21, ch: 14 }); hintsObj = null; expectAsyncHints(UrlCodeHints.hintProvider); }); @@ -264,7 +264,7 @@ define(function (require, exports, module) { it("should not hint for background-image outside of url()", function () { runs(function () { - testEditor.setCursorPos({ line: 10, ch: 20 }); + testEditor.setCursorPos({ line: 11, ch: 20 }); expectNoHints(UrlCodeHints.hintProvider); }); }); @@ -339,7 +339,7 @@ define(function (require, exports, module) { runs(function () { DocumentManager.setCurrentDocument(testDocument); testEditor = EditorManager.getCurrentFullEditor(); - testEditor.setCursorPos({ line: 21, ch: 12 }); + testEditor.setCursorPos({ line: 22, ch: 12 }); CommandManager.execute(Commands.SHOW_CODE_HINTS); }); @@ -378,9 +378,9 @@ define(function (require, exports, module) { }); it("should handle unclosed url(", function () { - var pos1 = { line: 10, ch: 20 }, - pos2 = { line: 10, ch: 24 }, - pos3 = { line: 10, ch: 34 }; + var pos1 = { line: 11, ch: 20 }, + pos2 = { line: 11, ch: 24 }, + pos3 = { line: 11, ch: 34 }; runs(function () { testEditor.setCursorPos(pos1); @@ -406,9 +406,9 @@ define(function (require, exports, module) { }); it("should handle unclosed url( with unclosed single-quote", function () { - var pos1 = { line: 10, ch: 20 }, - pos2 = { line: 10, ch: 25 }, - pos3 = { line: 10, ch: 36 }; + var pos1 = { line: 11, ch: 20 }, + pos2 = { line: 11, ch: 25 }, + pos3 = { line: 11, ch: 36 }; runs(function () { testEditor.setCursorPos(pos1); @@ -436,10 +436,10 @@ define(function (require, exports, module) { }); it("should keep hints open after inserting folder in HTML", function () { - var pos1 = { line: 17, ch: 12 }, - pos2 = { line: 17, ch: 22 }, - pos3 = { line: 17, ch: 33 }, - pos4 = { line: 17, ch: 34 }; + var pos1 = { line: 18, ch: 12 }, + pos2 = { line: 18, ch: 22 }, + pos3 = { line: 18, ch: 33 }, + pos4 = { line: 18, ch: 34 }; runs(function () { testEditor.setCursorPos(pos1); @@ -488,11 +488,11 @@ define(function (require, exports, module) { }); it("should keep hints open after inserting folder in CSS", function () { - var pos1 = { line: 10, ch: 20 }, - pos2 = { line: 10, ch: 25 }, - pos3 = { line: 10, ch: 35 }, - pos4 = { line: 10, ch: 37 }, - pos5 = { line: 10, ch: 48 }; + var pos1 = { line: 11, ch: 20 }, + pos2 = { line: 11, ch: 25 }, + pos3 = { line: 11, ch: 35 }, + pos4 = { line: 11, ch: 37 }, + pos5 = { line: 11, ch: 48 }; runs(function () { testEditor.setCursorPos(pos1); @@ -543,10 +543,10 @@ define(function (require, exports, module) { }); it("should insert folder and replace file in HTML", function () { - var pos1 = { line: 22, ch: 11 }, - pos2 = { line: 22, ch: 21 }, - pos3 = { line: 22, ch: 31 }, - pos4 = { line: 22, ch: 32 }; + var pos1 = { line: 23, ch: 11 }, + pos2 = { line: 23, ch: 21 }, + pos3 = { line: 23, ch: 31 }, + pos4 = { line: 23, ch: 32 }; runs(function () { testEditor.setCursorPos(pos1); @@ -592,10 +592,10 @@ define(function (require, exports, module) { }); it("should insert folder and replace file in CSS", function () { - var pos1 = { line: 9, ch: 24 }, - pos2 = { line: 9, ch: 34 }, - pos3 = { line: 9, ch: 43 }, - pos4 = { line: 9, ch: 45 }; + var pos1 = { line: 10, ch: 24 }, + pos2 = { line: 10, ch: 34 }, + pos3 = { line: 10, ch: 43 }, + pos4 = { line: 10, ch: 45 }; runs(function () { testEditor.setCursorPos(pos1); @@ -641,8 +641,8 @@ define(function (require, exports, module) { }); it("should collapse consecutive path separators when inserting folder in HTML", function () { - var pos1 = { line: 21, ch: 11 }, - pos2 = { line: 21, ch: 22 }; + var pos1 = { line: 22, ch: 11 }, + pos2 = { line: 22, ch: 22 }; runs(function () { testEditor.setCursorPos(pos1); @@ -666,8 +666,8 @@ define(function (require, exports, module) { }); it("should collapse consecutive path separators when inserting folder in CSS", function () { - var pos1 = { line: 8, ch: 25 }, - pos2 = { line: 8, ch: 36 }; + var pos1 = { line: 9, ch: 15 }, + pos2 = { line: 9, ch: 26 }; runs(function () { testEditor.setCursorPos(pos1); @@ -691,9 +691,9 @@ define(function (require, exports, module) { }); it("should show & insert case insensitive hints in HTML", function () { - var pos1 = { line: 17, ch: 12 }, - pos2 = { line: 17, ch: 13 }, - pos3 = { line: 17, ch: 21 }; + var pos1 = { line: 18, ch: 12 }, + pos2 = { line: 18, ch: 13 }, + pos3 = { line: 18, ch: 21 }; runs(function () { // Insert letter that matches filename, but with different case From 4dc4f23a62f1c773a6fe31ec3c060c36c3191f9f Mon Sep 17 00:00:00 2001 From: Randy Edmunds Date: Sat, 3 May 2014 11:04:02 -0700 Subject: [PATCH 9/9] add tests for filtered insertions --- .../default/UrlCodeHints/unittests.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/extensions/default/UrlCodeHints/unittests.js b/src/extensions/default/UrlCodeHints/unittests.js index b1aafd769a7..06077f92f9f 100644 --- a/src/extensions/default/UrlCodeHints/unittests.js +++ b/src/extensions/default/UrlCodeHints/unittests.js @@ -591,6 +591,54 @@ define(function (require, exports, module) { }); }); + it("should insert filtered folder in HTML", function () { + var pos1 = { line: 23, ch: 11 }, + pos2 = { line: 23, ch: 14 }, + pos3 = { line: 23, ch: 31 }; + + runs(function () { + testDocument.replaceRange("sub", pos1, pos1); + testEditor.setCursorPos(pos2); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(1); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // Partially existing folder was inserted correctly + UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]); + expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/test2.html"); + }); + }); + + it("should replace filtered file in HTML", function () { + var pos1 = { line: 23, ch: 11 }, + pos2 = { line: 23, ch: 14 }, + pos3 = { line: 23, ch: 21 }; + + runs(function () { + testDocument.replaceRange("tes", pos1, pos1); + testEditor.setCursorPos(pos2); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(1); + expect(hintsObj.hints[0]).toBe("test.html"); + + // Partially existing file was replaced correctly + UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]); + expect(testDocument.getRange(pos1, pos3)).toEqual("test.html'"); + }); + }); + it("should insert folder and replace file in CSS", function () { var pos1 = { line: 10, ch: 24 }, pos2 = { line: 10, ch: 34 }, @@ -640,6 +688,54 @@ define(function (require, exports, module) { }); }); + it("should insert filtered folder in CSS", function () { + var pos1 = { line: 10, ch: 24 }, + pos2 = { line: 10, ch: 27 }, + pos3 = { line: 10, ch: 43 }; + + runs(function () { + testDocument.replaceRange("sub", pos1, pos1); + testEditor.setCursorPos(pos2); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(1); + expect(hintsObj.hints[0]).toBe("subfolder/"); + + // Partially existing folder was inserted correctly + UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]); + expect(testDocument.getRange(pos1, pos3)).toEqual("subfolder/dummy.jpg"); + }); + }); + + it("should replace filtered file in CSS", function () { + var pos1 = { line: 10, ch: 24 }, + pos2 = { line: 10, ch: 27 }, + pos3 = { line: 10, ch: 34 }; + + runs(function () { + testDocument.replaceRange("tes", pos1, pos1); + testEditor.setCursorPos(pos2); + hintsObj = null; + expectAsyncHints(UrlCodeHints.hintProvider); + }); + + runs(function () { + expect(hintsObj).toBeTruthy(); + expect(hintsObj.hints).toBeTruthy(); + expect(hintsObj.hints.length).toBe(1); + expect(hintsObj.hints[0]).toBe("test.html"); + + // Partially existing file was replaced correctly + UrlCodeHints.hintProvider.insertHint(hintsObj.hints[0]); + expect(testDocument.getRange(pos1, pos3)).toEqual("test.html)"); + }); + }); + it("should collapse consecutive path separators when inserting folder in HTML", function () { var pos1 = { line: 22, ch: 11 }, pos2 = { line: 22, ch: 22 };