From db2c09a24bd3cbf0ee43af7ea26204ce99aa739e Mon Sep 17 00:00:00 2001 From: cxl Date: Wed, 22 Mar 2017 15:02:21 +0000 Subject: [PATCH] ide: Finding improved git-svn-id: svn://ultimatepp.org/upp/trunk@10965 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CodeEditor/CodeEditor.cpp | 39 +++++++++++++++----------------- uppsrc/CodeEditor/CodeEditor.h | 4 +++- uppsrc/CodeEditor/hl_color.i | 2 +- uppsrc/ide/Errors.cpp | 10 +++++--- uppsrc/ide/FindInFiles.cpp | 3 ++- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index 30a03631e..06858a51a 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -270,22 +270,20 @@ void CodeEditor::Periodic() void CodeEditor::SelectionChanged() { int l, h; - WString nselword; + WString nilluminated; bool sel = GetSelection(l, h); - if(sel && h - l < 128 && - (l == 0 || !iscid(GetChar(l - 1))) && - (h >= GetLength() || !iscid(GetChar(h)))) { + if(sel && h - l < 128) { for(int i = l; i < h; i++) { int c = GetChar(i); - if(!iscid(c)) { - nselword.Clear(); + if(c == '\n') { + nilluminated.Clear(); break; } - nselword.Cat(c); + nilluminated.Cat(c); } } - if(selword != nselword) { - selword = nselword; + if(illuminated != nilluminated) { + illuminated = nilluminated; Refresh(); } if(!foundsel) { @@ -1010,21 +1008,20 @@ void CodeEditor::HighlightLine(int line, Vector& hl, int po HighlightOutput hls(hl); WString l = GetWLine(line); GetSyntax(line)->Highlight(l.Begin(), l.End(), hls, this, line, pos); - if(selword.GetCount()) { + if(illuminated.GetCount()) { int q = 0; - for(;;) { - q = l.Find(selword, q); + while(q < l.GetCount() && q < hl.GetCount()) { + q = l.Find(illuminated, q); if(q < 0) break; - int h = q + selword.GetCount(); - if((q == 0 || !iscid(l[q - 1])) && (h >= l.GetCount() || !iscid(l[h]))) - for(int i = 0; i < selword.GetCount() && i + q < hl.GetCount(); i++) { - const HlStyle& st = hl_style[PAPER_SELWORD]; - hl[i + q].paper = st.color; - if(st.bold) - hl[i + q].font.Bold(); - } - q = h; + int n = illuminated.GetCount(); + while(n-- && q < hl.GetCount()) { + const HlStyle& st = hl_style[PAPER_SELWORD]; + hl[q].paper = st.color; + if(st.bold) + hl[q].font.Bold(); + q++; + } } } } diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index cf839de32..e16a021af 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -268,7 +268,7 @@ protected: enum { SEL_CHARS, SEL_WORDS, SEL_LINES }; int selkind; - WString selword; + WString illuminated; String iwc; @@ -500,6 +500,8 @@ public: void SyncTip(); void CloseTip() { if(tip.IsOpen()) tip.Close(); tip.d = NULL; } + + void Illuminate(const WString& text) { illuminated = text; Refresh(); } One GetSyntax(int line); bool IsCursorBracket(int pos) const; diff --git a/uppsrc/CodeEditor/hl_color.i b/uppsrc/CodeEditor/hl_color.i index 4e7d26ace..3efe5c5a6 100644 --- a/uppsrc/CodeEditor/hl_color.i +++ b/uppsrc/CodeEditor/hl_color.i @@ -53,7 +53,7 @@ HL_COLOR(INK_DIFF_ADDED, t_("Diff added line"), 0) HL_COLOR(INK_DIFF_REMOVED, t_("Diff removed line"), 0) HL_COLOR(INK_DIFF_COMMENT, t_("Diff comment"), 0) -HL_COLOR(PAPER_SELWORD, t_("Selected word through file"), 0) +HL_COLOR(PAPER_SELWORD, t_("Found/selected matches"), 0) HL_COLOR(PAPER_ERROR, t_("Error in compiler messages"), 0) HL_COLOR(PAPER_WARNING, t_("Warning in compiler messages"), 0) diff --git a/uppsrc/ide/Errors.cpp b/uppsrc/ide/Errors.cpp index a38f8e4c9..683fe8c3f 100644 --- a/uppsrc/ide/Errors.cpp +++ b/uppsrc/ide/Errors.cpp @@ -295,10 +295,14 @@ void Ide::GoToError(const ErrorInfo& f) String file = NormalizePath(f.file); DoEditAsText(file); EditFile(file); - int pos = editor.GetPos(editor.GetLineNo(f.lineno - 1), max(f.linepos - 1, 0)); + int lp = max(f.linepos - 1, 0); + int pos = editor.GetPos(editor.GetLineNo(f.lineno - 1), lp); editor.SetCursor(pos); - if(f.len) - editor.SetSelection(pos, pos + f.len); + if(*f.message == '\1') { + Vector h = Split(~f.message + 1, '\1', false); + if(h.GetCount() >= 4) + editor.Illuminate(h[3].Mid(atoi(h[1]), atoi(h[2])).ToWString()); + } editor.CenterCursor(); editor.SetFocus(); Sync(); diff --git a/uppsrc/ide/FindInFiles.cpp b/uppsrc/ide/FindInFiles.cpp index 61f7eeb29..263b6ddf0 100644 --- a/uppsrc/ide/FindInFiles.cpp +++ b/uppsrc/ide/FindInFiles.cpp @@ -313,7 +313,8 @@ void Ide::FindFileAll(const Vector>& f) for(auto pos : f) { editor.CachePos(pos.a); int linei = editor.GetLinePos(pos.a); - AddFoundFile(editfile, linei + 1, editor.GetUtf8Line(linei), pos.a, pos.b); + WString ln = editor.GetWLine(linei); + AddFoundFile(editfile, linei + 1, ln.ToString(), lenAsUtf8(~ln, pos.a), lenAsUtf8(~ln + pos.a, pos.b)); } ffound.HeaderTab(2).SetText(Format("Source line (%d)", ffound.GetCount())); ffound.Add(Null, Null, AsString(f.GetCount()) + " occurrence(s) have been found.");