ide: Finding improved

git-svn-id: svn://ultimatepp.org/upp/trunk@10965 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-03-22 15:02:21 +00:00
parent 7560f610ea
commit db2c09a24b
5 changed files with 31 additions and 27 deletions

View file

@ -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<LineEdit::Highlight>& 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++;
}
}
}
}

View file

@ -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<EditorSyntax> GetSyntax(int line);
bool IsCursorBracket(int pos) const;

View file

@ -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)

View file

@ -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<String> 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();

View file

@ -313,7 +313,8 @@ void Ide::FindFileAll(const Vector<Tuple<int, int>>& 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.");