1 namespace gui::controls;
4 selectionForeground = white;
5 disabled: defaultTextColor = Color { 85, 85, 85 };
14 char * strchrmax(const char * s, int c, int max)
18 for(i = 0; i < max && (ch = s[i]); i++)
24 public class SyntaxColorScheme
28 Color charLiteralColor;
29 Color stringLiteralColor;
30 Color preprocessorColor;
32 private Array<Color> keywordColors { };
34 public property Container<Color> keywordColors
36 set { keywordColors.Copy((void *)value); }
37 get { return keywordColors; }
45 #define XOFFSET (3 + (/*style.lineNumbers?6 * this.space.w:*/0))
47 #define YOFFSET (style.multiLine ? 1 : ((clientSize.h + 1 - space.h) / 2))
49 #define IS_ALUNDER(ch) (/*(ch) == '_' || */CharMatchCategories((ch), letters|numbers|marks|connector))
51 #define UTF8_IS_FIRST(x) (__extension__({ byte b = x; (!(b) || !((b) & 0x80) || ((b) & 0x40)); }))
52 #define UTF8_NUM_BYTES(x) (__extension__({ byte b = x; (b & 0x80 && b & 0x40) ? ((b & 0x20) ? ((b & 0x10) ? 4 : 3) : 2) : 1; }))
53 #define UTF8_GET_CHAR(string, numBytes) \
57 byte b = (string)[0]; \
60 numBytes = b ? 1 : 0; \
74 if(b & 0x08) { numBytes = 0; } \
83 for(i = 0; i<numBytes; i++) \
86 ch |= (b = (string)[i]) & mask; \
88 if(i > 1 && (!(b & 0x80) || (b & 0x40))) \
95 ch > 0x10FFFF || (ch >= 0xD800 && ch <= 0xDFFF) || \
96 (ch < 0x80 && numBytes > 1) || \
97 (ch < 0x800 && numBytes > 2) || \
98 (ch < 0x10000 && numBytes > 3))\
108 bool autoEmpty:1, readOnly:1, multiLine:1, stuckCaret:1, freeCaret:1, select:1, hScroll:1, vScroll:1, smartHome:1;
109 bool noCaret:1, noSelect:1, tabKey:1, useTab:1, tabSel:1, allCaps:1, syntax:1, wrap:1;
112 bool inMultiLineComment:1, inPrep:1, escaped:1, continuedSingleLineComment:1, wasInMultiLine:1, continuedString:1, continuedQuotes:1;
114 bool recomputeSyntax:1;
115 bool cursorFollowsView:1;
117 // bool lineNumbers:1;
122 void UnregisterClass_EditBox()
125 for(g = 0; g<NUM_KEYWORD_GROUPS; g++)
134 extern int __ecereVMethodID_class_OnFree;
137 static class ArrayImpl
144 public class OldArray
149 void ** array = (void **)((ArrayImpl)this).array;
150 if(type.type == normalClass || type.type == noHeadClass)
152 for(c = 0; c<size; c++)
153 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, array[c]);
155 // TODO: Call OnFree for structClass
156 delete ((ArrayImpl)this).array;
165 if(((ArrayImpl)this).array)
169 ((ArrayImpl)this).array = renew0 ((ArrayImpl)this).array byte[type.typeSize * value];
172 ((ArrayImpl)this).array = new0 byte[value * type.typeSize];
181 memcpy(((ArrayImpl)this).array, value, type.typeSize * size);
188 public class UndoAction : struct
191 subclass(UndoAction) type;
194 virtual void Undo(void * data) { type.Undo(this, data); }
195 virtual void Redo(void * data) { type.Redo(this, data); }
197 virtual void Print(void * data) { type.Print(this, data); }
201 if(((Class)type).Destructor)
202 ((void (*)(void *))((Class)type).Destructor)(this);
206 public class UndoBuffer
208 Array<UndoAction> actions { size = 8 };
227 bool continued = true;
228 while(curAction > 0 && continued)
230 UndoAction action = actions[--curAction];
234 /*Print("Undoing: ");
235 action.Print(data);*/
240 continued = curAction > 0 && actions[curAction-1].continued;
246 bool continued = true;
247 while(curAction < count && continued)
249 UndoAction action = actions[curAction];
250 continued = action.continued;
256 /*Print("Redoing: ");
257 action.Print(data);*/
266 void Record(UndoAction action)
268 if(!dontRecord && !insideRedo)
270 if(curAction < count)
273 for(c = curAction; c < count; c++)
279 if(count >= actions.size)
280 actions.size += actions.size / 2;
283 /*Print("Recording: ");
284 action.Print(data);*/
288 if(!firstEvent && count > 0)
289 actions[count-1].continued = true;
292 actions[count++] = action;
295 if(actions.size > count + count / 2 && count + count / 2 >= 8)
296 actions.size = count + count / 2;
303 static class AddCharAction : UndoAction
307 int addedSpaces, addedTabs, xAdjustment;
308 type = class(AddCharAction);
310 void Undo(EditBox editBox)
312 editBox.GoToPosition(null, (ch == '\n') ? (y + 1) : y, (ch == '\n') ? 0 : (x + 1) - xAdjustment);
314 if(addedTabs || addedSpaces)
316 editBox.DelCh(editBox.line, y, x - xAdjustment - (addedSpaces + addedTabs), editBox.line, y, x - xAdjustment, false);
317 editBox.GoToPosition(editBox.line, y, x);
319 editBox.UpdateDirty();
322 void Redo(EditBox editBox)
324 editBox.GoToPosition(null, y, x);
326 editBox.UpdateDirty();
329 void Print(EditBox editBox)
331 PrintLn("AddChar: y = ", y, "x = ", x, ", ch = ", ch, ", addedSpaces = ", addedSpaces, ", addedTabs = ", addedTabs);
336 static class AddTextAction : UndoAction
340 int addedSpaces, addedTabs, xAdjustment;
341 type = class(AddTextAction);
344 void Print(EditBox editBox)
346 PrintLn("AddText: y1 = ", y1, "x1 = ", x1, ", y2 = ", y2, ", x2 = ", x2, ", string = ", string, ", addedSpaces = ", addedSpaces, ", addedTabs = ", addedTabs);
354 void Undo(EditBox editBox)
359 editBox.GoToPosition(null, y1, x1);
361 l2 = editBox.lines.first;
362 for(c = 0; c < y2 && l2; c++, l2 = l2.next);
364 editBox.DelCh(l1, y1, x1, l2, y2, x2, true);
365 if(addedTabs || addedSpaces)
366 editBox.DelCh(editBox.line, y1, x1 - (addedSpaces + addedTabs), editBox.line, y1, x1, false);
368 editBox.SetViewToCursor(true);
372 void Redo(EditBox editBox)
374 editBox.GoToPosition(null, y1, x1);
375 editBox.PutS(string);
379 static class DelTextAction : UndoAction
383 bool placeAfter, noHighlight;
385 type = class(DelTextAction);
388 void Print(EditBox editBox)
390 PrintLn("DelText: y1 = ", y1, "x1 = ", x1, ", y2 = ", y2, ", x2 = ", x2, ", string = ", string, ", addedSpaces = ", addedSpaces, ", placeAfter = ", placeAfter);
393 void Undo(EditBox editBox)
395 editBox.GoToPosition(null, y1, x1);
396 editBox.PutS(string);
400 editBox.GoToPosition(null, y1, x1);
406 { int c; editBox.selLine = editBox.lines.first; for(c = 0; c < editBox.selY && editBox.selLine; c++, editBox.selLine = editBox.selLine.next); }
407 //editBox.SetViewToCursor(true);
410 editBox.DelCh(editBox.line, y1, x1 - addedSpaces, editBox.line, y1, x1, false);
419 { int c; editBox.selLine = editBox.lines.first; for(c = 0; c < editBox.selY && editBox.selLine; c++, editBox.selLine = editBox.selLine.next); }
420 //editBox.SetViewToCursor(true);
423 editBox.DelCh(editBox.selLine, y1, x1 - addedSpaces, editBox.selLine, y1, x1, false);
427 void Redo(EditBox editBox)
432 editBox.GoToPosition(null, y1, x1);
435 l2 = editBox.lines.first;
436 for(c = 0; c < y2 && l2; c++, l2 = l2.next);
438 editBox.DelCh(l1, y1, x1, l2, y2, x2, true);
439 editBox.SetViewToCursor(true);
449 static class ReplaceTextAction : UndoAction
451 int y1, x1, y2, x2, y3, x3;
455 int addedSpaces, addedTabs, xAdjustment;
457 type = class(ReplaceTextAction);
460 void Print(EditBox editBox)
462 PrintLn("ReplaceText: y1 = ", y1, "x1 = ", x1, ", y2 = ", y2, ", x2 = ", x2, ", y3 = ", y3, ", x3 = ", x3, ", oldString = ", oldString, ", newString = ", newString, ", addedSpaces = ", addedSpaces, ", addedTabs = ", addedTabs, ", placeAfter = ", placeAfter);
465 void Undo(EditBox editBox)
470 editBox.GoToPosition(null, y1, x1);
472 l3 = editBox.lines.first;
473 for(c = 0; c < y3 && l3; c++, l3 = l3.next);
475 editBox.DelCh(l1, y1, x1, l3, y3, x3, true);
477 editBox.PutS(oldString);
478 if(addedSpaces || addedTabs)
479 editBox.DelCh(l1, y1, x1 - (addedSpaces + addedTabs), l1, y1, x1, false);
481 //editBox.PutS(oldString);
484 editBox.GoToPosition(null, y1, x1);
487 { int c; editBox.selLine = editBox.lines.first; for(c = 0; c < editBox.selY && editBox.selLine; c++, editBox.selLine = editBox.selLine.next); }
493 { int c; editBox.selLine = editBox.lines.first; for(c = 0; c < editBox.selY && editBox.selLine; c++, editBox.selLine = editBox.selLine.next); }
497 void Redo(EditBox editBox)
502 editBox.GoToPosition(null, y1, x1);
504 l2 = editBox.lines.first;
505 for(c = 0; c < y2 && l2; c++, l2 = l2.next);
507 editBox.DelCh(l1, y1, x1, l2, y2, x2, true);
509 editBox.PutS(newString);
519 static class MoveTextAction : UndoAction
521 int fy1, fx1, fy2, fx2;
523 type = class(MoveTextAction);
525 void Undo(EditBox editBox)
530 void Redo(EditBox editBox)
536 public class EditLine : struct
544 property const char * text
548 // Only works for single line edit for now...
549 EditBox editBox = this.editBox;
553 get { return this ? buffer : null; }
555 property EditLine prev { get { return this ? prev : null; } };
556 property EditLine next { get { return this ? next : null; } };
557 property int count { get { return this ? count : 0; } };
564 // This makes sure the buffer always contains at least count characters
565 // Keeps a count/2 pad for avoiding always reallocating memory.
566 bool AdjustBuffer(int count)
574 newSize = (count + (count >> 1));
576 // Shrink down the buffer
579 buffer = new char[newSize];
580 if(!buffer) return false;
584 CopyBytes(buffer, this.buffer, count);
587 this.buffer = buffer;
591 // Increase the buffer
592 else if(size < count)
594 buffer = new char[newSize];
595 if(!buffer) return false;
599 CopyBytes(buffer, this.buffer, this.count + 1); // size);
602 this.buffer = buffer;
611 public struct BufferLocation
616 void AdjustDelete(BufferLocation start, BufferLocation end)
618 // Location is before, nothing to do
619 if(y < start.y || (y == start.y && x < start.x))
621 // Location is inside deleted bytes, point to the start
622 if((y >= start.y && (y > start.y || x >= start.x)) &&
623 (y >= end.y && (y > end.y || x >= end.x)))
628 // Location is on another line
630 y -= end.y - start.y;
631 // Location is the last touched line
638 //if(start.line == end.line)
639 x -= end.x - start.x;
648 // Assuming no carriage return before first character ???? fixed?
649 void AdjustAdd(BufferLocation start, BufferLocation end)
651 int numLines = end.y - start.y;
658 if(x > start.x || (x == start.x /*&& (numLines ? true : false)*/))
661 for(c = 0, line = start.line; c<numLines; c++)
664 //x += numLines ? end.x : (end.x - start.x);
665 x += end.x - start.x;
672 public enum EditBoxFindResult { notFound, found, wrapped };
674 static const char * keyWords1[] =
677 "return","break","continue","default","switch","case","if","else","for","while", "do","long","short",
678 "void", "char","int","float","double","signed","unsigned","static", "extern", "struct", "union", "typedef","enum",
680 "#include", "#define", "#pragma", "#if", "#else", "#elif", "#ifdef", "#ifndef", "#endif", "#undef", "#line",
681 "__attribute__", "__stdcall", "_stdcall",
682 "__declspec", "goto",
683 "inline", "__inline__", "_inline", "__inline", "__typeof","__extension__",
684 "asm", "__asm", "_asm", "volatile", "#cpu", "__stdcall__",
685 "__restrict__", "__restrict", "restrict",
688 "class", "private", "public",
690 "delete", "new", "new0", "renew", "renew0", "define",
693 "dllexport", "dllimport", "stdcall",
694 "subclass", "__on_register_module", "namespace", "using",
695 "typed_object", "any_object", "incref", "register", "watch", "stopwatching", "firewatchers", "watchable", "class_designer",
696 "class_fixed", "class_no_expansion", "isset", "class_default_property", "property_category", "class_data", "class_property",
697 "virtual", "thisclass","unichar", "dbtable", "dbindex", "database_open", "dbfield",
700 "uint", "uint32", "uint16", "uint64", "bool", "byte", "int64", "uintptr", "intptr", "intsize", "uintsize",
703 "this", "true", "false", "null", "value",
712 static const char * keyWords2[] =
714 "defined", "warning",
715 "include", "pragma", "elif", "ifdef", "ifndef", "endif", "undef", "line",
719 static const char ** keyWords[] = { keyWords1, keyWords2 };
720 #define NUM_KEYWORD_GROUPS (sizeof(keyWords) / sizeof(char **))
721 //static int * keyLen[NUM_KEYWORD_GROUPS];
722 static int keyLen[NUM_KEYWORD_GROUPS][sizeof(keyWords1)];
724 static char searchString[1025], replaceString[1025];
725 static bool matchCase = false, wholeWord = false, searchUp = false;
727 static GoToDialog goToDialog
729 autoCreate = false, isModal = true, text = $"Go To"
732 public class EditBox : CommonControl
734 class_property(icon) = "<:ecere>controls/editBox.png";
738 virtual bool Window::NotifyModified(EditBox editBox);
739 virtual void Window::NotifyCaretMove(EditBox editBox, int line, int charPos);
740 virtual void Window::NotifyUpdate(EditBox editBox);
741 virtual bool Window::NotifyDoubleClick(EditBox editBox, EditLine line, Modifiers mods);
742 virtual void Window::NotifyOvrToggle(EditBox editBox, bool overwrite);
743 virtual bool Window::NotifyKeyDown(EditBox editBox, Key key, unichar ch);
745 virtual bool Window::NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation);
746 virtual bool Window::NotifyCharsDeleted(EditBox editBox, BufferLocation beforeLoc, BufferLocation after, bool pasteOperation);
747 virtual bool Window::NotifyDropped(EditBox editBox, int x, int y);
749 virtual bool Window::NotifyUnsetModified(EditBox editBox);
751 // Why was this commented out?
752 // It is required otherwise updating font property from property sheet doesn't immediately reflect in form designer,
753 // and the scrollArea property isn't compared properly either.
757 if(font) ComputeFont();
758 SetInitSize(initSize);
764 style.vScroll = true;
770 style.hScroll = true;
774 property bool textHorzScroll { property_category $"Behavior" set { style.hScroll = value; } get { return style.hScroll; } }; // Should cut the text on set to false
775 property bool textVertScroll { property_category $"Behavior" set { style.vScroll = value; } get { return style.vScroll; } };
776 property bool readOnly
778 property_category $"Behavior"
781 style.readOnly = value;
782 itemEditCut.disabled = value || !selection;
783 itemEditDelete.disabled = value || !selection;
784 itemEditPaste.disabled = value;
786 get { return style.readOnly; }
788 property bool multiLine { property_category $"Behavior" set { style.multiLine = value; } get { return style.multiLine; } };
789 property bool freeCaret { property_category $"Behavior" set { style.freeCaret = value; } get { return style.freeCaret; } };
790 property bool tabKey { property_category $"Behavior" set { style.tabKey = value; } get { return style.tabKey; } };
791 property int tabSize { property_category $"Behavior" set { tabSize = value; } get { return tabSize; } };
792 property bool tabSelection { property_category $"Behavior" set { style.tabSel = value; if(value) style.tabKey = true; } get { return style.tabSel; } };
793 property bool smartHome { property_category $"Behavior" set { style.smartHome = value; } get { return style.smartHome; } };
794 property bool autoEmpty { property_category $"Behavior" set { style.autoEmpty = value; } get { return style.autoEmpty; } };
795 property bool noCaret { property_category $"Behavior" set { style.noCaret = value; if(value) { style.readOnly = true; style.stuckCaret = true; } } get { return style.noCaret; } };
796 property int maxLineSize { property_category $"Behavior" set { maxLineSize = value; } get { return maxLineSize; } };
797 property int maxNumLines { property_category $"Behavior" set { maxLines = value; } get { return maxLines; } };
798 property bool useTab { property_category $"Behavior" set { style.useTab = value; itemEditInsertTab.checked = value; } get { return style.useTab; } };
799 property bool syntaxHighlighting { property_category $"Appearance" set { style.syntax = value; } get { return style.syntax; } };
800 property bool noSelect { property_category $"Behavior" set { style.noSelect = value; } get { return style.noSelect; } };
801 property bool allCaps { property_category $"Behavior" set { style.allCaps = value; } get { return style.allCaps; } };
802 property bool autoSize { property_category $"Behavior" set { style.autoSize = value; } get { return style.autoSize; } };
803 property bool wrap { set { style.wrap = value; Update(null); } get { return style.wrap; } };
804 //property bool lineNumbers { set { style.lineNumbers = value; } get { return style.lineNumbers; } };
805 property int numLines { get { return this ? lineCount : 0; } };
806 property int lineNumber { get { return y; } }; // TODO: Change to property of EditLine this.line.number
807 property int column { get { return col; } }; // TODO: Add Set
808 property int charPos { get { return x; } }; // TODO: Add Set
809 property EditLine firstLine { get { return lines.first; } }; // Change these to a List<EditLine>... (this.lines[10].text)
810 property EditLine lastLine { get { return lines.last; } };
811 property EditLine line { get { return this.line; } }; // TODO: Add Set this.line = this.lines[10]
812 property const char * contents
814 property_category $"Data"
819 undoBuffer.dontRecord++;
821 DelCh(this.lines.first, 0, 0, this.lines.last, this.lineCount-1, ((EditLine)(this.lines.last)).count, true);
824 //SetViewToCursor(true);
827 undoBuffer.dontRecord--;
833 char * buffer = null;
836 /* Can't implement this right now because of memory leak... Need string reference counting...
843 for(line = lines.first; line; line = line.next)
844 len += strlen(line.buffer);
846 buffer = new char[len+1];
848 for(line = lines.first; line; line = line.next)
850 int lineLen = strlen(line.buffer);
851 memcpy(buffer + len, line.buffer, lineLen);
857 buffer = this.line ? this.line.buffer : null;
862 property bool overwrite { get { return overwrite; } };
863 property bool caretFollowsScrolling { get { return style.cursorFollowsView; } set { style.cursorFollowsView = value; } }
865 property char * multiLineContents
869 char * buffer = null;
876 for(line = lines.first; line; line = line.next)
877 len += strlen(line.buffer)+1;
879 buffer = new char[len+1];
881 for(line = lines.first; line; line = line.next)
883 int lineLen = strlen(line.buffer);
884 memcpy(buffer + len, line.buffer, lineLen);
886 if(line.next) buffer[len++] = '\n';
899 return this.line.buffer;
904 void SetLineText(const char * text)
908 EditLine_SetText(this.line, text);
912 property Color selectionColor { set { selectionColor = value; } get { return selectionColor; } isset { return selectionColor ? true : false; } };
913 property Color selectionText { set { selectionText = value; } get { return selectionText; } isset { return selectionText ? true : false; } };
914 property SyntaxColorScheme syntaxColorScheme { set { delete colorScheme; colorScheme = value; incref colorScheme; } }
915 property bool recordUndoEvent { set { undoBuffer.recordAsOne = value; undoBuffer.firstEvent = true; } get { return undoBuffer.recordAsOne; } };
917 // selectionStart.line, selectionStart.column (With Set)
918 // selection.line1, selection.line2, selection.column1, selection.column2 (Read only)
932 // Position of Caret (Not necessarily displayed position)
935 // Position of beginning of block (Block ends at (x,y))
937 // line is line at carret, selLine is line at beginning of block
938 EditLine line, selLine, dropLine;
939 // Mouse selection Moving virtual caret
944 // ViewX is x offset in pixels, ViewY is y offset in lines
946 // viewLine is first displayed line
949 // start and end of area to redraw
952 // MaxLine is the longest line
954 // MaxLength is the longest line's length
957 // MouseSelect is true once button is pressed, overwrite is true if mode is on
958 bool mouseSelect, mouseMove, overwrite, wordSelect;
959 // Timer is used for mouse selection scrolling
962 window = this, delay = 0.1;
971 OnMouseMove(mouseX, mouseY, -1);
976 // (mouseX,mouseY) is the position of the mouse in the edit box
981 void (* FontExtent)(Display display, Font font, const char * text, int len, int * width, int * height);
984 bool rightButtonDown;
987 UndoBuffer undoBuffer { data = this };
989 ColorAlpha selectionColor, selectionText;
990 SyntaxColorScheme colorScheme { };
995 Menu editMenu { menu, $"Edit", e };
998 editMenu, $"Cut\tCtrl+X", t, disabled = true;
1000 bool NotifySelect(MenuItem item, Modifiers mods)
1002 if(!(style.readOnly))
1007 MenuItem itemEditCopy
1009 editMenu, $"Copy\tCtrl+C", c, disabled = true;
1011 bool NotifySelect(MenuItem item, Modifiers mods)
1017 MenuItem itemEditPaste
1019 editMenu, $"Paste\tCtrl+V", p;
1021 bool NotifySelect(MenuItem item, Modifiers mods)
1023 if(!(style.readOnly))
1028 MenuItem itemEditDelete
1030 editMenu, $"Delete\tDel", d, disabled = true;
1032 bool NotifySelect(MenuItem item, Modifiers mods)
1034 if(!(style.readOnly))
1039 MenuDivider { editMenu };
1040 MenuItem itemEditSelectAll
1042 editMenu, $"Select All\tCtrl+A", a;
1044 bool NotifySelect(MenuItem item, Modifiers mods)
1050 MenuDivider { editMenu };
1051 MenuItem itemEditUndo
1053 editMenu, $"Undo\tCtrl+Z", u;
1056 bool NotifySelect(MenuItem item, Modifiers mods)
1062 MenuItem itemEditRedo
1064 editMenu, $"Redo\tCtrl+Y", o;
1067 bool NotifySelect(MenuItem item, Modifiers mods)
1073 MenuDivider { editMenu };
1076 editMenu, $"Find Previous\tShift-F3", e, shiftF3;
1078 bool NotifySelect(MenuItem item, Modifiers mods)
1081 Find(searchString, wholeWord, matchCase, false);
1083 itemEditFind.NotifySelect(this, item, mods);
1089 editMenu, $"Find Next\tF3", n, f3;
1091 bool NotifySelect(MenuItem item, Modifiers mods)
1094 Find(searchString, wholeWord, matchCase, true);
1096 itemEditFind.NotifySelect(this, item, mods);
1100 MenuItem itemEditFind
1102 editMenu, $"Find...\tCtrl+F", f, ctrlF;
1104 bool NotifySelect(MenuItem item, Modifiers mods)
1108 editBox = this, master = master, isModal = true, searchString = searchString, matchCase = matchCase, wholeWord = wholeWord,
1109 searchUp = searchUp;
1112 // Fix dialog from above shouldn't be visible
1113 // void NotifyDestroyed(FindDialog dialog, DialogResult result)
1114 void NotifyDestroyed(Window window, DialogResult result)
1116 FindDialog dialog = (FindDialog) window;
1117 searchUp = dialog.searchUp;
1118 strcpy(searchString, dialog.searchString);
1119 matchCase = dialog.matchCase;
1120 wholeWord = dialog.wholeWord;
1129 editMenu, $"Replace...\tCtrl+R", r, ctrlR;
1131 bool NotifySelect(MenuItem item, Modifiers mods)
1133 ReplaceDialog dialog
1137 searchString = searchString,
1138 replaceString = replaceString,
1139 matchCase = matchCase,
1140 wholeWord = wholeWord,
1144 // void NotifyDestroyed(ReplaceDialog dialog, DialogResult result)
1145 void NotifyDestroyed(Window window, DialogResult result)
1147 ReplaceDialog dialog = (ReplaceDialog)window;
1148 const char * replace = dialog.replaceString;
1150 strcpy(replaceString, replace);
1151 strcpy(searchString, dialog.searchString);
1152 matchCase = dialog.matchCase;
1153 wholeWord = dialog.wholeWord;
1160 MenuDivider { editMenu };
1163 editMenu, $"Go To...\tCtrl+G", g, ctrlG;
1165 bool NotifySelect(MenuItem item, Modifiers mods)
1167 goToDialog.editBox = this;
1168 goToDialog.master = master;
1169 goToDialog.Create();
1173 MenuDivider { editMenu };
1174 MenuItem itemEditInsertTab
1176 editMenu, $"Insert Tabs", i, checkable = true;
1178 bool NotifySelect(MenuItem item, Modifiers mods)
1180 style.useTab = item.checked;
1186 snapVertScroll = true;
1187 snapHorzScroll = true;
1191 static bool syntaxInit = false;
1196 for(g = 0; g<NUM_KEYWORD_GROUPS; g++)
1198 for(c = 0; keyWords[g][c]; c++);
1199 //keyLen[g] = new int[c];
1200 for(c = 0; keyWords[g][c]; c++)
1202 keyLen[g][c] = strlen(keyWords[g][c]);
1206 colorScheme.commentColor = dimGray;
1207 colorScheme.charLiteralColor = crimson;
1208 colorScheme.stringLiteralColor = crimson;
1209 colorScheme.preprocessorColor = green;
1210 colorScheme.numberColor = teal;
1211 colorScheme.keywordColors = [ blue, blue ];
1214 FontExtent = Display::FontExtent;
1216 lines.offset = (uint)(uintptr)&((EditLine)0).prev;
1218 style = EditBoxBits { hScroll = true };
1220 // cursor = guiApp.GetCursor(IBeam);
1222 // Default Properties
1224 maxLineSize = 1024;*/
1227 maxLineSize = MAXINT;
1232 mouseSelect = this.mouseMove = false;
1235 x = selX = selY = 0;
1238 line = selLine = null;
1244 endY = clientSize.h;
1247 // Default space to 8 in case window is not constructed
1250 undoBuffer.dontRecord++;
1252 undoBuffer.dontRecord--;
1254 viewLine = lines.first;
1255 style.recomputeSyntax = true;
1261 UpdateCaretPosition(true);
1267 lines.Free(EditLine::Free);
1270 void FlushBuffer(Surface surface, EditLine line, int wc, int * renderStart, int * x, int y, int numSpaces, bool drawSpaces, Box box)
1272 int count = wc - *renderStart;
1275 if(y + space.h >= box.top && y <= box.bottom)
1281 //FontExtent(display, font, line.buffer + *renderStart, count, &w, null);
1282 surface.TextFont(font);
1283 surface.TextExtent(line.buffer + *renderStart, count, &w, null);
1284 if(*x + w + XOFFSET > 0)
1285 surface.WriteText(XOFFSET + *x,y, line.buffer + *renderStart, count);
1290 w = numSpaces; // * space.w;
1291 if(*x + w + XOFFSET > 0 && (drawSpaces || surface.GetTextOpacity()))
1292 surface.Area(XOFFSET + *x - 1, y, XOFFSET + *x + w, y + space.h-1);
1293 // WHATS UP WITH THIS... surface.Area(XOFFSET + *x, y, XOFFSET + *x + w, y + space.h-1);
1301 bool CheckColors(EditLine line, int wc, bool selection, int selX, int editX, bool *selected,
1302 Color selectionForeground, Color selectionBackground, Color textColor, Color *foreground, Color *background, bool *opacity, int *overwrite)
1308 if((wc == selX && line == selLine) || (wc == editX && line == this.line))
1312 *foreground = (*selected) ? selectionForeground : textColor;
1313 *background = selectionBackground;
1314 *opacity = *selected;
1321 if(this.overwrite && active)
1323 if((style.stuckCaret && wc == line.count && !line.next) ||
1324 (!mouseMove && line == this.line && wc == editX))
1333 void FigureStartSyntaxStates(EditLine firstLine, bool reset)
1337 bool inMultiLineComment = reset ? false : style.inMultiLineComment;
1338 bool wasInMultiLine = reset ? false : style.wasInMultiLine;
1339 bool inString = false;
1340 bool inQuotes = false;
1341 bool inPrep = reset ? false : style.inPrep;
1342 bool inSingleLineComment = false;
1343 bool escaped = reset ? false : style.escaped;
1344 bool continuedSingleLineComment = reset ? false : style.continuedSingleLineComment;
1345 bool continuedString = reset ? false : style.continuedString;
1346 bool continuedQuotes = reset ? false : style.continuedQuotes;
1348 EditLine line = reset ? lines.first : firstLine;
1349 // int maxBackUp = 1000, c;
1350 // for(c = 0, line = viewLine; c < maxBackUp && line && line.prev; line = line.prev);
1351 for(; line != viewLine; line = line.next)
1353 char * text = line.buffer;
1356 bool lastWasStar = false;
1357 bool firstWord = true;
1358 if(!escaped) inPrep = false;
1359 inSingleLineComment = continuedSingleLineComment;
1361 inString = continuedString;
1362 inQuotes = continuedQuotes;
1365 for(c = 0; (ch = text[c]); c++)
1367 bool wasEscaped = escaped;
1368 bool backLastWasStar = lastWasStar;
1369 bool backWasInMultiLine = wasInMultiLine;
1371 lastWasStar = false;
1372 wasInMultiLine = inMultiLineComment;
1375 if(!inSingleLineComment && !inMultiLineComment && !inQuotes && !inString)
1377 if(text[c+1] == '/')
1379 inSingleLineComment = true;
1381 else if(text[c+1] == '*')
1383 inMultiLineComment = true;
1386 else if(backLastWasStar)
1387 inMultiLineComment = false;
1391 if(backWasInMultiLine) lastWasStar = true;
1393 else if(ch == '\"' && !inSingleLineComment && !inMultiLineComment && !inQuotes)
1395 if(inString && !wasEscaped)
1404 else if(ch == '\'' && !inSingleLineComment && !inMultiLineComment && !inString)
1406 if(inQuotes && !wasEscaped)
1418 else if(ch == '#' && !inQuotes && !inString && !inMultiLineComment && !inSingleLineComment)
1425 else if(ch != ' ' && ch != '\t')
1428 if(line.count && line.text[line.count - 1] == '\\')
1430 continuedSingleLineComment = inSingleLineComment;
1431 continuedString = inString;
1432 continuedQuotes = inQuotes;
1436 continuedSingleLineComment = false;
1437 continuedString = false;
1438 continuedQuotes = false;
1442 style.continuedSingleLineComment = continuedSingleLineComment;
1443 style.continuedString = continuedString;
1444 style.continuedQuotes = continuedQuotes;
1445 style.inMultiLineComment = inMultiLineComment;
1446 style.wasInMultiLine = wasInMultiLine;
1447 style.inPrep = inPrep;
1448 style.escaped = escaped;
1452 /*void OnDrawOverChildren(Surface surface)
1454 if(style.lineNumbers)
1456 int currentLineNumber = this.viewY + 1;
1459 for(i = 0; i * space.h < box.height; i++)
1461 // ********* LINE NUMBERING *********
1462 surface.SetForeground(Color{60, 60, 60});
1463 //Highlight current line
1464 if(this.caretY / space.h == currentLineNumber - 1)
1465 surface.SetBackground(Color{220, 220, 220});
1467 surface.SetBackground(Color{230, 230, 230});
1468 surface.textOpacity = true;
1470 sprintf(lineText,"%5u ", currentLineNumber % 100000);
1471 if(currentLineNumber > this.lineCount)
1472 surface.WriteText(0,i*space.h+1," ",6);
1474 surface.WriteText(0,i*space.h+1,lineText,6);
1476 currentLineNumber++;
1481 void OnRedraw(Surface surface)
1485 bool selected = false, selection = true;
1487 Color selectionBackground = selectionColor ? selectionColor : SELECTION_COLOR;
1488 Color selectionForeground = selectionText ? selectionText : SELECTION_TEXT;
1489 Color defaultTextColor = property::foreground;
1492 int maxW = clientSize.w;
1494 Color foreground, background;
1497 // Overwrite Caret Stuff
1499 int overWriteX = 0, overWriteY = 0;
1502 // ****** SYNTAX STATES ******
1503 bool inMultiLineComment = style.inMultiLineComment;
1504 bool inString = false;
1505 bool inQuotes = false;
1506 bool inPrep = style.inPrep;
1507 bool inSingleLineComment = false;
1508 bool escaped = style.escaped;
1509 bool continuedSingleLineComment = style.continuedSingleLineComment;
1510 bool continuedString = style.continuedString;
1511 bool continuedQuotes = style.continuedQuotes;
1512 bool wasInMultiLine = style.wasInMultiLine;
1513 // ****** ************* ******
1516 defaultTextColor = Color { 85, 85, 85 };
1517 textColor = defaultTextColor;
1520 Abs(selectionBackground.r - property::background.r) +
1521 Abs(selectionBackground.g - property::background.g) +
1522 Abs(selectionBackground.b - property::background.b) < 92)
1524 selectionBackground = formColor;
1525 selectionForeground = selectionColor ? selectionColor : SELECTION_COLOR;
1528 surface.TextFont(this.font);
1530 surface.SetBackground(GDefaultPalette()[RND_Get(1, 15)]);
1531 surface.Area(0,0,MAXINT,MAXINT);
1536 surface.SetBackground(formColor);
1537 surface.Area(0,0,clientSize.w, clientSize.h);
1540 if(this.selX == this.x && this.selY == this.y)
1550 editX = Min(this.x,this.line.count);
1551 selX = Min(this.selX,this.selLine.count);
1554 selected = (this.selY < this.viewY) ^ (this.y < this.viewY);
1556 foreground = selected ? selectionForeground : textColor;
1557 background = selectionBackground;
1563 surface.SetForeground(foreground);
1564 surface.SetBackground(background);
1565 surface.TextOpacity(opacity);
1567 surface.GetBox(box);
1569 for(line = this.viewLine; line; line = line.next)
1571 int x = -this.viewX;
1575 Color newTextColor = textColor = defaultTextColor;
1576 bool lineComplete = false;
1579 // ****** SYNTAX HIGHLIGHTING ******
1580 bool lastWasStar = false;
1581 bool trailingSpace = false;
1582 bool firstWord = true;
1583 if(!escaped) inPrep = false;
1584 inSingleLineComment = continuedSingleLineComment;
1586 inString = continuedString;
1587 inQuotes = continuedQuotes;
1588 // *********************************
1590 /* === DEBUGGING TOOL FOR MAXLINE ===
1592 if(line == this.maxLine)
1594 surface.SetBackground(GREEN|0xFF000000);
1595 surface.TextOpacity(true);
1599 surface.TextOpacity(selected ? true : false);
1600 surface.SetBackground(selected ? SELECTION_COLOR|0xFF000000 : BLACK|0xFF000000);
1604 if(line == this.selLine && line == this.line)
1606 end = Max(line.count, this.x);
1607 end = Max(end, this.selX);
1609 else if(line == this.selLine)
1610 end = Max(line.count, this.selX);
1611 else if(line == this.line)
1612 end = Max(line.count, this.x);
1620 bool spacing = true;
1621 bool cantHaveWords = false;
1628 lineComplete = false;
1631 textColor = newTextColor;
1634 foreground = textColor;
1635 surface.SetForeground(textColor);
1639 for(; c<end && !cantHaveWords;)
1643 bufferLen += wordLen;
1647 /*if(line.count > 4000)
1654 for(; c<line.count; c++)
1656 unichar ch = line.buffer[c];
1657 unichar bf = (wordLen == 1) ? line.buffer[c-1] : 0;
1658 //if(ch == ' ' || ch == '\t' || (wordLen && (ch == '(' || ch == ')' || ch == ';' || ch == ':')) || (wordLen == 1 && line.buffer[c-1] == '('))
1659 if(CharMatchCategories(ch, separators) || /*ch == ' ' ||*/ ch == '\t' ||
1660 (wordLen && !CharMatchCategories(ch, numbers|letters|marks|connector) && ch != '#' /*&& ch != '_'*/) ||
1661 (bf && !CharMatchCategories(bf, numbers|letters|separators|marks|connector) && bf != '#' && bf != '\t' /*&& bf != '_' && bf != ' '*/))
1664 trailingSpace = false;
1670 for(; c<line.count; c++)
1672 unichar ch = line.buffer[c];
1673 if(ch == '\t' || ch == ' ')
1675 cantHaveWords = true;
1676 if(ch == ' ' && c == line.count-1)
1677 trailingSpace = true;
1681 if(ch != ' ' && ch != '\t')
1686 if(c == line.count && c < end)
1695 cantHaveWords = true;
1700 lastWasStar = false;
1706 bool backEscaped = escaped;
1707 bool backLastWasStar = lastWasStar;
1708 bool backInMultiLineComment = inMultiLineComment;
1709 bool backInString = inString;
1710 bool backInQuotes = inQuotes;
1711 bool backInPrep = inPrep;
1712 bool backInSingleLineComment = inSingleLineComment;
1713 bool backWasInMultiLine = wasInMultiLine;
1715 char * word = line.buffer + c - wordLen;
1717 bool wasEscaped = escaped;
1719 lastWasStar = false;
1721 wasInMultiLine = inMultiLineComment;
1723 // Determine Syntax Highlighting
1724 newTextColor = defaultTextColor;
1727 if(inSingleLineComment || inMultiLineComment)
1729 newTextColor = colorScheme.commentColor;
1733 newTextColor = colorScheme.charLiteralColor;
1737 newTextColor = colorScheme.stringLiteralColor;
1741 newTextColor = colorScheme.preprocessorColor;
1743 if(wordLen == 1 && word[0] == '/')
1745 if(!inSingleLineComment && !inMultiLineComment && !inQuotes && !inString)
1749 inSingleLineComment = true;
1750 newTextColor = colorScheme.commentColor;
1752 else if(word[1] == '*')
1754 inMultiLineComment = true;
1755 newTextColor = colorScheme.commentColor;
1758 else if(backLastWasStar)
1759 inMultiLineComment = false;
1761 else if(wordLen == 1 && word[0] == '*')
1763 if(backWasInMultiLine)
1766 else if(!inSingleLineComment && !inMultiLineComment && !inQuotes && wordLen == 1 && word[0] == '\"')
1768 if(inString && !wasEscaped)
1775 newTextColor = colorScheme.stringLiteralColor;
1778 else if(!inSingleLineComment && !inMultiLineComment && !inString && wordLen == 1 && word[0] == '\'')
1780 if(inQuotes && !wasEscaped)
1785 newTextColor = colorScheme.charLiteralColor;
1788 else if(wordLen == 1 && word[0] == '\\')
1793 else if(x < box.right && !inQuotes && !inString && !inMultiLineComment && !inSingleLineComment && (isdigit(word[0]) || (word[0] == '.' && isdigit(word[1]))))
1795 char * dot = word[wordLen] == '.' ? word + wordLen : (word[0] == '.' && (word == line.buffer || word[-1] == '-' || isspace(word[-1])) ? word : null);
1796 bool isReal = dot != null;
1803 bool isHex = (word[0] == '0' && (word[1] == 'x' || word[1] == 'X'));
1806 exponent = strchrmax(word, 'p', wordLen);
1807 if(!exponent) exponent = strchrmax(word, 'P', wordLen);
1811 exponent = strchrmax(word, 'e', wordLen);
1812 if(!exponent) exponent = strchrmax(word, 'E', wordLen);
1814 isReal = exponent != null;
1817 strtod(word, &s); // strtod() seems to break on hex floats (e.g. 0x23e3p12, 0x1.fp3)
1819 strtol(word, &s, 0);
1825 int gotF = 0, gotL = 0, gotU = 0, gotI = 0;
1828 for(i = 0; valid && i < 5 && (ch = s[i]) && (isalnum(ch) || ch == '_'); i++)
1832 case 'f': case 'F': gotF++; if(gotF > 1 || !isReal) valid = false; break;
1835 if(gotL > 2 || isReal || (gotL == 2 && (s[i-1] != ch)))
1838 case 'u': case 'U': gotU++; if(gotU > 1 || isReal) valid = false; break;
1839 case 'i': case 'I': case 'j': case 'J': gotI++; if(gotI > 1) valid = false; break;
1840 default: valid = false;
1844 // Don't highlight numbers with too many decimal points
1845 if(s[0] == '.' && isdigit(s[1]))
1848 while(s[0] == '.' && isdigit(s[1]))
1850 int newWordLen = s - word;
1851 c += newWordLen - wordLen;
1852 wordLen = newWordLen;
1855 newWordLen = s - word;
1856 c += newWordLen - wordLen;
1857 wordLen = newWordLen;
1861 int newWordLen = s + i - word;
1862 newTextColor = colorScheme.numberColor;
1863 c += newWordLen - wordLen;
1864 wordLen = newWordLen;
1866 else if(dot && dot > word && dot < s)
1867 newTextColor = colorScheme.numberColor;
1872 if(!inQuotes && !inString && !inMultiLineComment && !inSingleLineComment && word[0] == '#')
1877 newTextColor = wordLen == 1 ? colorScheme.keywordColors[1] : colorScheme.preprocessorColor;
1880 if(x < box.right && !inQuotes && !inString && !inMultiLineComment && !inSingleLineComment)
1882 for(g = 0; g < ((inPrep && word[0] != '#') ? 2 : 1); g++)
1884 const char ** keys = keyWords[g];
1885 int * len = keyLen[g];
1886 for(ccc = 0; keys[ccc]; ccc++)
1888 if(len[ccc] == wordLen && !strncmp(keys[ccc], word, wordLen))
1890 newTextColor = colorScheme.keywordColors[g];
1899 // If highlighting for this word is different, break
1900 if(newTextColor != textColor)
1904 // Better solution than going back?
1907 // Reset syntax flags
1908 escaped = backEscaped;
1909 lastWasStar = backLastWasStar;
1910 inMultiLineComment = backInMultiLineComment;
1911 inString = backInString;
1912 inQuotes = backInQuotes;
1913 inPrep = backInPrep;
1914 inSingleLineComment = backInSingleLineComment;
1915 wasInMultiLine = backWasInMultiLine;
1920 textColor = newTextColor;
1923 foreground = textColor;
1924 surface.SetForeground(textColor);
1931 // If we're not breaking, this can't be rendered as spacing anymore
1934 // Do word wrapping here
1940 FontExtent(display, font, line.buffer + start, bufferLen + wordLen, &tw, null);
1945 w += numSpaces * space.w;
1947 if(x + viewX + w > maxW)
1949 // Avoid an endless loop until we fix wrapping
1950 if(c - wordLen > start)
1953 lineComplete = true;
1959 bufferLen += wordLen;
1964 int renderStart = start;
1966 bool flagTrailingSpace = false;
1970 // Render checking if we need to split because of selection or to find where to draw insert caret
1971 for(wc = start; wc < start + bufferLen; wc++)
1973 flush = CheckColors(line, wc, selection, selX, editX, &selected, selectionForeground,
1974 selectionBackground, textColor, &foreground, &background, &opacity, &overWrite);
1977 overWriteCh = (wc < line.count) ? line.buffer[wc] : ' ';
1978 if(overWriteCh == '\t') overWriteCh = ' ';
1983 flagTrailingSpace = numSpaces && trailingSpace && style.syntax && start + bufferLen == line.count && line != this.line;
1984 if(flagTrailingSpace) surface.SetBackground(red);
1985 FlushBuffer(surface, line, wc, &renderStart, &x, y, numSpaces, flagTrailingSpace, box);
1994 surface.TextOpacity(opacity);
1995 surface.SetBackground(background);
1996 surface.SetForeground(foreground);
2003 if(wc < line.count && line.buffer[wc] == '\t')
2005 numSpaces += (tabSize * space.w) - ((x + numSpaces + viewX) % (tabSize * space.w));
2009 numSpaces += space.w;
2013 flagTrailingSpace = numSpaces && trailingSpace && style.syntax && start + bufferLen == line.count && line != this.line;
2014 if(flagTrailingSpace) surface.SetBackground(red);
2015 FlushBuffer(surface, line, wc, &renderStart, &x, y, numSpaces, flagTrailingSpace, box);
2020 if(CheckColors(line, c, selection, selX, editX, &selected, selectionForeground,
2021 selectionBackground, textColor, &foreground, &background, &opacity, &overWrite))
2030 surface.TextOpacity(opacity);
2031 surface.SetBackground(background);
2032 surface.SetForeground(foreground);
2035 if(style.freeCaret && selected)
2037 surface.SetBackground(selectionBackground);
2038 surface.Area(x + XOFFSET - 1,y,clientSize.w-1,y+this.space.h-1);
2039 // TEST: surface.Area(x + XOFFSET,y,clientSize.w-1,y+this.space.h-1);
2044 if(style.freeCaret && selected)
2046 surface.SetBackground(selectionBackground);
2047 surface.Area(x + XOFFSET - 1,y,clientSize.w-1,y+this.space.h-1);
2050 if(line.count && line.text[line.count - 1] == '\\')
2052 continuedSingleLineComment = inSingleLineComment;
2053 continuedString = inString;
2054 continuedQuotes = inQuotes;
2058 continuedSingleLineComment = false;
2059 continuedString = false;
2060 continuedQuotes = false;
2064 if(y > box.bottom) // >=clientSize.h)
2070 surface.TextOpacity(true);
2071 surface.SetForeground(black);
2072 surface.SetBackground(Color {255,255,85});
2073 surface.WriteText(XOFFSET + overWriteX,overWriteY, &overWriteCh, 1);
2077 void FixScrollArea()
2079 if(style.hScroll || style.vScroll)
2081 int width = maxLength + XOFFSET;
2082 int height = lineCount * space.h;
2083 if(style.freeCaret && line)
2088 width = Max(line.length + (x - line.count) * space.w, maxLength + XOFFSET);
2092 if(selX > selLine.count)
2093 width = Max(selLine.length + (selX - selLine.count) * space.w, maxLength + XOFFSET);
2098 SetScrollLineStep(8, space.h);
2099 SetScrollArea(width, height, true);
2103 void ComputeLength(EditLine line)
2108 for(c = 0; c < line.count; )
2117 for(len = 0; c < line.count; c += numBytes)
2119 ch = line.buffer[c];
2120 numBytes = UTF8_NUM_BYTES(ch);
2122 if(ch == ' ' || ch == '\t')
2129 if(!len && ch == ' ')
2134 else if(!len && ch == '\t')
2136 w = (tabSize * space.w) - (x % (tabSize * space.w));
2140 FontExtent(display, font, line.buffer + start, len, &w, null);
2151 if(line.length > this.maxLength)
2153 this.maxLine = line;
2154 this.maxLength = line.length;
2156 if(style.autoSize) AutoSize();
2165 this.maxLine = null;
2167 for(line = lines.first; line; line = line.next)
2169 if(line.length > this.maxLength)
2171 this.maxLength = line.length;
2172 this.maxLine = line;
2176 if(style.autoSize) AutoSize();
2181 if(this.selY != this.y)
2183 else if(this.selX != this.x) // commented out to erase caret: if(this.selX != this.x)
2187 void ComputeColumn()
2189 // Adjust new edit X position according to tabs
2190 int c, position = 0;
2193 for(c = 0; c<this.line.count && c<this.x && (ch = UTF8_GET_CHAR(this.line.buffer + c, nb)); c+= nb)
2195 // TODO: MIGHT WANT TO RETHINK WHAT COLUMN SHOULD BE REGARDING TABS
2197 position += this.tabSize - (position % this.tabSize);
2201 position += this.x - c;
2202 this.col = position;
2205 void DelCh(EditLine l1, int y1, int c1, EditLine l2, int y2, int c2, bool placeAfter)
2207 _DelCh(l1, y1, c1, l2, y2, c2, placeAfter, true, null);
2210 bool HasCommentOrEscape(EditLine line)
2212 bool hadComment = strstr(line.buffer, "/*") || strstr(line.buffer, "*/");
2217 for(c = line.count-1; c >= 0; c--)
2219 char ch = line.buffer[c];
2225 else //if(ch != ' ' && ch != '\t')
2232 int _DelCh(EditLine l1, int y1, int c1, EditLine l2, int y2, int c2, bool placeAfter, bool highlight, int * addedSpacesPtr)
2234 EditLine line = l1, next;
2236 int oldCount1, oldCount2;
2237 int y, firstViewY, firstY, firstDropY, firstSelY;
2240 DelTextAction action = null;
2241 bool hadComment = false;
2245 hadComment = HasCommentOrEscape(line);
2247 if(y2 > y1 || c2 > c1)
2249 if(start < l1.count)
2251 while(!UTF8_IS_FIRST(l1.buffer[start]) && start)
2255 oldCount1 = l1.count;
2257 while(c1 < oldCount1)
2259 byte ch = buffer[c1];
2260 if(UTF8_IS_FIRST(ch)) break;
2264 oldCount2 = l2.count;
2266 while(c2 < oldCount2)
2268 byte ch = buffer[c2];
2269 if(UTF8_IS_FIRST(ch)) break;
2274 if(!undoBuffer.dontRecord && (y2 > y1 || c2 > c1))
2279 len = GetText(null, l1, y1, start, l2, y2, c2, false, false);
2280 string = new char[len];
2281 action = DelTextAction { y1 = y1, x1 = start, y2 = y2, x2 = c2, string = string, placeAfter = placeAfter, noHighlight = !highlight };
2282 GetText(string, l1, y1, start, l2, y2, c2, false, false);
2286 //oldCount1 = l1.count;
2287 //oldCount2 = l2.count;
2290 BufferLocation before = { l1,y1,c1}, after = { l2,y2,c2 };
2291 NotifyCharsDeleted(master, this, &before, &after, this.pasteOperation);
2294 if(c2 > oldCount2) c2 = oldCount2;
2295 if(!(style.freeCaret))
2296 if(c1 > oldCount1) c1 = oldCount1;
2297 newLineCount = c1 + l2.count-c2;
2303 buffer = new char[line.size ? line.size : 1];
2305 buffer = new char[line.size];
2306 // TODO: Better handling of these allocation failures
2307 if(!buffer) return extras;
2308 CopyBytes(buffer,l2.buffer,oldCount1 + 1/*line.count + 1*//*line.size*/);
2313 // TODO: Better handling of these allocation failures
2314 if(!line.AdjustBuffer(newLineCount))
2318 /*if(newLineCount > 4000 || newLineCount < 0)
2319 printf("Warning");*/
2321 line.count = newLineCount;
2323 memmove(l1.buffer+c1, buffer+c2,line.count-c1);
2328 action.addedSpaces = c1-oldCount1;
2330 if(action.addedSpaces > action.x1)
2336 if(addedSpacesPtr) *addedSpacesPtr = c1-oldCount1;
2337 FillBytes(l1.buffer+oldCount1,' ',c1-oldCount1);
2339 line.buffer[line.count] = '\0';
2346 this.dropX -= c2-c1;
2347 this.dropX = Max(this.dropX,0);
2349 this.x = Max(this.x,0);
2356 firstViewY = this.viewY;
2358 firstDropY = this.dropY;
2359 firstSelY = this.selY;
2360 for(line = l1;line;line = next, y++)
2368 if(line == this.viewLine)
2370 if(this.viewLine.next)
2372 this.viewLine = this.viewLine.next;
2374 style.recomputeSyntax = true;
2378 this.viewLine = this.viewLine.prev;
2380 style.recomputeSyntax = true;
2383 else if(y < firstViewY)
2385 if(line == this.line)
2389 this.line = this.line.next;
2390 this.x = this.line.count;
2395 this.line = this.line.prev;
2396 this.x = this.line.count;
2403 if(line == this.dropLine)
2405 if(this.dropLine.next)
2407 this.dropLine = this.dropLine.next;
2408 this.dropX = this.dropLine.count;
2412 this.dropLine = this.dropLine.prev;
2413 this.dropX = this.dropLine.count;
2417 else if(y < firstDropY)
2419 if(line == this.selLine)
2421 if(this.selLine.next)
2423 this.selLine = this.selLine.next;
2424 this.selX = this.selLine.count;
2428 this.selLine = this.selLine.prev;
2429 this.selX = this.selLine.count;
2433 else if(y < firstSelY)
2437 if(line == l2) break;
2441 if(style.syntax && (hadComment || HasCommentOrEscape(this.line)))
2444 style.recomputeSyntax = true;
2449 bool DelSel(int * addedSpacesPtr)
2451 if(this.line != this.selLine || this.x != this.selX)
2453 if(this.selY < this.y)
2455 _DelCh(this.selLine, this.selY, this.selX, this.line, this.y, this.x, true, true, addedSpacesPtr);
2458 this.line = this.selLine;
2460 else if(this.selY > this.y)
2462 _DelCh(this.line, this.y, this.x, this.selLine, this.selY, this.selX, false, true, addedSpacesPtr);
2465 this.selLine = this.line;
2467 else if(this.selX < this.x)
2469 _DelCh(this.selLine, this.selY, this.selX, this.line, this.y, this.x, true, true, addedSpacesPtr);
2472 this.line = this.selLine;
2476 _DelCh(this.line, this.y, this.x, this.selLine, this.selY, this.selX, false, true, addedSpacesPtr);
2479 this.selLine = this.line;
2487 bool AddToLine(const char * stringLine, int count, bool LFComing, int * addedSpacesPtr, int * addedTabsPtr, int * xAdjustmentPtr)
2489 bool hadComment = false;
2490 // Add the line here
2491 EditLine line = this.line;
2493 // The purpose of this is solely to lock a max number of characters if no HSCROLLING is present
2494 if(!style.hScroll && created)
2496 int endX = (style.freeCaret) ? this.x : Min(this.x, line.count);
2501 // Lock if no place to display.
2504 else if(endX > this.x)
2505 max = Max(this.x, line.count);
2509 for(x = 0, c = 0; c < max+count; )
2513 const char * string;
2514 if(c < Min(this.x, line.count))
2515 string = line.buffer + c;
2518 else if(c < endX + count)
2519 string = stringLine + c - endX;
2521 string = line.buffer + c - endX - count;
2525 w = (tabSize * space.w) - (x % (tabSize * space.w));
2529 numBytes = UTF8_NUM_BYTES(*string);
2530 FontExtent(display, this.font, string, numBytes, &w, null);
2534 if(x >= clientSize.w)
2539 c += numBytes; // - 1;
2545 int addedSpaces = 0;
2547 int xAdjustment = 0;
2549 // Add blank spaces if EES_FREECARET
2550 if(this.x > line.count)
2560 for(c = 0; c<line.count; c++)
2562 if(this.line.buffer[c] == '\t')
2563 position += this.tabSize - (position % this.tabSize);
2567 wantedPosition = position + (this.x - line.count);
2569 // A tab is too much...
2570 if(position + (this.tabSize - (position % this.tabSize)) > wantedPosition)
2571 addedSpaces = wantedPosition - position;
2574 xAdjustment = wantedPosition - position;
2578 position += this.tabSize - (position % this.tabSize);
2579 // Add as many tabs as needed
2580 addedTabs += (wantedPosition - position) / this.tabSize;
2581 position += (addedTabs-1) * this.tabSize;
2582 // Finish off with spaces
2583 addedSpaces = wantedPosition - position;
2585 xAdjustment -= addedSpaces + addedTabs;
2589 addedSpaces = this.x - line.count;
2592 this.x = Min(this.x, line.count);
2594 if(line.count + count + addedSpaces + addedTabs > this.maxLineSize)
2600 hadComment = HasCommentOrEscape(line);
2602 // Adjust the size of the line
2603 if(!line.AdjustBuffer(line.count+count+addedTabs+addedSpaces))
2607 BufferLocation before = { this.line, this.y, this.x }, after = { this.line, this.y, this.x };
2610 memmove(line.buffer+this.x+count, line.buffer+this.x,line.count-this.x);
2611 CopyBytes(line.buffer + this.x + addedTabs + addedSpaces, stringLine, count);
2614 FillBytes(line.buffer+line.count,'\t',addedTabs);
2616 if(addedTabs > 4000 || addedTabs < 0)
2619 line.count += addedTabs;
2624 FillBytes(line.buffer+line.count,' ',addedSpaces);
2626 if(addedSpaces > 4000 || addedSpaces < 0)
2629 line.count += addedSpaces;
2632 if(addedTabsPtr) *addedTabsPtr = addedTabs;
2633 if(addedSpacesPtr) *addedSpacesPtr = addedSpaces;
2634 if(xAdjustmentPtr) *xAdjustmentPtr = xAdjustment;
2636 if(count > 4000 || count < 0)
2639 line.count += count;
2640 this.x += count + addedTabs + addedSpaces;
2643 this.selLine = this.line;
2645 line.buffer[line.count] = '\0';
2647 ComputeLength(line);
2652 hasComment = HasCommentOrEscape(line);
2653 if(!undoBuffer.insideRedo)
2655 int backDontRecord = undoBuffer.dontRecord;
2656 undoBuffer.dontRecord = 0;
2657 NotifyCharsAdded(master, this, &before, &after, this.pasteOperation);
2658 undoBuffer.dontRecord = backDontRecord;
2660 if(style.syntax && (hadComment || hasComment || line != this.line))
2662 style.recomputeSyntax = true;
2670 void Emptyline(EditLine line, int y)
2673 DelCh(line, y, 0, line.next, y+1, 0, true);
2675 DelCh(line, y, 0, line, y, line.count, true);
2678 void GoToEnd(bool deselect)
2682 this.line = this.lines.last;
2683 if(this.y != this.lineCount-1)
2685 else if (this.x != this.line.count)
2686 DirtyLine(this.lineCount-1);
2687 this.y = this.lineCount-1;
2688 this.x = this.line.count;
2695 void GoToHome(bool deselect)
2699 this.line = this.lines.first;
2702 else if (this.x !=0)
2703 DirtyLine(this.lineCount-1);
2712 // Returns true if it needs scrolling
2713 bool FindMouse(int px, int py, int * tx, int * ty, EditLine * tline, bool half)
2718 bool needHScroll = false;
2725 line = this.viewLine ? (void *)this.viewLine.prev : null;
2730 line = (void *)this.lines.first;
2735 py = Min(py, clientSize.h);
2737 py = Min(py, this.lineCount);
2739 for(c = 0, line = this.viewLine; (line != (void *)this.lines.last && c<py); line = line.next, c++)
2745 if( (px >= clientSize.w || px < clientSize.w/2) && this.viewX)
2748 px = Min(px,clientSize.w+this.space.w);
2752 *tx = AdjustXPosition(line, px + viewX, half, null, MAXINT, 0);
2755 if(tline) *tline = line;
2758 // Prevent divide by 0 from non valid this.font
2760 return (y < this.viewY) || needHScroll;
2762 return (y < this.viewY || y >= this.viewY + clientSize.h / this.space.h) || needHScroll;
2766 // Minimal Update Management Functions
2770 this.endY = clientSize.h-1;
2771 // ErrorLog("DirtyAll\n");
2774 void DirtyEnd(int y)
2776 if((y - this.viewY)*this.space.h < this.startY)
2777 this.startY = (y - this.viewY)*this.space.h+ YOFFSET;
2778 this.endY = clientSize.h-1;
2779 //ErrorLog("DirtyEnd %d\n", y);
2782 void DirtyLine(int y)
2786 if((y - this.viewY)*this.space.h < this.startY)
2787 this.startY = (y - this.viewY)*this.space.h + YOFFSET;
2788 if((y - this.viewY+1)*this.space.h > this.endY)
2789 this.endY = (y - this.viewY+1)*this.space.h-1 + YOFFSET;
2791 //ErrorLog("DirtyLine %d\n", y);
2798 if(style.recomputeSyntax)
2800 FigureStartSyntaxStates(lines.first, true);
2801 style.recomputeSyntax = false;
2804 if(this.startY > this.endY) return;
2805 if(this.startY <= 0 && this.endY >= clientSize.h-1)
2811 box.right = clientSize.w-1;
2812 box.top = this.startY;
2813 box.bottom = this.endY;
2816 this.startY = clientSize.h;
2820 bool IsMouseOnSelection()
2822 bool mouseOnSelection = false;
2825 int minY = Min(this.selY, this.y);
2826 int maxY = Max(this.selY, this.y);
2827 int minX = Min(this.selX, this.x);
2828 int maxX = Max(this.selX, this.x);
2830 FindMouse(this.mouseX - this.space.w / 2, this.mouseY, &x, &y, null, false);
2832 if(maxX != minX || maxY != minY)
2834 if(y > minY && y < maxY)
2835 mouseOnSelection = true;
2836 else if(y == minY && y == maxY)
2837 mouseOnSelection = (x < maxX && x >= minX);
2841 mouseOnSelection = (x >= this.selX);
2842 else if(y == this.y)
2843 mouseOnSelection = (x >= this.x);
2848 mouseOnSelection = (x < this.selX);
2849 else if(y == this.y)
2850 mouseOnSelection = (x < this.x);
2853 return mouseOnSelection;
2856 void UpdateCaretPosition(bool setCaret)
2860 if(mouseMove || !style.noCaret)
2862 int max = this.mouseMove ? this.dropX : this.x;
2863 int y = this.mouseMove ? this.dropY : this.y;
2864 EditLine line = this.mouseMove ? this.dropLine : this.line;
2866 if(!(style.freeCaret))
2867 max = Min(max, line.count);
2869 if(FontExtent && display)
2871 for(c = 0; c < max; )
2880 for(len = 0; c < Min(max, line.count); c += numBytes)
2882 ch = line.buffer[c];
2883 numBytes = UTF8_NUM_BYTES(ch);
2885 if(ch == ' ' || ch == '\t')
2892 if(!len && ch == ' ')
2897 else if(!len && ch == '\t')
2899 w = (tabSize * space.w) - (x % (tabSize * space.w));
2903 FontExtent(display, this.font, line.buffer + start, len, &w, null);
2915 caretY = y * this.space.h;
2917 SetCaret(x + XOFFSET-2, y * space.h + YOFFSET, space.h);
2924 // TOFIX: Mismatch between NotifyCaretMove() and NotifyDropped() / GoToPosition()
2925 NotifyCaretMove(master, this, y + 1, x + 1);
2931 void SelectionEnables()
2933 if((x != selX || y != selY) && !selection)
2937 itemEditCut.disabled = false;
2938 itemEditDelete.disabled = false;
2940 itemEditCopy.disabled = false;
2942 this.selection = true;
2944 else if((x == selX && y == selY) && selection)
2946 itemEditCut.disabled = true;
2947 itemEditCopy.disabled = true;
2948 itemEditDelete.disabled = true;
2950 this.selection = false;
2954 void SetSelectCursor()
2956 if(!inactive || !style.noSelect)
2959 cursor = guiApp.GetCursor(arrow);
2960 else if(this.mouseSelect)
2961 cursor = guiApp.GetCursor(iBeam);
2964 if(IsMouseOnSelection())
2965 cursor = guiApp.GetCursor(arrow);
2967 cursor = guiApp.GetCursor(iBeam);
2972 int AdjustXPosition(EditLine line, int position, bool half, int * px, int max, int sc)
2975 int x = px ? *px : 0;
2981 if(c < Min(max, line.count))
2985 for(len = 0; c < Min(max, line.count); c += numBytes)
2987 ch = line.buffer[c];
2988 numBytes = UTF8_NUM_BYTES(ch);
2990 if(ch == ' ' || ch == '\t')
2997 if(!len && ch == ' ')
3002 else if(!len && ch == '\t')
3004 w = (tabSize * space.w) - (x % (tabSize * space.w));
3008 FontExtent(display, font, line.buffer + start, len, &w, null);
3012 if(style.freeCaret && c < max)
3021 if(x + (((half && len == 1) ? (w / 2) : w)) >= position)
3026 int a = start + len;
3029 while(a > 0 && !UTF8_IS_FIRST(line.buffer[--a]));
3033 FontExtent(display, font, line.buffer + start, a - start, &w, null);
3036 if(position > x + (half ? ((w + lastW) / 2) : lastW)) break;
3040 return Min(this.maxLineSize - 1, start + len);
3046 void SetCursorToViewX()
3048 bool selecting = this.x != selX || y != selY;
3050 // Horizontal Adjustment
3052 int c = AdjustXPosition(line, viewX, false, &x, MAXINT, 0);
3057 c = AdjustXPosition(line, viewX + clientSize.w - 1, false, &x, MAXINT, c);
3069 UpdateCaretPosition(false);
3075 void SetCursorToViewY()
3078 EditLine oldLine = this.line;
3080 bool selecting = this.x != this.selX || this.y != this.selY;
3082 numLines = clientSize.h / this.space.h;
3084 // Vertical Adjustment
3085 if(this.viewY > this.y)
3087 this.y = this.viewY;
3088 this.line = this.viewLine;
3091 if(this.viewY + numLines <= this.y)
3095 this.y = this.viewY-1;
3096 for(c = 0, line = this.viewLine; line && c<numLines; line = line.next, c++)
3103 if(this.line != oldLine)
3105 this.x = AdjustXPosition(this.line, caretX, true, null, MAXINT, 0);
3113 this.selLine = this.line;
3116 UpdateCaretPosition(false);
3123 bool SaveFile(const char * fileName)
3125 File f = eFile_Open(fileName, FO_WRITE);
3129 eWindow_SetModified(false);
3130 eInstance_Delete(f);
3137 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
3141 if(!style.multiLine)
3143 x = (active && this.active && !style.readOnly) ? line.count : 0;
3146 SetViewToCursor(true);
3151 if(!active && modified)
3154 if(!NotifyModified(master, this))
3157 *goOnWithActivation = false;
3164 if(timer) timer.Stop();
3166 mouseSelect = false;
3174 int aw = maxLength + 12, ah = Max(lineCount, 1) * space.h + 2;
3175 int nw = minClientSize.w, nh = minClientSize.h, xw = maxClientSize.w, xh = maxClientSize.h;
3176 clientSize = { nw && aw < nw ? nw : xw && aw > xw ? xw : aw, nh && ah < nh ? nh : xh && ah > xh ? xh : ah };
3179 bool OnResizing(int *w, int *h)
3185 *w = space.h * 80 / 14;
3189 void OnResize(int w, int h)
3192 if(!hasHorzScroll && !hasVertScroll && viewLine)
3193 SetViewToCursor(true);
3195 //if(!hasHorzScroll && !hasVertScroll && viewLine)
3197 SetViewToCursor(true);
3202 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
3204 if(style.readOnly) return true;
3205 // We really shouldn't be pasting here, Unix middle button paste is for the selection (not the clipboard), good for the terminal
3206 // Middle button already serves as a dragger as well.
3211 bool OnRightButtonDown(int x, int y, Modifiers mods)
3213 this.rightButtonDown = true;
3218 bool OnRightButtonUp(int x, int y, Modifiers mods)
3221 if(!parent.inactive && rightButtonDown)
3224 Menu contextMenu { };
3226 MenuItem { contextMenu, $"Cut\tCtrl+X", t, NotifySelect = itemEditCut.NotifySelect, disabled = !selection || style.readOnly };
3227 MenuItem { contextMenu, $"Copy\tCtrl+C", c, NotifySelect = itemEditCopy.NotifySelect, disabled = !selection };
3228 MenuItem { contextMenu, $"Paste\tCtrl+V", p, NotifySelect = itemEditPaste.NotifySelect, disabled = style.readOnly };
3229 MenuItem { contextMenu, $"Delete\tDel", d, NotifySelect = itemEditDelete.NotifySelect, disabled = !selection || style.readOnly };
3230 MenuDivider { contextMenu };
3231 MenuItem { contextMenu, $"Select All\tCtrl+A", a, NotifySelect = itemEditSelectAll.NotifySelect };
3233 popup = PopupMenu { master = this, menu = contextMenu,
3235 nonClient = true, interim = false, parent = parent,
3236 position = { x + clientStart.x + parent.clientStart.x + position.x, y + cientStart.y + parent.sy + clientStart.y + position.y };
3238 position = { x + clientStart.x + absPosition.x - guiApp.desktop.position.x, y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
3242 rightButtonDown = false;
3246 bool OnLeftButtonDown(int mx, int my, Modifiers mods)
3251 if(style.noSelect) return true;
3253 // Should we have a separate 'selectOnActivate' style?
3254 if(!mods.isActivate || (style.readOnly && style.multiLine))
3260 mouseX = mx - XOFFSET;
3263 FindMouse(mouseX, mouseY, &x, &y, &line, true);
3265 //PrintLn("OnLeftButtonDown: ", x, ", ", y);
3271 else if(IsMouseOnSelection() && !mods.isActivate)
3281 if(!mouseMove && !wordSelect && (!mods.isActivate || style.multiLine))
3283 if(mods.shift && !mods.isActivate)
3304 UpdateCaretPosition(true);
3305 // Return false because DataBoxes automatically set EditBox editor's clickThrough to true for MouseMove events
3306 // ( for tool tips -- see 95ee4962c4c7bc3fe0a04aa6a4f98cacada40884)
3310 bool OnLeftButtonUp(int x, int y, Modifiers mods)
3314 mouseSelect = false;
3325 FindMouse(mouseX, mouseY, &x, &y, &line, true);
3327 //PrintLn("MouseMove: ", x, ", ", y);
3333 mouseMove = IsMouseOnSelection();
3337 int size = SelSize();
3340 char * text = new char[size+1];
3344 GetSel(text, false);
3346 if(Max(selY, this.y) == dropY)
3350 if(this.dropX > this.selX)
3351 moveX = this.x - this.selX;
3355 if(this.dropX > this.x)
3356 moveX = this.selX - this.x;
3360 recordUndoEvent = true;
3362 this.dropX -= moveX;
3363 this.selX = this.x = this.dropX;
3364 this.selY = this.y = this.dropY;
3365 this.selLine = this.line = this.dropLine;
3367 recordUndoEvent = false;
3369 SetViewToCursor(true);
3374 byte * c = ((EditBox)this).multiLineContents, * c2;
3375 int l1 = c ? strlen(c) : 0, l2;
3378 c2 = ((EditBox)this).multiLineContents;
3379 l2 = c2 ? strlen(c2) : 0;
3380 if(l1 != l2 || (l1 && strcmp(c, c2)))
3410 FindMouse(mouseX, mouseY, &x, &y, &line, true);
3412 //PrintLn("Dropped: ", x, ", ", y);
3414 NotifyDropped(master, this, x, y);
3418 // Return false because DataBoxes automatically set EditBox editor's clickThrough to true for MouseMove events
3419 // ( for tool tips -- see 95ee4962c4c7bc3fe0a04aa6a4f98cacada40884)
3423 bool OnMouseMove(int mx, int my, Modifiers mods)
3429 if(mods != -1 && mods.isSideEffect)
3434 if(style.noSelect) return true;
3435 if(wordSelect) return true;
3436 mouseX = mx - XOFFSET;
3439 needScroll = FindMouse(this.mouseX, this.mouseY, &x, &y, &line, true);
3441 if(this.mouseMove || this.mouseSelect)
3450 ((style.hScroll) || (style.vScroll)))
3457 DirtyLine(this.dropY);
3460 DirtyLine(this.dropY);
3461 this.dropLine = line;
3462 SetViewToCursor(true);
3464 //PrintLn("MouseMove: ", "dropX = ", x, ", dropY = ", y);
3467 else if(this.mouseSelect)
3469 DirtyLine(this.selY);
3476 SetViewToCursor(true);
3479 //PrintLn("MouseSelect: ", "x = ", x, ", y = ", y);
3486 bool OnLeftDoubleClick(int mx, int my, Modifiers mods)
3491 //PrintLn("OnLeftDoubleClick: ", mx, ", ", my, ", mods = ", mods);
3495 if(style.noSelect) return true;
3496 FindMouse(mx, my, &x, &y, &line, false);
3497 if(!NotifyDoubleClick(master, this, line, mods))
3504 for(c = x; c >= 0; c--)
3507 while(c > 0 && !UTF8_IS_FIRST(line.buffer[c])) c--;
3508 ch = UTF8_GET_CHAR(line.buffer + c, numBytes);
3515 for(c = start; c<line.count; c += numBytes)
3517 unichar ch = UTF8_GET_CHAR(line.buffer + c, numBytes);
3518 if(!ch || !IS_ALUNDER(ch))
3528 this.line = this.selLine = line;
3529 this.wordSelect = (c != start);
3540 Menu fileMenu { menu, "File", F };
3541 saveDialog = fileDialog;
3542 MenuItem { fileMenu, $"Save\tCtrl+S", S, CtrlS, NotifySelect = MenuFileSave };
3543 MenuItem { fileMenu, $"Save As...", A, NotifySelect = MenuFileSaveAs };
3545 if(style.autoSize) AutoSize();
3553 FontExtent(display, font, " ", 1, (int *)&space.w, (int *)&space.h);
3554 FontExtent(display, font, "W", 1, (int *)&large.w, (int *)&large.h);
3556 space.w = Max(space.w, 1);
3557 large.w = Max(large.w, 1);
3558 space.h = Max(space.h, 1);
3559 large.h = Max(large.h, 1);
3563 for(line = lines.first; line; line = line.next)
3564 ComputeLength(line);
3569 SetViewToCursor(true);
3577 bool OnLoadGraphics()
3579 FontExtent = Display::FontExtent;
3582 // UpdateCaretPosition(true);
3586 void OnUnloadGraphics()
3591 bool OnKeyHit(Key key, unichar ch)
3593 bool shift = (key.shift) ? true : false;
3595 //PrintLn("OnKeyHit: code = ", key.code, ", mods = ", key.modifiers, ", ch = ", (int)ch);
3597 if(!ch && !key.alt && !key.ctrl)
3599 key.code = (SmartKey)key.code;
3601 else if(!ch && key.alt)
3604 switch(key.code) //(ch || key.alt || key.ctrl) ? key.code : (Key)(SmartKey)key.code)
3607 if(style.readOnly) break;
3608 if(style.stuckCaret) GoToEnd(true);
3609 if(!(style.freeCaret))
3611 this.x = Min(this.x, this.line.count);
3617 EditLine line = this.line;
3619 for(y = this.y; y>= 0; y--)
3621 c = (y == this.y) ? (Min(this.x-1, line.count-1)) : line.count-1;
3623 // Slow down when going on lines...
3624 if(y != this.y) break;
3628 //if(this.line.buffer[c] != '\t' && this.line.buffer[c] != ' ')
3629 if(IS_ALUNDER(line.buffer[c]))
3634 if(!IS_ALUNDER(line.buffer[c]))
3636 //if(this.line.buffer[c] == '\t' || this.line.buffer[c] == ' ')
3651 _DelCh(line, y, c+1, this.line, this.y, this.x, true, false, null);
3652 this.x = this.selX = Min(c+1, line.count);
3653 this.y = this.selY = y;
3654 this.line = this.selLine = line;
3655 SetViewToCursor(true);
3666 if(style.readOnly) break;
3667 if(style.stuckCaret) break;
3676 if(this.line != this.selLine || this.x != this.selX)
3679 SetViewToCursor(true);
3684 EditLine line1 = this.line, line2 = this.line;
3685 int x1, y1 = this.y, x2, y2 = this.y;
3686 if(!style.freeCaret)
3688 this.selX = this.x = Min(this.x, this.line.count);
3693 if(x1 < line1.count)
3699 char * buffer = line1.buffer;
3700 for(i = x1; i < line1.count; i++)
3702 if(!IS_ALUNDER(buffer[i]))
3706 for(; i < line1.count; i++)
3708 // Delete trailing whitespace
3709 if(IS_ALUNDER(buffer[i]))
3719 // Avoid creating trailing spaces if there is no content on next line
3722 if(line2 && !line2.count)
3727 _DelCh(line1, y1, x1, line2, y2, x2, false, false, null);
3728 SetViewToCursor(true);
3737 if(!key.alt && !key.ctrl)
3741 bool stuffAfter = false;
3744 /*bool resetX = false;
3747 if(style.stuckCaret) GoToEnd(true);
3748 if(style.readOnly) break;
3749 if(!(style.multiLine)) break;
3751 for(c = 0; c<this.line.count && c<this.x; c++)
3753 if(this.line.buffer[c] == '\t')
3754 position += this.tabSize - (position % this.tabSize);
3755 else if(this.line.buffer[c] == ' ')
3761 // Prevent adding trailing spaces if at the head of a line
3762 /*if(c && c == this.x && c < this.line.count && this.x == this.selX && this.y == this.selY)
3774 if(this.x < this.line.count)
3777 //If last character is a { indent one tab
3778 c = Min(x, line.count);
3779 if(c > 0 && line.buffer[c - 1] == '{')
3781 //Except if the next non space character is a }
3782 bool indent = false;
3784 for(i = c; i <= this.line.count; i++) // indent will be set to true on nul terminating char
3785 if(this.line.buffer[i] != ' ' && this.line.buffer[i] != '\t')
3787 if(this.line.buffer[i] != '}')
3792 position += this.tabSize;
3795 addString = new char[position + 2];
3796 addString[len++] = '\n';
3797 addString[len] = '\0';
3799 if(stuffAfter || !style.freeCaret)
3801 for(c = 0; c<position; )
3803 if(style.useTab && c + this.tabSize <= position)
3805 addString[len++] = '\t';
3810 addString[len++] = ' ';
3814 addString[len] = '\0';
3816 recordUndoEvent = true;
3819 EditLine prevLine = this.line.prev;
3822 // Nuke spaces if that is all that is left on previous line
3824 char * buffer = prevLine.buffer;
3825 for(i = 0; i < prevLine.count; i++)
3826 if(buffer[i] != ' ' && buffer[i] != '\t')
3828 if(i == prevLine.count)
3829 DelCh(prevLine, this.y - 1, 0, prevLine, this.y - 1, prevLine.count, false);
3833 this.x = this.selX = backX;
3836 else */if(!stuffAfter && style.freeCaret)
3838 this.x = this.selX = position;
3842 SetViewToCursor(true);
3845 recordUndoEvent = false;
3853 if(style.stuckCaret) break;
3854 if(!(style.freeCaret))
3856 this.x = Min(this.x, this.line.count);
3857 this.selX = Min(this.selX, this.selLine.count);
3860 if(!shift) SelDirty();
3863 bool foundAlpha = false;
3866 EditLine line, lastLine = null;
3867 int lastC = 0, lastY = 0;
3869 for(line = this.line; (line && !found); line = line.prev, y--)
3874 if(this.x == 0 && line != this.line)
3883 if(line == this.line) start = this.x -1; else start = line.count-1;
3884 start = Min(start, line.count-1);
3886 for(c = start; c >= 0;)
3889 unichar ch = UTF8_GET_CHAR(line.buffer + c, numBytes);
3907 byte ch = line.buffer[c];
3908 if(UTF8_IS_FIRST(ch)) break;
3912 // No next word found,
3913 if(!found && ( this.x > 0 || (!line.count && this.x)))
3927 this.line = lastLine;
3938 byte * buffer = (byte *)line.buffer;
3941 byte ch = buffer[x];
3942 if(UTF8_IS_FIRST(ch)) break;
3959 if(!shift) _Deselect();
3960 SetViewToCursor(true);
3966 if(style.stuckCaret) break;
3967 if(!(style.freeCaret))
3969 this.x = Min(this.x, this.line.count);
3970 this.selX = Min(this.selX, this.selLine.count);
3973 if(!shift) SelDirty();
3974 if(!shift && (this.x != this.selX || this.y != this.selY));
3977 bool onAChar = false;
3978 if(this.selX != this.x || this.selY != this.y)
3980 if(this.x<this.line.count)
3981 if(this.line.buffer[this.x] != '\t' && this.line.buffer[this.x] !=' ')
3983 if(key.shift && onAChar &&
3984 ((this.y > this.selY)||((this.selY == this.y)&&(this.x >= this.selX))))
3986 bool foundAlpha = false;
3988 EditLine line = null, lastLine = null;
3990 int lastC = 0, lastY = 0, lastNumBytes = 0;
3992 for(line = this.line; (line && !found); line = line.next, y++)
3994 int start = (line == this.line) ? this.x : 0;
3998 for(c = start; c < line.count && (ch = UTF8_GET_CHAR(line.buffer + c, numBytes)); c += numBytes)
4004 lastNumBytes = numBytes;
4014 if(!found && (c != this.x || line != this.line))
4027 this.x = lastC + lastNumBytes;
4029 this.line = lastLine;
4036 bool foundAlpha = false;
4041 for(line = this.line; (line && !found); line = line.next, y++)
4043 int start = (line == this.line) ? this.x : 0;
4047 for(c = start; c < line.count && (ch = UTF8_GET_CHAR(line.buffer + c, numBytes)); c += numBytes)
4063 // No next word found,
4064 if(!found && (c != this.x || line != this.line))
4068 this.x = line.count;
4080 if(x < line.count || (style.freeCaret && line.count < maxLineSize))
4084 byte * buffer = (byte *)line.buffer;
4087 byte ch = buffer[x];
4088 if(UTF8_IS_FIRST(ch)) break;
4109 if(!shift) _Deselect();
4110 SetViewToCursor(true);
4117 if(!style.vScroll || hasVertScroll) break;
4123 if(style.stuckCaret) break;
4125 if(!shift) SelDirty();
4135 this.x = AdjustXPosition(line, caretX, true, null, MAXINT, 0);
4139 if(!shift) _Deselect();
4141 SetViewToCursor(false);
4144 if(caretY == this.y * space.h)
4150 if(!style.freeCaret)
4151 this.x = Min(this.x, line.count);
4161 int sx = 0, sy = this.y * space.h;
4162 char * text = line.text;
4163 int maxW = clientSize.w - sx;
4164 display.FontExtent(font, " ", 1, null, &th);
4168 int startPos = textPos;
4171 bool lineComplete = false;
4173 if(!style.wrap && caretY == MAXINT)
4176 //textPos = line.count;
4177 //lineComplete = true;
4180 for(; (style.freeCaret || textPos < line.count) && !lineComplete;)
4184 char * nextSpace = (textPos < line.count) ? strchr(text + textPos, ' ') : (text + textPos);
4187 len = (nextSpace - (text + textPos));
4189 len = line.count - textPos;
4191 if(textPos < line.count)
4193 display.FontExtent(font, text + textPos, len, &w, null);
4195 if(nextSpace) { w += space.w; len++; }
4197 if(style.wrap && x + width + w > maxW && x > 0)
4199 lineComplete = true;
4209 if((!style.freeCaret && textPos >= line.count) || (sy == caretY - th && caretX <= x + width + sx))
4213 while(this.x > 0 && x + sx > caretX && this.x > startPos)
4216 if(this.x > line.count)
4219 while(this.x > 0 && !UTF8_IS_FIRST(text[--this.x]));
4220 len = this.x - startPos;
4221 display.FontExtent(font, text + startPos, len, &x, null);
4225 if(!shift) _Deselect();
4227 SetViewToCursor(false);
4231 if(sy == caretY - th || textPos >= line.count)
4233 if(textPos >= line.count)
4235 int c = textPos - 1;
4236 while(c > 0 && text[c] == ' ') c--;
4240 this.x = line.count;
4243 if(!shift) _Deselect();
4245 SetViewToCursor(false);
4250 } while(textPos < line.count);
4253 if(!shift) _Deselect();
4255 SetViewToCursor(false);
4264 int x = AdjustXPosition(this.line, this.line.prev, true, null, MAXINT, 0);
4265 if(!shift) SelDirty();
4266 this.line = this.line.prev;
4272 if(!shift) _Deselect();
4276 SetViewToCursor(false);
4282 return style.multiLine ? false : true;
4286 if(!style.vScroll || hasVertScroll)
4293 if(style.stuckCaret) break;
4298 int sx = 0, sy = this.y * this.space.h;
4299 int maxW = clientSize.w - sx;
4300 char * text = line.buffer;
4303 if(!shift) SelDirty();
4309 if(AdjustXPosition(line, maxW, this.x, line.count, true, null, MAXINT, 0) <= line.count)
4319 this.x = AdjustXPosition(line, caretX, true, null, MAXINT, 0);
4323 if(!shift) _Deselect();
4325 SetViewToCursor(false);
4328 while(!textPos || (style.freeCaret || textPos<line.count))
4330 int startPos = textPos;
4333 bool lineComplete = false;
4334 if(!style.wrap && sy <= caretY)
4336 textPos = line.count;
4337 lineComplete = true;
4339 for(; (style.freeCaret || textPos<line.count) && !lineComplete;)
4343 char * nextSpace = (textPos < line.count) ? strchr(text + textPos, ' ') : (text + textPos);
4346 len = (nextSpace - (text + textPos));
4348 len = line.count - textPos;
4350 if(textPos < line.count)
4352 display.FontExtent(font, text + textPos, len, &w, &th);
4354 if(nextSpace) { w += space.w; len++; }
4355 if(style.wrap && x + width + w > maxW && x > 0)
4357 lineComplete = true;
4367 if(sy > caretY && ((!style.freeCaret && textPos >= line.count) || caretX <= x + width + sx))
4371 while(this.x > 0 && x + sx > caretX && textPos > startPos)
4374 if(this.x > line.count)
4377 while(this.x > 0 && !UTF8_IS_FIRST(text[--this.x]));
4379 len = this.x - startPos;
4380 display.FontExtent(font, text + startPos, len, &x, null);
4383 if(!shift) _Deselect();
4386 SetViewToCursor(false);
4392 this.x = line.count;
4395 if(!shift) _Deselect();
4398 SetViewToCursor(false);
4401 else if(textPos >= line.count && line.next)
4407 sy = this.y * this.space.h;
4408 sx = 0; //textBlock.startX;
4414 sx = 0; //textBlock.startX;
4422 this.x = Min(this.x, line.count);
4423 //int x = AdjustXPosition(this.line, this.line.next, true, null, MAXINT, 0);
4425 if(!shift) _Deselect();
4428 if(this.selX != this.x || this.selY != this.y)
4431 SetViewToCursor(false);
4438 int x = AdjustXPosition(this.line, this.line.next, true, null, MAXINT, 0);
4439 if(!shift) SelDirty();
4440 this.line = this.line.next;
4444 if(!shift) _Deselect();
4447 if(this.selX != this.x || this.selY != this.y)
4455 return style.multiLine ? false : true;
4458 if(style.stuckCaret) break;
4459 if(!style.multiLine && key.ctrl) break;
4460 if(!(style.freeCaret))
4461 this.selX = Min(this.selX, this.selLine.count);
4463 if(!shift) SelDirty();
4466 this.line = this.lines.first;
4467 if(this.y != 0 || this.x != 0)
4477 EditLine line = this.line;
4479 for(c=0; line.buffer[c]; c++)
4480 if(line.buffer[c] != ' ' && line.buffer[c] != '\t')
4482 if(overwrite || (shift && (c != 0 || this.x)))
4491 if(overwrite || (shift && this.x != 0))
4497 if(!shift) _Deselect();
4498 SetViewToCursor(true);
4504 if(style.stuckCaret) break;
4505 if(!style.multiLine && key.ctrl) break;
4506 if(!style.freeCaret)
4507 this.selX = Min(this.selX, this.selLine.count);
4509 if(!shift) SelDirty();
4514 else if(this.x != this.line.count)
4516 this.x = this.line.count;
4517 if(overwrite || shift)
4521 if(!shift) _Deselect();
4522 SetViewToCursor(true);
4527 if(style.tabKey && !key.ctrl)
4529 if(this.selY != this.y && style.tabSel)
4531 EditLine firstLine, lastLine;
4535 // Do multi line selection tabbing here
4536 if(this.selY < this.y)
4538 firstLine = this.selLine;
4539 lastLine = this.line;
4545 // Selecting going up
4546 firstLine = this.line;
4547 lastLine = this.selLine;
4554 for(line = firstLine; line; line = line.next, y++)
4556 if(line != lastLine || x)
4560 BufferLocation before = { line, y, 0 }, after = { line, y, 0 };
4562 for(c=0; c<line.count && lastC < this.tabSize; c++, lastC++)
4564 if(line.buffer[c] == '\t')
4569 else if(line.buffer[c] != ' ')
4574 NotifyCharsDeleted(master, this, &before, &after, this.pasteOperation);
4577 int len = GetText(null, line, y, 0, line, y, lastC, false, false);
4578 char * string = new char[len];
4579 DelTextAction action { y1 = y, x1 = 0, y2 = y, x2 = lastC, string = string, placeAfter = true };
4580 GetText(string, line, y, 0, line, y, lastC, false, false);
4583 memmove(line.buffer,line.buffer+lastC,line.size-lastC);
4584 if(!line.AdjustBuffer(line.count-lastC))
4590 if(line == lastLine) break;
4595 for(line = firstLine; line; line = line.next, y++)
4599 if(line != lastLine || x)
4603 if(line.count + 1 <= this.maxLineSize)
4605 BufferLocation before = { line, y, 0 }, after = { line, y, 1 };
4607 if(!line.AdjustBuffer(line.count+1))
4610 NotifyCharsAdded(master, this, &before, &after, this.pasteOperation);
4612 AddCharAction action { ch = '\t', x = 0, y = y };
4616 memmove(line.buffer+1,line.buffer,line.size-1);
4618 line.buffer[0] = '\t';
4623 if(line.count + this.tabSize <= this.maxLineSize)
4626 BufferLocation before = { line, y, 0 }, after = { line, y, this.tabSize };
4627 NotifyCharsAdded(master, this, &before, &after, this.pasteOperation);
4629 if(!line.AdjustBuffer(line.count+this.tabSize))
4633 char * string = new char[this.tabSize + 1];
4634 memset(string, ' ', this.tabSize);
4635 string[this.tabSize] = '\0';
4636 Record(AddTextAction { string = string, x1 = 0, y1 = y, x2 = this.tabSize, y2 = y });
4639 memmove(line.buffer+this.tabSize,line.buffer,line.size-(this.tabSize));
4640 line.count+=this.tabSize;
4641 for(c=0; c<this.tabSize; c++)
4642 line.buffer[c] = ' ';
4648 if(line == lastLine) break;
4651 ComputeLength(maxLine);
4663 char * addString = new char[this.tabSize + 1];
4665 if(!(style.freeCaret))
4667 this.x = Min(this.x, this.line.count);
4671 start = Min(this.x, this.selX);
4672 for(c=start; ((c == start) || ((c) % this.tabSize)); c++)
4674 addString[len++] = ' ';
4682 SetViewToCursor(true);
4691 if(!(style.hScroll) || hasHorzScroll) break;
4692 if(this.viewX < this.maxLength)
4694 //this.viewX+=this.space.w*this.tabSize;
4696 SetScrollPosition((this.viewX + this.space.w*this.tabSize), this.viewY * this.space.h);
4703 if(!shift) _Deselect();
4715 if(!(style.hScroll) || hasHorzScroll) break;
4718 //this.viewX-=this.space.w*this.tabSize;
4719 //this.viewX = Max(this.viewX,0);
4721 SetScrollPosition((this.viewX-this.space.w*this.tabSize), this.viewY * this.space.h);
4722 // SetCursorToView();
4729 if(!shift) _Deselect();
4742 else if(!style.readOnly)
4746 if(!(style.readOnly))
4752 this.overwrite ^= 1;
4753 UpdateCaretPosition(true);
4758 NotifyOvrToggle(master, this, this.overwrite);
4770 if(style.noSelect) break;
4773 //Save current view position
4774 int tempX = this.viewX;
4775 int tempY = this.viewY;
4779 this.selLine = this.lines.first;
4780 this.y = this.lineCount-1;
4781 this.line = this.lines.last;
4782 this.x = this.line.count;
4785 SetViewToCursor(true);
4787 //Restore previous view position
4788 SetScrollPosition(tempX, tempY * this.space.h);
4794 // TOCHECK: Was there any good reason why we weren't returning false here?
4795 return false; // break;
4800 if(!(style.readOnly))
4808 if(style.readOnly) break;
4814 if(style.readOnly) break;
4819 if(style.readOnly) break;
4823 if(style.readOnly) break;
4827 if(style.readOnly) break;
4828 if(key.shift && key.code == rightBracket)
4830 //Only indent back if you are exactly at one tab.
4832 //bool whitespace = true;
4837 int indentwidth = 0;
4838 EditLine line = this.line;
4840 //Only remove one tab if there is nothing else on the line.
4841 for(i = 0; i < this.line.count; i++)
4843 if(this.line.buffer[i] != ' ' && this.line.buffer[i] != '\t')
4857 for(pos = line.count - 1; pos >= 0; pos--)
4859 char c = line.buffer[pos];
4863 indentwidth += this.tabSize;
4865 //Counting backwards, so when you find a character, indentation is reset
4875 //Place the } to get an undo:
4878 this.x = this.line.count;
4882 putsize = indentwidth;
4884 putsize = indentwidth / this.tabSize + indentwidth % this.tabSize;
4886 newline = new char[putsize+2];
4887 newline[putsize] = '}';
4888 newline[putsize+1] = '\0';
4892 for(; i < indentwidth / this.tabSize; i++)
4894 for(;i < putsize; i++)
4903 else if(!key.ctrl && !key.alt && ch != 128 && ch >= 32)
4915 void OnHScroll(ScrollBarAction action, int position, Key key)
4918 //PrintLn("OnHScroll: ", action, ", pos = ", position, ", key = ", key);
4920 this.viewX = position;
4921 if(action != setRange)
4923 if(!this.mouseMove && style.cursorFollowsView)
4930 void OnVScroll(ScrollBarAction action, int position, Key key)
4932 int oldViewY = this.viewY;
4935 //PrintLn("OnVScroll: ", action, ", pos = ", position, ", key = ", key);
4937 position /= this.space.h;
4939 if(position < this.viewY)
4941 for(; position < this.viewY && this.viewLine.prev; this.viewLine = this.viewLine.prev, this.viewY--);
4942 style.recomputeSyntax = true;
4944 else if(position > this.viewY)
4946 EditLine oldViewLine = viewLine;
4947 for(; position > this.viewY && this.viewLine.next; this.viewLine = this.viewLine.next, this.viewY++);
4948 FigureStartSyntaxStates(oldViewLine, false);
4951 if(action != setRange)
4953 if(!this.mouseMove && style.cursorFollowsView && !SelSize()) SetCursorToViewY();
4956 if(this.x != this.selX || this.y != this.selY)
4960 Scroll(0, (this.viewY - oldViewY) * this.space.h);
4963 int numLines = clientSize.h / this.space.h;
4965 if(Abs(this.viewY - oldViewY) < numLines)
4968 if(this.viewY > oldViewY)
4970 for(y = oldViewY; y <this.viewY; y++)
4971 DirtyLine(y + numLines);
4975 for(y = this.viewY; y <oldViewY; y++)
4976 DirtyLine(y + numLines);
4981 // Fix dirt of stuff before first line...
4982 if(this.viewY - oldViewY > 0)
4984 Box box { 0,0, clientSize.w-1, YOFFSET-1 };
4991 bool _AddCh(unichar ch, int * addedSpacesPtr, int * addedTabsPtr, int * xAdjustmentPtr)
4994 int length, endX = 0;
4996 ReplaceTextAction replaceAction = null;
4997 AddCharAction addCharAction = null;
4998 int addedSpaces = 0, addedTabs = 0, xAdjustment = 0;
5000 if(ch == '\r') return true;
5001 if(style.stuckCaret /*|EES_READONLY)*/ )
5004 if(ch == '\n' && !(style.multiLine) && this.line) return false;
5006 if(!undoBuffer.dontRecord)
5008 if(selX != x || selY != y)
5013 int len = GetText(null, selLine, selY, selX, this.line, y, x, false, false);
5014 oldString = new char[len];
5015 UTF32toUTF8Len(&ch, 1, buffer, 4);
5016 newString = CopyString(buffer);
5017 GetText(oldString, selLine, selY, selX, this.line, y, x, false, false);
5019 replaceAction = ReplaceTextAction { newString = newString, oldString = oldString, placeAfter = false };
5020 if(selY < y || (selY == y && selX < x))
5022 replaceAction.x1 = selX;
5023 replaceAction.y1 = selY;
5024 replaceAction.x2 = x;
5025 replaceAction.y2 = y;
5029 replaceAction.x1 = x;
5030 replaceAction.y1 = y;
5031 replaceAction.x2 = selX;
5032 replaceAction.y2 = selY;
5034 Record(replaceAction);
5035 undoBuffer.dontRecord++;
5039 addCharAction = AddCharAction { y = y, x = x, ch = ch };
5040 Record(addCharAction);
5046 DelSel(&addedSpaces);
5047 if(this.lineCount+1 > this.maxLines)
5050 Emptyline(this.lines.first,0);
5054 if(!(style.autoSize && (!maxClientSize.h || maxClientSize.h > clientSize.h + this.space.h)) && !(style.vScroll))
5056 // Make sure it fits, but we need a default line is this.font is too big for window
5057 if(this.space.h * (this.lineCount+1) > clientSize.h && this.line)
5060 if((this.y >= 0) && this.y < this.viewY)
5065 line = EditLine { };
5068 lines.Insert(this.line, line);
5069 line.editBox = this;
5075 // If we're displacing the lines from a current line ...
5078 if(this.line.buffer)
5081 if(this.line.count < endX) endX = this.line.count;
5082 length = this.line.count - endX;
5085 if(!line.AdjustBuffer(length))
5089 if(this.line.buffer)
5091 CopyBytes(line.buffer,this.line.buffer+endX, length+1);
5093 if(endX > 4000 || endX < 0)
5096 this.line.count = endX;
5097 this.line.buffer[this.line.count] = '\0';
5098 this.line.AdjustBuffer(this.line.count);
5099 ComputeLength(this.line);
5103 BufferLocation before = { this.line, this.y, this.x }, after;
5108 line.count = length;
5111 if(length > 4000 || length < 0)
5114 ComputeLength(this.line);
5119 line.buffer[line.count] = '\0';
5122 after.line = this.line, after.y = this.y, after.x = this.x;
5124 NotifyCharsAdded(master, this, &before, &after, this.pasteOperation);
5130 int count = UTF32toUTF8Len(&ch, 1, string, 5);
5131 DelSel(&addedSpaces);
5132 result = AddToLine(string, count, false, addedSpaces ? null : &addedSpaces, &addedTabs, &xAdjustment);
5133 if(addedSpacesPtr) *addedSpacesPtr = addedSpaces;
5134 if(addedTabsPtr) *addedTabsPtr = addedTabs;
5135 if(xAdjustmentPtr) *xAdjustmentPtr = xAdjustment;
5139 this.selLine = this.line;
5143 replaceAction.x3 = x;
5144 replaceAction.y3 = y;
5145 replaceAction.addedSpaces = addedSpaces;
5146 replaceAction.addedTabs = addedTabs;
5147 undoBuffer.dontRecord--;
5151 addCharAction.x -= addedTabs * (tabSize-1);
5152 addCharAction.addedSpaces = addedSpaces;
5153 addCharAction.addedTabs = addedTabs;
5160 /****************************************************************************
5162 ****************************************************************************/
5165 bool AddCh(unichar ch)
5167 return _AddCh(ch, null, null, null);
5172 this.modified = true;
5173 NotifyUpdate(master, this);
5174 modifiedDocument = true;
5177 void Delete(EditLine line1, int y1, int x1, EditLine line2, int y2, int x2)
5180 _DelCh(line1, y1, x1, line2, y2, x2, false, false, null);
5181 SetViewToCursor(true);
5189 itemEditUndo.disabled = undoBuffer.curAction == 0;
5190 itemEditRedo.disabled = undoBuffer.curAction == undoBuffer.count;
5196 if(savedAction == undoBuffer.curAction)
5198 modifiedDocument = false;
5200 NotifyUnsetModified(master, this);
5207 itemEditUndo.disabled = undoBuffer.curAction == 0;
5208 itemEditRedo.disabled = undoBuffer.curAction == undoBuffer.count;
5214 if(savedAction == undoBuffer.curAction)
5216 modifiedDocument = false;
5218 NotifyUnsetModified(master, this);
5222 void Record(UndoAction action)
5224 if(!undoBuffer.dontRecord)
5226 undoBuffer.Record(action);
5227 itemEditUndo.disabled = undoBuffer.curAction == 0;
5228 itemEditRedo.disabled = undoBuffer.curAction == undoBuffer.count;
5235 this.lines.first, 0,0,
5236 this.lines.last, this.lines.count-1, strlen(((EditLine)this.lines.last).buffer));
5239 void Select(EditLine line1, int y1, int x1, EditLine line2, int y2, int x2)
5244 this.selLine = line1 ? (EditLine)line1 : this.lines.first;
5245 this.x = line2 ? x2 : ((EditLine)this.lines.last).count;
5246 this.y = line2 ? y2 : (this.lineCount-1);
5247 this.line = line2 ? (EditLine)line2 : this.lines.last;
5250 SetViewToCursor(true);
5254 // TODO: Fix this vs modifiedDocument window property
5255 void SetModified(bool flag)
5259 this.modified = false;
5260 if(flag && !NotifyModified(master, this))
5261 this.modified = true;
5266 bool AddS(const char * string)
5273 int addedSpaces = 0, addedTabs = 0, xAdjustment = 0;
5274 AddTextAction action = null;
5275 ReplaceTextAction replaceAction = null;
5277 this.pasteOperation = true;
5279 if(style.stuckCaret /*|EES_READONLY)*/ )
5282 if(!undoBuffer.dontRecord)
5284 char * placeString = CopyString(string);
5285 if(!style.multiLine)
5289 for(i = 0; (ch = placeString[i]); i++)
5292 placeString[i] = '\0';
5293 placeString = renew placeString byte[i+1];
5298 if(selX != x || selY != y)
5302 int len = GetText(null, selLine, selY, selX, this.line, y, x, false, false);
5303 oldString = new char[len];
5304 newString = placeString;
5305 GetText(oldString, selLine, selY, selX, this.line, y, x, false, false);
5307 replaceAction = ReplaceTextAction { newString = newString, oldString = oldString, placeAfter = false };
5308 if(selY < y || (selY == y && selX < x))
5310 replaceAction.x1 = selX;
5311 replaceAction.y1 = selY;
5312 replaceAction.x2 = x;
5313 replaceAction.y2 = y;
5317 replaceAction.x1 = x;
5318 replaceAction.y1 = y;
5319 replaceAction.x2 = selX;
5320 replaceAction.y2 = selY;
5322 Record(replaceAction);
5326 if(string[0] == '\n')
5327 action = AddTextAction { y1 = y, x1 = Min(this.line.count, x), string = placeString };
5329 action = AddTextAction { y1 = y, x1 = x, string = placeString };
5337 undoBuffer.dontRecord++;
5338 DelSel(&addedSpaces);
5342 for(c = 0; string[c]; c++)
5344 if(string[c] == '\n' || string[c] == '\r')
5346 if(!AddToLine(line, count, true, addedSpaces ? null : &addedSpaces, addedTabs ? null : &addedTabs, xAdjustment ? null : &xAdjustment))
5351 if(string[c] == '\n')
5360 // Reset for next line
5364 if(string[c] == '\r' && *line == '\n')
5376 // Why was this here?
5379 // Add the line here
5381 if(!AddToLine(line,count,false, addedSpaces ? null : &addedSpaces, addedTabs ? null : &addedTabs, xAdjustment ? null : &xAdjustment))
5387 undoBuffer.dontRecord--;
5392 action.addedSpaces = addedSpaces;
5393 action.addedTabs = addedTabs;
5394 action.xAdjustment = xAdjustment;
5396 else if(replaceAction)
5398 replaceAction.y3 = y;
5399 replaceAction.x3 = x;
5400 replaceAction.addedSpaces = addedSpaces;
5401 replaceAction.addedTabs = addedTabs;
5402 replaceAction.xAdjustment = xAdjustment;
5405 UpdateCaretPosition(true);
5407 this.pasteOperation = false;
5420 DelCh(this.lines.first, 0, 0, this.lines.last, this.lineCount-1, ((EditLine)(this.lines.last)).count, true);
5421 SetViewToCursor(true);
5427 void PutCh(unichar ch)
5431 if((ch >= 32 /*&& ch <=126*/) || ch == '\n' || ch == '\t')
5432 //if((ch >= 32) || ch == '\n')
5434 int addedSpaces = 0, addedTabs = 0, xAdjustment = 0;
5435 ReplaceTextAction replaceAction = null;
5436 AddCharAction addCharAction = null;
5439 ch = (ch < 128) ? toupper(ch) : ch; // TODO: UNICODE TO UPPER
5441 if(this.overwrite && selX == x && selY == y && this.x < this.line.count)
5446 int len = GetText(null, line, y, x, line, y, x+1, false, false);
5447 oldString = new char[len];
5448 UTF32toUTF8Len(&ch, 1, buffer, 4);
5449 newString = CopyString(buffer);
5450 GetText(oldString, line, y, x, line, y, x+1, false, false);
5451 replaceAction = ReplaceTextAction { newString = newString, oldString = oldString, placeAfter = false };
5452 replaceAction.x1 = x;
5453 replaceAction.y1 = y;
5454 replaceAction.x2 = x+1;
5455 replaceAction.y2 = y;
5456 Record(replaceAction);
5458 undoBuffer.dontRecord++;
5459 DelCh(this.line, this.y, this.x, this.line, this.y, this.x+1, true);
5460 undoBuffer.dontRecord--;
5462 else if(!undoBuffer.dontRecord)
5464 if(selX != x || selY != y)
5469 int len = GetText(null, line, y, x, selLine, selY, selX, false, false);
5470 oldString = new char[len];
5471 UTF32toUTF8Len(&ch, 1, buffer, 4);
5472 newString = CopyString(buffer);
5473 GetText(oldString, line, y, x, selLine, selY, selX, false, false);
5474 replaceAction = ReplaceTextAction { newString = newString, oldString = oldString, placeAfter = true };
5475 if(selY < y || (selY == y && selX < x))
5477 replaceAction.x1 = selX;
5478 replaceAction.y1 = selY;
5479 replaceAction.x2 = x;
5480 replaceAction.y2 = y;
5484 replaceAction.x1 = x;
5485 replaceAction.y1 = y;
5486 replaceAction.x2 = selX;
5487 replaceAction.y2 = selY;
5489 Record(replaceAction);
5493 addCharAction = AddCharAction { y = y, x = x, ch = ch };
5494 Record(addCharAction);
5497 undoBuffer.dontRecord++;
5498 result = _AddCh(ch, &addedSpaces, &addedTabs, &xAdjustment);
5501 replaceAction.x3 = x;
5502 replaceAction.y3 = y;
5503 replaceAction.addedSpaces = addedSpaces;
5504 replaceAction.addedTabs = addedTabs;
5505 replaceAction.addedTabs = xAdjustment;
5509 addCharAction.addedSpaces = addedSpaces;
5510 addCharAction.addedTabs = addedTabs;
5511 addCharAction.xAdjustment = xAdjustment;
5513 undoBuffer.dontRecord--;
5517 if(result) SetViewToCursor(true);
5521 void PutS(const char * string)
5526 SetViewToCursor(true);
5531 void Printf(const char * format, ...)
5535 char temp[MAX_F_STRING];
5537 va_start(args, format);
5538 vsnprintf(temp, sizeof(temp), format, args);
5539 temp[sizeof(temp)-1] = 0;
5545 void SetContents(const char * format, ...)
5549 undoBuffer.dontRecord++;
5551 DelCh(this.lines.first, 0, 0, this.lines.last, this.lineCount-1, ((EditLine)(this.lines.last)).count, true);
5554 char temp[MAX_F_STRING];
5556 va_start(args, format);
5557 vsnprintf(temp, sizeof(temp), format, args);
5558 temp[sizeof(temp)-1] = 0;
5565 undoBuffer.dontRecord--;
5578 x -= 1 + _DelCh(line, y, x-1, line, y, x, true, false, null);
5581 else if(this.line.prev)
5583 EditLine line = this.line.prev;
5587 _DelCh(line, this.y-1, x, this.line, this.y, this.x, true, false, null);
5595 this.selLine = this.line;
5600 SetViewToCursor(true);
5605 Emptyline(this.line,this.y);
5606 this.selX = this.x = 0;
5609 this.selLine = this.line;
5611 SetViewToCursor(true);
5621 SetViewToCursor(true);
5629 SetViewToCursor(true);
5633 bool GoToLineNum(int lineNum)
5638 EditLine line = this.lines.first;
5639 for(c = 0; c < lineNum && line; c++, line = line.next);
5649 SetViewToCursor(true);
5656 // NOTE: Mismatch with NotifyCaretMove() for x/y + 1
5657 bool GoToPosition(EditLine line, int y, int x)
5669 for(line = this.lines.first, c = 0; c<y && line; c++, line = line.next);
5683 SetViewToCursor(true);
5690 void SetViewToCursor(bool setCaret)
5699 bool dontScroll = false;
5705 selected = selX != this.x || selY != y;
5712 checkLine = dropLine;
5718 checkLine = this.line;
5723 numLines = clientSize.h / space.h;
5725 // This is broken. The EditBox now doesn't do anything different when adding to it,
5726 // regardless of the previous scrolling position. It should be read and then set again
5727 // if one wishes to preserve it.
5728 /* // Don't scroll view to cursor if we're in a EES_NOCARET box
5729 if(style.noCaret && this.viewY < lineCount - numLines - 1)
5733 // Horizontal Adjustment
5734 if(!dontScroll && checkLine)
5738 dropX = AdjustXPosition(this.line, MAXINT, true, &x, checkX, 0);
5741 this.x = AdjustXPosition(this.line, MAXINT, true, &x, checkX, 0);
5747 if(x + space.w >= this.viewX + clientSize.w && clientSize.w >= space.w)
5748 viewX = x - clientSize.w+space.w;
5749 if(x < this.viewX + clientSize.w/2 - space.w)
5750 viewX = Max(0, x - clientSize.w/2 + space.w);
5758 // Vertical Adjustment
5759 if(viewY > checkY) viewY = checkY;
5760 if(viewY + numLines <= checkY)
5762 if(clientSize.h >= space.h)
5764 for(line = viewLine; line && (viewY + numLines <= checkY); line = line.next)
5774 for(;dropLine && dropLine.prev && dropY >= numLines;)
5776 dropLine = dropLine.prev;
5780 for(;this.line && this.line.prev && this.y >= numLines;)
5782 this.line = this.line.prev;
5787 SetScrollPosition(viewX, viewY * this.space.h);
5789 UpdateCaretPosition(setCaret);
5795 selLine = this.line;
5805 void CenterOnCursor()
5807 int numLines = clientSize.h / this.space.h;
5808 int y = this.y - numLines / 2;
5810 bool figureSyntax = false;
5811 EditLine oldViewLine = viewLine;
5812 if(y > this.lineCount - numLines) y = this.lineCount-numLines;
5817 for(;y < this.viewY; y++)
5819 this.viewLine = this.viewLine.prev;
5820 style.recomputeSyntax = true;
5822 for(;y > this.viewY; y--)
5824 this.viewLine = this.viewLine.next;
5825 figureSyntax = true;
5828 FigureStartSyntaxStates(oldViewLine, false);
5832 SetScrollPosition(this.viewX, viewY * this.space.h);
5833 UpdateCaretPosition(true);
5837 void SetCursorToView()
5848 numLines = clientSize.h / this.space.h;
5852 for(c=0, line = this.viewLine.next; line && c<numLines && (this.viewY < this.lineCount - numLines); line = line.next, c++);
5853 SetScrollPosition(this.viewX, (this.viewY + c) * this.space.h);
5857 //EditLine oldLine = this.line;
5858 bool lastOne = false;
5859 EditLine oldViewLine = this.viewLine;
5860 bool figureSyntax = false;
5862 if(this.y >= this.lineCount-1) return;
5864 for(c=0, line = this.line.next; line && c<numLines; line = line.next, c++)
5866 if(this.viewY + numLines < this.lines.count)
5868 this.viewLine = this.viewLine.next;
5870 figureSyntax = true;
5872 else if(c && !lastOne)
5881 FigureStartSyntaxStates(oldViewLine, false);
5882 this.x = AdjustXPosition(line, caretX, true, null, MAXINT, 0);
5885 SetViewToCursor(false);
5894 if(this.y == 0) return;
5896 numLines = clientSize.h / this.space.h;
5900 for(c=0, line = this.viewLine.prev; line && c<numLines; line = line.prev, c++);
5901 SetScrollPosition(this.viewX, (this.viewY - c) * this.space.h);
5905 for(c=0, line = this.line.prev; line && c<numLines; line = line.prev, c++)
5910 if(this.viewLine.prev)
5912 this.viewLine = this.viewLine.prev;
5914 style.recomputeSyntax = true;
5918 this.x = AdjustXPosition(line, caretX, true, null, MAXINT, 0);
5921 SetViewToCursor(false);
5928 if(this.viewLine.prev)
5931 // this.viewLine = this.viewLine.prev;
5934 SetScrollPosition(this.viewX, (this.viewY - 1) * this.space.h);
5941 if(this.viewLine.next)
5944 // this.viewLine = this.viewLine.next;
5947 SetScrollPosition(this.viewX, (this.viewY + 1) * this.space.h);
5954 EditLine l1, l2, line;
5955 int x1, x2, nx1, nx2;
5960 if(!this.selLine) return 0;
5961 if(this.selLine == this.line && this.selX == this.x) return 0;
5962 if(this.selY < this.y)
5969 else if(this.selY > this.y)
5976 else if(this.selX < this.x)
5978 l1 = l2 = this.line;
5984 l1 = l2 = this.line;
5988 nx1 = Min(x1,l1.count);
5989 nx2 = Min(x2,l2.count);
5991 // Find Number of Bytes Needed
5993 for(line = l1; line; line = line.next)
5995 if(line == l1) start = nx1; else start = 0;
5996 if(line == l2) end = nx2; else end = line.count;
5998 if(style.freeCaret && line == l2)
6001 count = Max(x2-Max(x1,l1.count),0);
6003 count = Max(x2-l2.count,0);
6007 if(line == l2) break;
6008 // Add Carriage Return / line Feed
6015 void GetSelPos(EditLine * l1, int *y1, int *x1, EditLine * l2, int * y2, int * x2, bool reorder)
6019 if(!reorder || this.selY < this.y)
6021 if(l1) *l1 = this.selLine;
6022 if(y1) *y1 = this.selY;
6023 if(x1) *x1 = this.selX;
6024 if(l2) *l2 = this.line;
6025 if(y2) *y2 = this.y;
6026 if(x2) *x2 = this.x;
6028 else if(this.selY > this.y)
6030 if(l1) *l1 = this.line;
6031 if(y1) *y1 = this.y;
6032 if(x1) *x1 = this.x;
6033 if(l2) *l2 = this.selLine;
6034 if(y2) *y2 = this.selY;
6035 if(x2) *x2 = this.selX;
6037 else if(this.selX < this.x)
6039 if(l1) *l1 = this.line;
6040 if(y1) *y1 = this.selY;
6041 if(x1) *x1 = this.selX;
6042 if(l2) *l2 = this.line;
6043 if(y2) *y2 = this.y;
6044 if(x2) *x2 = this.x;
6048 if(l1) *l1 = this.line;
6049 if(y1) *y1 = this.y;
6050 if(x1) *x1 = this.x;
6051 if(l2) *l2 = this.line;
6052 if(y2) *y2 = this.selY;
6053 if(x2) *x2 = this.selX;
6058 void SetSelPos(EditLine l1, int y1, int x1, EditLine l2, int y2, int x2)
6060 if(this && (this.selY != y1 || this.selX != x1 || this.y != y2 || this.x != x2))
6062 this.selLine = (EditLine)l1;
6065 this.line = (EditLine)l2;
6069 SetViewToCursor(true);
6073 int GetText(char * text, EditLine _l1, int _y1, int _x1, EditLine _l2, int _y2, int _x2, bool addCr, bool addSpaces)
6075 EditLine l1, l2, line;
6076 int x1, x2, nx1, nx2;
6107 nx1 = Min(x1,l1.count);
6108 nx2 = Min(x2,l2.count);
6111 for(line = l1; line; line = line.next)
6113 if(line == l1) start = nx1; else start = 0;
6114 if(line == l2) end = nx2; else end = line.count;
6117 CopyBytes(text, line.buffer + start, end - start);
6120 numChars += end-start;
6122 if(style.freeCaret && line == l2 && addSpaces)
6125 count = Max(x2-Max(x1,l1.count),0);
6127 count = Max(x2-l2.count,0);
6130 FillBytes(text,' ',count);
6136 if(line == l2) break;
6148 // '\0' terminate Terminate
6155 void GetSel(char * text, bool addCr)
6157 GetText(text, line, y, x, selLine, selY, selX, addCr, true);
6160 private void _Deselect() // This assumes marking lines as dirty is handled by the caller
6178 int size = SelSize();
6181 // Try to allocate memory
6182 ClipBoard clipBoard { };
6183 if(clipBoard.Allocate(size+1))
6185 GetSel(clipBoard.memory, true);
6198 ClipBoard clipBoard { };
6199 if(clipBoard.Load())
6200 PutS(clipBoard.memory);
6212 SetViewToCursor(true);
6218 void DeleteSelection()
6223 SetViewToCursor(true);
6229 void Save(File f, bool cr)
6232 savedAction = undoBuffer.curAction;
6234 for(line = this.lines.first; line; line = line.next)
6236 f.Write(line.buffer, line.count, 1);
6239 if(cr) f.Putc('\r');
6245 #define BUFFER_SIZE 16384
6248 undoBuffer.dontRecord++;
6251 char buffer[BUFFER_SIZE];
6255 int count = f.Read(buffer, 1, BUFFER_SIZE-1);
6256 buffer[count] = '\0';
6262 undoBuffer.dontRecord--;
6263 undoBuffer.count = 0;
6264 undoBuffer.curAction = 0;
6265 itemEditUndo.disabled = undoBuffer.curAction == 0;
6266 itemEditRedo.disabled = undoBuffer.curAction == undoBuffer.count;
6269 EditBoxFindResult Find(const char * text, bool matchWord, bool matchCase, bool isSearchDown)
6273 bool firstPass = true;
6274 EditBoxFindResult result = found;
6276 if(!this.line) return notFound;
6279 for(line = this.line;;)
6287 line = this.lines.first;
6293 line = this.lines.last;
6294 num = this.lineCount - 1;
6300 string = SearchString(line.buffer, firstPass ? Min(this.x,line.count) : 0,text,matchCase,matchWord);
6302 string = RSearchString(line.buffer,text,firstPass ? (Min(this.x,line.count)-1) : line.count,matchCase,matchWord);
6306 Select((void *)line,num,string - line.buffer,(void *)line,num,string - line.buffer + strlen(text));
6309 if(line == this.line && !firstPass) break;
6327 EditBoxFindResult FindInSelection(const char * text, bool matchWord, bool matchCase, EditLine l2, int y2, int x2)
6331 int searchLen = strlen(text);
6332 for(line = (EditLine)this.line, y = this.y; y <= y2; line = line.next, y++)
6334 char * string = SearchString(line.buffer, (y == this.y) ? Min(this.x,line.count) : 0,text,matchCase,matchWord);
6335 if(string && (y < y2 || (string - line.buffer) + searchLen <= x2))
6337 Select((void *)line,y,string - line.buffer,(void *)line,y,string - line.buffer + strlen(text));
6344 bool OnKeyDown(Key key, unichar ch)
6347 //PrintLn("OnKeyDown: code = ", key.code, ", mods = ", key.modifiers, ", ch = ", (int)ch);
6349 if(!NotifyKeyDown(master, this, key, ch))
6359 this.mouseMove = false;
6360 OnLeftButtonUp(0,0,0);
6361 SetViewToCursor(true);
6371 public class EditBoxStream : File
6374 BufferLocation start, sel;
6381 EditBox editBox = this.editBox;
6383 editBox.x = start.x;
6384 editBox.y = start.y;
6385 editBox.line = start.line;
6387 editBox.selX = sel.x;
6388 editBox.selY = sel.y;
6389 editBox.selLine = sel.line;
6391 editBox.SetViewToCursor(true);
6392 //editBox.ComputeColumn();
6396 property EditBox editBox
6404 start.line = value.line;
6408 sel.line = value.selLine;
6411 value.GoToHome(true);
6414 get { return editBox; }
6417 uint Read(byte * buffer, uint size, uint count)
6420 EditBox editBox = this.editBox;
6421 EditLine line = editBox.line;
6427 for(;read < count && line; line = (*&line.next))
6429 int numBytes = Min(count - read, (*&line.count) - x);
6432 memcpy(buffer + read, (*&line.buffer) + x, numBytes);
6437 for(;read < count && x < (*&line.count);)
6439 buffer[read++] = (*&line.buffer)[x++];
6446 buffer[read++] = '\n';
6451 if(x == (*&line.count) && (*&line.next))
6460 editBox.line = editBox.selLine = line;
6461 editBox.x = editBox.selX = x;
6462 editBox.y = editBox.selY = y;
6467 bool Seek(int pos, FileSeekMode mode)
6470 EditBox editBox = this.editBox;
6471 EditLine line = editBox.line;
6473 if(mode == FileSeekMode::start)
6475 pos = pos - this.pos;
6485 for(;read < pos && line; line = (*&line.next))
6487 int numBytes = Min(pos - read, (*&line.count) - x);
6490 read += numBytes; x += numBytes;
6493 /*for(;read < pos && x < (*&line.count);)
6521 for(;read < pos && line; line = (*&line.prev))
6523 int numBytes = Min(pos - read, x);
6529 /*for(;read < pos && x > 0;)
6539 x = (*&(*&line.prev).count);
6555 editBox.line = editBox.selLine = line;
6556 editBox.x = editBox.selX = x;
6557 editBox.y = editBox.selY = y;
6562 bool Puts(const char * string)
6564 EditBox editBox = this.editBox;
6565 BufferLocation start { editBox.line, editBox.y, editBox.x };
6569 editBox.AddS(string);
6571 pos.line = editBox.line;
6575 this.start.AdjustAdd(start, pos);
6576 sel.AdjustAdd(start, pos);
6581 // NOTE: BYTE, NOT UNICODE CHARACTER!
6584 EditBox editBox = this.editBox;
6585 BufferLocation start = { editBox.line, editBox.y, editBox.x };
6590 utf8Bytes[numBytes++] = ch;
6591 utf8Bytes[numBytes] = 0;
6592 if(UTF8Validate((char *)utf8Bytes))
6594 editBox.AddCh(UTF8_GET_CHAR(utf8Bytes, numBytes));
6596 pos.line = editBox.line;
6599 this.start.AdjustAdd(start, pos);
6600 sel.AdjustAdd(start, pos);
6607 bool Getc(char * ch)
6609 return Read(ch, 1, 1) ? true : false;
6612 void DeleteBytes(uint count)
6614 EditBox editBox = this.editBox;
6617 BufferLocation pos { editBox.line, editBox.y, editBox.x };
6618 BufferLocation end = pos;
6623 for(;c < count && end.line && end.x < end.line.count;)
6628 if(c < count && end.line && end.line.next)
6630 end.line = end.line.next;
6639 start.AdjustDelete(pos, end);
6640 sel.AdjustDelete(pos, end);
6642 editBox._DelCh(pos.line, pos.y, pos.x, end.line, end.y, end.x, true, false, null);