aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cocoa/ScintillaCocoa.mm4
-rw-r--r--doc/ScintillaHistory.html5
-rw-r--r--gtk/ScintillaGTK.cxx6
-rw-r--r--qt/ScintillaEditBase/ScintillaEditBase.cpp9
-rw-r--r--src/Editor.cxx33
-rw-r--r--src/Editor.h2
-rw-r--r--src/ScintillaBase.cxx14
-rw-r--r--src/ScintillaBase.h6
-rw-r--r--win32/ScintillaWin.cxx6
9 files changed, 49 insertions, 36 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 9a507e55c..8271e7988 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -2187,11 +2187,11 @@ ptrdiff_t ScintillaCocoa::InsertText(NSString *input) {
while (sv.length()) {
const unsigned char leadByte = sv[0];
const unsigned int bytesInCharacter = UTF8BytesOfLead[leadByte];
- AddCharUTF(sv.data(), bytesInCharacter, false);
+ InsertCharacter(sv.substr(0, bytesInCharacter));
sv.remove_prefix(bytesInCharacter);
}
} else {
- AddCharUTF(encoded.c_str(), static_cast<unsigned int>(encoded.length()), false);
+ InsertCharacter(encoded);
}
}
return encoded.length();
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 659eba28a..7e9da5464 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -566,6 +566,11 @@
<a href="https://sourceforge.net/p/scintilla/feature-requests/1295/">Feature #1295</a>.
</li>
<li>
+ Platform layers should use InsertCharacter method to perform keyboard and IME input, replacing
+ AddCharUTF method.
+ <a href="https://sourceforge.net/p/scintilla/feature-requests/1293/">Feature #1293</a>.
+ </li>
+ <li>
On Win32, limit text returned from WM_GETTEXT to the length specified in wParam.
<a href="https://sourceforge.net/p/scintilla/bugs/2110/">Bug #2110</a>.
</li>
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx
index ff2b1ffdf..f138da131 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -2259,7 +2259,7 @@ void ScintillaGTK::MoveImeCarets(int pos) {
void ScintillaGTK::DrawImeIndicator(int indicator, int len) {
// Emulate the visual style of IME characters with indicators.
// Draw an indicator on the character before caret by the character bytes of len
- // so it should be called after addCharUTF().
+ // so it should be called after InsertCharacter().
// It does not affect caret positions.
if (indicator < 8 || indicator > INDIC_MAX) {
return;
@@ -2351,7 +2351,7 @@ void ScintillaGTK::CommitThis(char *commitStr) {
if (!IsUnicodeMode())
docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true);
- AddCharUTF(docChar.c_str(), docChar.size());
+ InsertCharacter(docChar);
}
g_free(uniStr);
ShowCaretAtCurrentPosition();
@@ -2412,7 +2412,7 @@ void ScintillaGTK::PreeditChangedInlineThis() {
if (!IsUnicodeMode())
docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true);
- AddCharUTF(docChar.c_str(), docChar.size());
+ InsertCharacter(docChar);
DrawImeIndicator(indicator[i], docChar.size());
}
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp
index 326e29ff3..a37adca1b 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp
@@ -258,7 +258,7 @@ void ScintillaEditBase::keyPressEvent(QKeyEvent *event)
QString text = event->text();
if (input && !text.isEmpty() && text[0].isPrint()) {
QByteArray utext = sqt->BytesForDocument(text);
- sqt->AddCharUTF(utext.data(), utext.size());
+ sqt->InsertCharacter(std::string_view(utext.data(), utext.size()));
} else {
event->ignore();
}
@@ -449,7 +449,7 @@ void ScintillaEditBase::DrawImeIndicator(int indicator, int len)
{
// Emulate the visual style of IME characters with indicators.
// Draw an indicator on the character before caret by the character bytes of len
- // so it should be called after AddCharUTF().
+ // so it should be called after InsertCharacter().
// It does not affect caret positions.
if (indicator < 8 || indicator > INDIC_MAX) {
return;
@@ -547,9 +547,8 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event)
const unsigned int ucWidth = commitStr.at(i).isHighSurrogate() ? 2 : 1;
const QString oneCharUTF16 = commitStr.mid(i, ucWidth);
const QByteArray oneChar = sqt->BytesForDocument(oneCharUTF16);
- const int oneCharLen = oneChar.length();
- sqt->AddCharUTF(oneChar.data(), oneCharLen);
+ sqt->InsertCharacter(std::string_view(oneChar.data(), oneChar.length()));
i += ucWidth;
}
@@ -575,7 +574,7 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event)
const QByteArray oneChar = sqt->BytesForDocument(oneCharUTF16);
const int oneCharLen = oneChar.length();
- sqt->AddCharUTF(oneChar.data(), oneCharLen);
+ sqt->InsertCharacter(std::string_view(oneChar.data(), oneCharLen));
DrawImeIndicator(imeIndicator[i], oneCharLen);
i += ucWidth;
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 2500e6157..2f35862e8 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -100,10 +100,10 @@ Timer::Timer() noexcept :
Idler::Idler() noexcept :
state(false), idlerID(0) {}
-static constexpr bool IsAllSpacesOrTabs(const char *s, unsigned int len) noexcept {
- for (unsigned int i = 0; i < len; i++) {
+static constexpr bool IsAllSpacesOrTabs(std::string_view sv) noexcept {
+ for (const char ch : sv) {
// This is safe because IsSpaceOrTab() will return false for null terminators
- if (!IsSpaceOrTab(s[i]))
+ if (!IsSpaceOrTab(ch))
return false;
}
return true;
@@ -1891,7 +1891,7 @@ void Editor::AddChar(char ch) {
char s[2];
s[0] = ch;
s[1] = '\0';
- AddCharUTF(s, 1);
+ InsertCharacter(std::string_view(s, 1));
}
void Editor::FilterSelections() {
@@ -1901,9 +1901,9 @@ void Editor::FilterSelections() {
}
}
-// AddCharUTF inserts an array of bytes which may or may not be in UTF-8.
-void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
- if (len == 0) {
+// InsertCharacter inserts a character encoded in document code page.
+void Editor::InsertCharacter(std::string_view sv) {
+ if (sv.empty()) {
return;
}
FilterSelections();
@@ -1943,7 +1943,7 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
}
}
positionInsert = RealizeVirtualSpace(positionInsert, currentSel->caret.VirtualSpace());
- const Sci::Position lengthInserted = pdoc->InsertString(positionInsert, s, len);
+ const Sci::Position lengthInserted = pdoc->InsertString(positionInsert, sv.data(), sv.length());
if (lengthInserted > 0) {
currentSel->caret.SetPosition(positionInsert + lengthInserted);
currentSel->anchor.SetPosition(positionInsert + lengthInserted);
@@ -1972,32 +1972,33 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
// Avoid blinking during rapid typing:
ShowCaretAtCurrentPosition();
if ((caretSticky == SC_CARETSTICKY_OFF) ||
- ((caretSticky == SC_CARETSTICKY_WHITESPACE) && !IsAllSpacesOrTabs(s, len))) {
+ ((caretSticky == SC_CARETSTICKY_WHITESPACE) && !IsAllSpacesOrTabs(sv))) {
SetLastXChosen();
}
- int ch = static_cast<unsigned char>(s[0]);
- if (treatAsDBCS || pdoc->dbcsCodePage != SC_CP_UTF8) {
- if (len > 1) {
+ int ch = static_cast<unsigned char>(sv[0]);
+ if (pdoc->dbcsCodePage != SC_CP_UTF8) {
+ if (sv.length() > 1) {
// DBCS code page or DBCS font character set.
- ch = (ch << 8) | static_cast<unsigned char>(s[1]);
+ ch = (ch << 8) | static_cast<unsigned char>(sv[1]);
}
} else {
- if ((ch < 0xC0) || (1 == len)) {
+ if ((ch < 0xC0) || (1 == sv.length())) {
// Handles UTF-8 characters between 0x01 and 0x7F and single byte
// characters when not in UTF-8 mode.
// Also treats \0 and naked trail bytes 0x80 to 0xBF as valid
// characters representing themselves.
} else {
unsigned int utf32[1] = { 0 };
- UTF32FromUTF8(std::string_view(s, len), utf32, std::size(utf32));
+ UTF32FromUTF8(sv, utf32, std::size(utf32));
ch = utf32[0];
}
}
NotifyChar(ch);
if (recordingMacro) {
- NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(s));
+ std::string copy(sv); // ensure NUL-terminated
+ NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(copy.data()));
}
}
diff --git a/src/Editor.h b/src/Editor.h
index c5bddb1e0..5716ba048 100644
--- a/src/Editor.h
+++ b/src/Editor.h
@@ -393,7 +393,7 @@ protected: // ScintillaBase subclass needs access to much of Editor
Sci::Position RealizeVirtualSpace(Sci::Position position, Sci::Position virtualSpace);
SelectionPosition RealizeVirtualSpace(const SelectionPosition &position);
void AddChar(char ch);
- virtual void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false);
+ virtual void InsertCharacter(std::string_view sv);
void ClearBeforeTentativeStart();
void InsertPaste(const char *text, Sci::Position len);
enum PasteShape { pasteStream=0, pasteRectangular = 1, pasteLine = 2 };
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx
index 5a44fd9af..6799dfd06 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -79,17 +79,21 @@ void ScintillaBase::Finalise() {
popup.Destroy();
}
-void ScintillaBase::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
- const bool isFillUp = ac.Active() && ac.IsFillUpChar(*s);
+void ScintillaBase::AddCharUTF(const char *s, unsigned int len, bool /*treatAsDBCS*/) {
+ InsertCharacter(std::string_view(s, len));
+}
+
+void ScintillaBase::InsertCharacter(std::string_view sv) {
+ const bool isFillUp = ac.Active() && ac.IsFillUpChar(sv[0]);
if (!isFillUp) {
- Editor::AddCharUTF(s, len, treatAsDBCS);
+ Editor::InsertCharacter(sv);
}
if (ac.Active()) {
- AutoCompleteCharacterAdded(s[0]);
+ AutoCompleteCharacterAdded(sv[0]);
// For fill ups add the character after the autocompletion has
// triggered so containers see the key so can display a calltip.
if (isFillUp) {
- Editor::AddCharUTF(s, len, treatAsDBCS);
+ Editor::InsertCharacter(sv);
}
}
}
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index f03d1c090..d28e47c4e 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -59,7 +59,11 @@ protected:
void Initialise() override {}
void Finalise() override;
- void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false) override;
+ [[deprecated]]
+ // This method is deprecated, use InsertCharacter instead. The treatAsDBCS parameter is no longer used.
+ virtual void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false);
+
+ void InsertCharacter(std::string_view sv) override;
void Command(int cmdId);
void CancelModes() override;
int KeyCommand(unsigned int iMessage) override;
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index 0aca39fdc..6b3489349 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -924,7 +924,7 @@ void ScintillaWin::MoveImeCarets(Sci::Position offset) {
void ScintillaWin::DrawImeIndicator(int indicator, int len) {
// Emulate the visual style of IME characters with indicators.
// Draw an indicator on the character before caret by the character bytes of len
- // so it should be called after addCharUTF().
+ // so it should be called after InsertCharacter().
// It does not affect caret positions.
if (indicator < 8 || indicator > INDIC_MAX) {
return;
@@ -1055,7 +1055,7 @@ void ScintillaWin::AddWString(std::wstring_view wsv) {
const size_t ucWidth = UTF16CharLength(wsv[i]);
const std::string docChar = StringEncode(wsv.substr(i, ucWidth), codePage);
- AddCharUTF(docChar.c_str(), static_cast<unsigned int>(docChar.size()));
+ InsertCharacter(docChar);
i += ucWidth;
}
}
@@ -1104,7 +1104,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
const size_t ucWidth = UTF16CharLength(wsv[i]);
const std::string docChar = StringEncode(wsv.substr(i, ucWidth), codePage);
- AddCharUTF(docChar.c_str(), static_cast<unsigned int>(docChar.size()));
+ InsertCharacter(docChar);
DrawImeIndicator(imeIndicator[i], static_cast<unsigned int>(docChar.size()));
i += ucWidth;