aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Editor.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/Editor.cxx')
-rw-r--r--src/Editor.cxx45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx
index b0bd99e83..14906f523 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -1663,7 +1663,7 @@ void Editor::LinesSplit(int pixelWidth) {
unsigned int posLineStart = pdoc->LineStart(line);
LayoutLine(line, surface, vs, ll, pixelWidth);
for (int subLine = 1; subLine < ll->lines; subLine++) {
- pdoc->InsertString(posLineStart + (subLine - 1) * strlen(eol) +
+ pdoc->InsertCString(posLineStart + (subLine - 1) * strlen(eol) +
ll->LineStart(subLine), eol);
targetEnd += static_cast<int>(strlen(eol));
}
@@ -4115,7 +4115,7 @@ void Editor::Duplicate(bool forLine) {
char *text = CopyRange(start, end);
if (forLine) {
const char *eol = StringFromEOLMode(pdoc->eolMode);
- pdoc->InsertString(end, eol);
+ pdoc->InsertCString(end, eol);
pdoc->InsertString(end + istrlen(eol), text, end - start);
} else {
pdoc->InsertString(end, text, end - start);
@@ -4135,7 +4135,7 @@ void Editor::NewLine() {
} else if (pdoc->eolMode == SC_EOL_CR) {
eol = "\r";
} // else SC_EOL_LF -> "\n" already set
- if (pdoc->InsertString(currentPos, eol)) {
+ if (pdoc->InsertCString(currentPos, eol)) {
SetEmptySelection(currentPos + istrlen(eol));
while (*eol) {
NotifyChar(*eol);
@@ -4994,7 +4994,7 @@ void Editor::DropAt(int position, const char *value, bool moving, bool rectangul
SetEmptySelection(position);
} else {
position = MovePositionOutsideChar(position, currentPos - position);
- if (pdoc->InsertString(position, value)) {
+ if (pdoc->InsertCString(position, value)) {
SetSelection(position + istrlen(value), position);
}
pdoc->EndUndoAction();
@@ -5700,6 +5700,26 @@ int Editor::WrapCount(int line) {
}
}
+void Editor::AddStyledText(char *buffer, int appendLength) {
+ // The buffer consists of alternating character bytes and style bytes
+ size_t textLength = appendLength / 2;
+ char *text = new char[textLength];
+ if (text) {
+ size_t i;
+ for (i=0;i<textLength;i++) {
+ text[i] = buffer[i*2];
+ }
+ pdoc->InsertString(CurrentPosition(), text, textLength);
+ for (i=0;i<textLength;i++) {
+ text[i] = buffer[i*2+1];
+ }
+ pdoc->StartStyling(CurrentPosition(), static_cast<char>(0xff));
+ pdoc->SetStyles(textLength, text);
+ delete []text;
+ }
+ SetEmptySelection(currentPos + textLength);
+}
+
static bool ValidMargin(unsigned long wParam) {
return wParam < ViewStyle::margins;
}
@@ -5736,7 +5756,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
pdoc->BeginUndoAction();
pdoc->DeleteChars(0, pdoc->Length());
SetEmptySelection(0);
- pdoc->InsertString(0, CharPtrFromSPtr(lParam));
+ pdoc->InsertCString(0, CharPtrFromSPtr(lParam));
pdoc->EndUndoAction();
return 1;
}
@@ -5886,7 +5906,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
pdoc->BeginUndoAction();
ClearSelection();
char *replacement = CharPtrFromSPtr(lParam);
- pdoc->InsertString(currentPos, replacement);
+ pdoc->InsertCString(currentPos, replacement);
pdoc->EndUndoAction();
SetEmptySelection(currentPos + istrlen(replacement));
EnsureCaretVisible();
@@ -6042,13 +6062,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return 0;
}
- case SCI_ADDSTYLEDTEXT: {
- if (lParam == 0)
- return 0;
- pdoc->InsertStyledString(CurrentPosition() * 2, CharPtrFromSPtr(lParam), wParam);
- SetEmptySelection(currentPos + wParam / 2);
- return 0;
- }
+ case SCI_ADDSTYLEDTEXT:
+ if (lParam)
+ AddStyledText(CharPtrFromSPtr(lParam), wParam);
+ return 0;
case SCI_INSERTTEXT: {
if (lParam == 0)
@@ -6058,7 +6075,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
insertPos = CurrentPosition();
int newCurrent = CurrentPosition();
char *sz = CharPtrFromSPtr(lParam);
- pdoc->InsertString(insertPos, sz);
+ pdoc->InsertCString(insertPos, sz);
if (newCurrent > insertPos)
newCurrent += istrlen(sz);
SetEmptySelection(newCurrent);