Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit fc194db

Browse files
committed
Merge pull request #6277 from adobe/randy/issue-6249
Fix entity insertion with 2 entities on same line
2 parents cb6cf49 + fe91284 commit fc194db

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/extensions/default/HtmlEntityCodeHints/main.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,31 @@ define(function (require, exports, module) {
220220
var start = {line: -1, ch: -1},
221221
end = {line: -1, ch: -1},
222222
cursor = this.editor.getCursorPos(),
223-
match,
224-
matchSemicolonPos;
223+
line = this.editor.document.getLine(cursor.line),
224+
subLine,
225+
ampersandPos,
226+
semicolonPos,
227+
entityMatch;
225228

226229
end.line = start.line = cursor.line;
227230
start.ch = cursor.ch - this.currentQuery.length;
228-
match = this.editor.document.getLine(cursor.line).slice(cursor.ch);
229-
matchSemicolonPos = match.indexOf(";");
231+
subLine = line.slice(cursor.ch);
232+
ampersandPos = subLine.indexOf("&");
233+
semicolonPos = subLine.indexOf(";");
230234
end.ch = start.ch + this.currentQuery.length;
231-
232-
if (matchSemicolonPos !== -1 && /^(#*[0-9]+)|([a-zA-Z]+)$/.test(match.slice(0, matchSemicolonPos))) {
233-
end.ch = this.editor.document.getLine(cursor.line).indexOf(";", start.ch) + 1;
235+
236+
// We're looking for ';' in line before next '&'
237+
if (semicolonPos !== -1 && (ampersandPos === -1 || ampersandPos > semicolonPos)) {
238+
239+
subLine = subLine.slice(0, semicolonPos);
240+
241+
// regexp must match entire subLine string
242+
entityMatch = subLine.match(/^(#?[0-9]+)|([a-zA-Z]+)$/);
243+
if (entityMatch && entityMatch.length > 0 && entityMatch.index === 0 &&
244+
entityMatch[0].length === subLine.length) {
245+
// replace entity
246+
end.ch = line.indexOf(";", start.ch) + 1;
247+
}
234248
}
235249

236250
completion = completion.slice(0, completion.indexOf(" "));

src/extensions/default/HtmlEntityCodeHints/unittest-files/default.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<!-- Should show hints when cursor inside Entity -->
1717
<p>
18-
Test&acute;
18+
Test&acute; with more text and a subsequent entity such as &dagger;
1919
</p>
2020

2121
<!-- Shouldn't show hints inside an opening tag-->

0 commit comments

Comments
 (0)