Skip to content

Commit 6e3800c

Browse files
committed
Only autodecode entities that are caret-adjacent
Cf. #12
1 parent 12bac1a commit 6e3800c

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/Forms/resource.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include <windows.h>
1212

13-
#define HTMLTAG_VERSION L"1.5.1.2\0"
14-
#define HTMLTAG_VERSION_WORDS 1, 5, 1, 2
13+
#define HTMLTAG_VERSION L"1.5.1.3\0"
14+
#define HTMLTAG_VERSION_WORDS 1, 5, 1, 3
1515

1616
#define ID_ABOUT_HTML_TAG_DLG 0x1000
1717
#define ID_UNICODE_FMT_CONFIG_DLG 0x2000

src/HtmlTag.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,15 @@ bool autoCompleteMatchingTag(const Sci_Position startPos, const char *tagName) {
467467
// --------------------------------------------------------------------------------------
468468
void findAndDecode(const int keyCode, DecodeCmd cmd) {
469469
using Decoder = int (*)();
470+
SciActiveDocument doc = plugin.editor().activeDocument();
470471
int ch = keyCode & 0xff;
471472

472-
if ((cmd == dcAuto) && (!(plugin.options.liveEntityDecoding || plugin.options.liveUnicodeDecoding) ||
473+
if ((cmd == dcAuto) && ((ch == 0x0D && doc.sendMessage(SCI_GETEOLMODE) == SC_EOL_CRLF) ||
474+
!(plugin.options.liveEntityDecoding || plugin.options.liveUnicodeDecoding) ||
473475
!((ch >= 0x09 && ch <= 0x0D) || ch == 0x20))) {
474476
return;
475477
}
476478

477-
SciActiveDocument doc = plugin.editor().activeDocument();
478479
Sci_Position caret = doc.currentPosition(), charOffset = -1, anchor, selStart, nextCaretPos;
479480
bool didReplace = false;
480481

@@ -492,11 +493,15 @@ void findAndDecode(const int keyCode, DecodeCmd cmd) {
492493
int chCurrent = static_cast<int>(doc.sendMessage(SCI_GETCHARAT, anchor));
493494
if (chCurrent >= 0 && chCurrent <= 0x20)
494495
break;
495-
if (chCurrent == '&' && (plugin.options.liveEntityDecoding || cmd == dcEntity)) { // Handle entities
496-
didReplace = replace(Entities::decode, anchor, caret);
497-
if (!(ch == 0x0A || ch == 0x0D))
498-
++charOffset;
499-
break;
496+
else if (plugin.options.liveEntityDecoding || cmd == dcEntity) {
497+
if (anchor == (caret - 1) && chCurrent != ';') // No adjacent entity here
498+
break;
499+
else if (chCurrent == '&') { // Handle entities
500+
didReplace = replace(Entities::decode, anchor, caret);
501+
if (!(ch == 0x0A || ch == 0x0D))
502+
++charOffset;
503+
break;
504+
}
500505
} else if (chCurrent == plugin.options.unicodePrefix[0] &&
501506
(plugin.options.liveUnicodeDecoding || cmd == dcUnicode)) { // Handle Unicode
502507
size_t lenPrefix = plugin.options.unicodePrefix.size();

0 commit comments

Comments
 (0)