From 033a2e74e1b3e1b62aa52ec167e475837e2cd778 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Fri, 30 Jan 2026 23:10:05 +0100 Subject: [PATCH] ide, CodeEditor, CtrlLib: TheIDE Console (and CodeEditor and LineEdit) optimized for smoother building experience --- uppsrc/CodeEditor/CodeEditor.cpp | 3 +- uppsrc/CodeEditor/CodeEditor.h | 3 ++ uppsrc/CtrlLib/Text.cpp | 7 +++- uppsrc/ide/Console.cpp | 66 +++++++++++++++++--------------- uppsrc/ide/ide.h | 3 ++ 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index 003f42f42..c6d0220ea 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -252,6 +252,7 @@ void CodeEditor::PostInsert(int pos, const WString& text) { if(text.GetCount() > 200 || GetRefreshInfo(pos) != refresh_info || text.Find('\n') >= 0) Refresh(); else + if(!console_mode) CheckSyntaxRefresh(pos, text); } WhenUpdate(); @@ -341,7 +342,7 @@ void CodeEditor::CheckBrackets() CancelBracketHighlight(highlight_bracket_pos0); CancelBracketHighlight(highlight_bracket_pos); if(!IsSelection()) { - if(GetSyntax(GetCursorLine())->CheckBrackets(*this, highlight_bracket_pos0, highlight_bracket_pos)) { + if(!console_mode && GetSyntax(GetCursorLine())->CheckBrackets(*this, highlight_bracket_pos0, highlight_bracket_pos)) { RefreshLine(GetLine(highlight_bracket_pos0)); RefreshLine(GetLine(highlight_bracket_pos)); bracket_start = GetTimeClick(); diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 1fa00b392..303a5a522 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -264,6 +264,8 @@ protected: bool withfindreplace; bool wordwrap; bool blk0_header; + + bool console_mode = false; int ff_start_pos; @@ -550,6 +552,7 @@ public: int GetActiveAnnotationLine() const { return bar.GetActiveAnnotationLine(); } Size GetBarSize() const { return bar.GetSize(); } void HideBar() { bar.Hide(); } + void ConsoleMode() { console_mode = true; } void AnimateBar(const Vector& a) { bar.SetAnimate(a); } void BarColor(Color c) { bar.Background(c); } void BarText(const String& text, Color c) { bar.Text(text, c); } diff --git a/uppsrc/CtrlLib/Text.cpp b/uppsrc/CtrlLib/Text.cpp index 4082f6a1b..437716a90 100644 --- a/uppsrc/CtrlLib/Text.cpp +++ b/uppsrc/CtrlLib/Text.cpp @@ -615,6 +615,11 @@ String TextCtrl::GetEncodedLine(int i, byte charset) const int TextCtrl::GetLinePos64(int64& pos) const { GuiLock __; + if(pos == total) { // Appending at the end - accelerate + int l = GetLineCount() - 1; + pos = GetLineLength(l); + return l; + } if(pos < cpos && cpos - pos < pos && !view) { int i = cline; int64 ps = cpos; @@ -858,10 +863,10 @@ void TextCtrl::Remove0(int pos, int size) { GuiLock __; int rmpos = pos, rmsize = size; PreRemove(rmpos, rmsize); - total -= size; if(pos < cpos) cpos = cline = 0; int i = GetLinePos32(pos); + total -= size; // GetLinePos32 is using total, so this mush be after it! DirtyFrom(i); WString ln = GetWLine(i); int sz = min(LimitSize(ln.GetLength() - pos), size); diff --git a/uppsrc/ide/Console.cpp b/uppsrc/ide/Console.cpp index 576a6a94b..aaed35840 100644 --- a/uppsrc/ide/Console.cpp +++ b/uppsrc/ide/Console.cpp @@ -50,6 +50,7 @@ Console::Console() { input.Hide(); serial = 0; HideBar(); + ConsoleMode(); } void Console::LeftDouble(Point p, dword) { @@ -78,38 +79,43 @@ void Console::Append(const String& s) { Puts(t); return; } - int l, h; - GetSelection32(l, h); - if(GetCursor32() == GetLength32()) l = -1; - EditPos p = GetEditPos(); - SetEditable(); - MoveTextEnd(); - WString t = Filter(s, sAppf).ToWString(); - int mg = max(40, sb.GetReducedViewSize().cx / GetFontSize().cx); - if(wrap_text && mg > 4) { - int x = GetColumnLine(GetCursor32()).x; - WStringBuffer tt; - const wchar *q = t; - while(*q) { - if(x > mg - 1) { - tt.Cat('\n'); - tt.Cat(" "); - x = 4; + + text_buffer << s; + flush.KillPost([=] { + int l, h; + GetSelection32(l, h); + if(GetCursor32() == GetLength32()) l = -1; + EditPos p = GetEditPos(); + SetEditable(); + MoveTextEnd(); + WString t = Filter(text_buffer, sAppf).ToWString(); + int mg = max(40, sb.GetReducedViewSize().cx / GetFontSize().cx); + if(wrap_text && mg > 4) { + int x = GetColumnLine(GetCursor32()).x; + WStringBuffer tt; + const wchar *q = t; + while(*q) { + if(x > mg - 1) { + tt.Cat('\n'); + tt.Cat(" "); + x = 4; + } + x++; + if(*q == '\n') + x = 0; + tt.Cat(*q++); } - x++; - if(*q == '\n') - x = 0; - tt.Cat(*q++); + Paste(tt); } - Paste(tt); - } - else - Paste(t); - SetReadOnly(); - if(l >= 0) { - SetEditPos(p); - SetSelection(l, h); - } + else + Paste(t); + SetReadOnly(); + if(l >= 0) { + SetEditPos(p); + SetSelection(l, h); + } + text_buffer.Clear(); + }); } bool Console::Key(dword key, int count) { diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index e996d967b..efc422743 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -101,6 +101,9 @@ protected: FrameBottom input; String line; int serial; + + String text_buffer; + TimeCallback flush; void CheckEndGroup(); void FlushConsole();