aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormitchell <unknown>2019-07-11 12:49:28 -0400
committermitchell <unknown>2019-07-11 12:49:28 -0400
commite305512e58c726ef1855ffec4af69c90cfc9e396 (patch)
tree9ac416d8c4d4c676d9bf8b7c6f546e179b583616
parentf40378978a7b3bb901a2085a2c76b1ac4a3f45a0 (diff)
downloadscintilla-mirror-e305512e58c726ef1855ffec4af69c90cfc9e396.tar.gz
Backport: Feature [feature-requests:#1293]. InsertCharacter replaces AddCharUTF.
Backport of changeset 7575:e1e9f53b0423.
-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.cxx11
-rw-r--r--src/Editor.h2
-rw-r--r--src/ScintillaBase.cxx12
-rw-r--r--src/ScintillaBase.h5
-rw-r--r--win32/ScintillaWin.cxx6
9 files changed, 36 insertions, 24 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 7c70b2e60..b4789c432 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -2292,11 +2292,11 @@ ptrdiff_t ScintillaCocoa::InsertText(NSString *input) {
while (sv.length()) {
const unsigned char leadByte = sv[0];
const unsigned int bytesInCharacter = UTF8BytesOfLead[leadByte];
- AddCharUTF(sv.c_str(), bytesInCharacter, false);
+ InsertCharacter(sv.c_str(), bytesInCharacter);
sv = sv.substr(bytesInCharacter, sv.length());
}
} else {
- AddCharUTF(encoded.c_str(), static_cast<unsigned int>(encoded.length()), false);
+ InsertCharacter(encoded.c_str(), static_cast<unsigned int>(encoded.length()));
}
}
return encoded.length();
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 2428a129a..019a0efbf 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -555,6 +555,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 fd26dd2c6..d49bad1bd 100644
--- a/gtk/ScintillaGTK.cxx
+++ b/gtk/ScintillaGTK.cxx
@@ -2258,7 +2258,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;
@@ -2350,7 +2350,7 @@ void ScintillaGTK::CommitThis(char *commitStr) {
if (!IsUnicodeMode())
docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true);
- AddCharUTF(docChar.c_str(), docChar.size());
+ InsertCharacter(docChar.c_str(), docChar.size());
}
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.c_str(), docChar.size());
DrawImeIndicator(indicator[i], docChar.size());
}
diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp
index d7f25dbdc..ea65fb1d3 100644
--- a/qt/ScintillaEditBase/ScintillaEditBase.cpp
+++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp
@@ -259,7 +259,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(utext.data(), utext.size());
} else {
event->ignore();
}
@@ -450,7 +450,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;
@@ -548,9 +548,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(oneChar.data(), oneChar.length());
i += ucWidth;
}
@@ -576,7 +575,7 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event)
const QByteArray oneChar = sqt->BytesForDocument(oneCharUTF16);
const int oneCharLen = oneChar.length();
- sqt->AddCharUTF(oneChar.data(), oneCharLen);
+ sqt->InsertCharacter(oneChar.data(), oneCharLen);
DrawImeIndicator(imeIndicator[i], oneCharLen);
i += ucWidth;
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 161e71706..eb8e4f521 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1888,7 +1888,7 @@ void Editor::AddChar(char ch) {
char s[2];
s[0] = ch;
s[1] = '\0';
- AddCharUTF(s, 1);
+ InsertCharacter(s, 1);
}
void Editor::FilterSelections() {
@@ -1898,8 +1898,8 @@ 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) {
+// InsertCharacter inserts a character encoded in document code page.
+void Editor::InsertCharacter(const char *s, unsigned int len) {
if (len == 0) {
return;
}
@@ -1974,7 +1974,7 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
}
int ch = static_cast<unsigned char>(s[0]);
- if (treatAsDBCS || pdoc->dbcsCodePage != SC_CP_UTF8) {
+ if (pdoc->dbcsCodePage != SC_CP_UTF8) {
if (len > 1) {
// DBCS code page or DBCS font character set.
ch = (ch << 8) | static_cast<unsigned char>(s[1]);
@@ -1994,7 +1994,8 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
NotifyChar(ch);
if (recordingMacro) {
- NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(s));
+ std::string copy(s, len); // ensure NUL-terminated
+ NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(copy.data()));
}
}
diff --git a/src/Editor.h b/src/Editor.h
index e8d1ed48e..9c3f3934c 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(const char *s, unsigned int len);
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 0c00309b7..a72267d32 100644
--- a/src/ScintillaBase.cxx
+++ b/src/ScintillaBase.cxx
@@ -78,17 +78,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(s, len);
+}
+
+void ScintillaBase::InsertCharacter(const char *s, unsigned int len) {
+ const bool isFillUp = ac.Active() && ac.IsFillUpChar(s[0]);
if (!isFillUp) {
- Editor::AddCharUTF(s, len, treatAsDBCS);
+ Editor::InsertCharacter(s, len);
}
if (ac.Active()) {
AutoCompleteCharacterAdded(s[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(s, len);
}
}
}
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index 39fb9d411..dc1438155 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -61,7 +61,10 @@ protected:
void Initialise() override {}
void Finalise() override;
- void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false) override;
+ // 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(const char *s, unsigned int len) 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 fb97719c0..f3764f424 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -927,7 +927,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;
@@ -1059,7 +1059,7 @@ void ScintillaWin::AddWString(std::wstring wcs) {
const std::wstring uniChar(wcs, i, ucWidth);
std::string docChar = StringEncode(uniChar, codePage);
- AddCharUTF(docChar.c_str(), static_cast<unsigned int>(docChar.size()));
+ InsertCharacter(docChar.c_str(), static_cast<unsigned int>(docChar.size()));
i += ucWidth;
}
}
@@ -1108,7 +1108,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
const std::wstring uniChar(wcs, i, ucWidth);
std::string docChar = StringEncode(uniChar, codePage);
- AddCharUTF(docChar.c_str(), static_cast<unsigned int>(docChar.size()));
+ InsertCharacter(docChar.c_str(), static_cast<unsigned int>(docChar.size()));
DrawImeIndicator(imeIndicator[i], static_cast<unsigned int>(docChar.size()));
i += ucWidth;