ide: Replace in block optimized, Highlighting thousands

git-svn-id: svn://ultimatepp.org/upp/trunk@6398 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2013-10-06 15:54:11 +00:00
parent e51439e784
commit ad921e4852
9 changed files with 65 additions and 27 deletions

View file

@ -26,6 +26,7 @@ inline bool IsComment(int a, int b) {
}
void CodeEditor::PreInsert(int pos, const WString& text) {
DTIMING("PreInsert");
if(IsFullRefresh()) return;
rm_ins = ScanSyntax(GetLine(pos) + 1);
}
@ -45,6 +46,7 @@ void CodeEditor::CheckBraces(const WString& text)
}
void CodeEditor::PostInsert(int pos, const WString& text) {
DTIMING("PostInsert");
if(check_edited)
bar.SetEdited(GetLine(pos));
if(IsFullRefresh()) return;
@ -63,6 +65,7 @@ void CodeEditor::PostInsert(int pos, const WString& text) {
}
void CodeEditor::PreRemove(int pos, int size) {
DTIMING("PreRemove");
if(IsFullRefresh()) return;
if(size > 200)
Refresh();
@ -77,6 +80,7 @@ void CodeEditor::PreRemove(int pos, int size) {
}
void CodeEditor::PostRemove(int pos, int size) {
DTIMING("PostRemove");
if(check_edited)
bar.SetEdited(GetLine(pos));
if(IsFullRefresh()) return;
@ -1002,7 +1006,9 @@ void CodeEditor::DefaultHlStyles()
SetHlStyle(INK_CONST_STRINGOP, LtBlue);
SetHlStyle(INK_CONST_INT, Red);
SetHlStyle(INK_CONST_INT_3, Red, true, false, false);
SetHlStyle(INK_CONST_FLOAT, Magenta);
SetHlStyle(INK_CONST_FLOAT_3, Magenta, true, false, false);
SetHlStyle(INK_CONST_HEX, Blue);
SetHlStyle(INK_CONST_OCT, Blue);

View file

@ -314,6 +314,7 @@ protected:
Array<Found> foundwild;
bool foundsel;
bool found, notfoundfw, notfoundbk;
int foundpos, foundsize;
int iwc;
@ -434,6 +435,7 @@ public:
void CloseFindReplace();
void FindReplace(bool pick_selection, bool pick_text, bool replace);
bool FindFrom(int pos, bool back, const wchar *text, bool wholeword, bool ignorecase, bool wildcards, bool block);
bool Find(bool back, const wchar *text, bool wholeword, bool ignorecase, bool wildcards,
bool block);
bool Find(bool back = false, bool blockreplace = false, bool replace = false);

View file

@ -370,6 +370,7 @@ void EditorBar::SetBreakpoint(int ln, const String& s)
void EditorBar::SetEdited(int ln, int count)
{
DTIMING("SetEdited");
if(ignored_next_edit) {
ignored_next_edit = false;
return;

View file

@ -127,8 +127,24 @@ int CodeEditor::Match(const wchar *f, const wchar *s, int line, bool we, bool ig
}
bool CodeEditor::Find(bool back, const wchar *text, bool wholeword, bool ignorecase,
bool wildcards, bool block)
bool wildcards, bool block)
{
DTIMING("Find");
if(notfoundfw) MoveTextBegin();
if(notfoundbk) MoveTextEnd();
int cursor, pos;
if(found)
GetSelection(pos, cursor);
else
GetSelection(cursor, pos);
pos = cursor;
return FindFrom(pos, back, text, wholeword, ignorecase, wildcards, block);
}
bool CodeEditor::FindFrom(int pos, bool back, const wchar *text, bool wholeword, bool ignorecase,
bool wildcards, bool block) {
DTIMING("Find2");
WString ft;
const wchar *s = text;
while(*s) {
@ -158,35 +174,32 @@ bool CodeEditor::Find(bool back, const wchar *text, bool wholeword, bool ignorec
else
ft.Cat(c);
}
foundwild.Clear();
if(ft.IsEmpty()) return false;
if(notfoundfw) MoveTextBegin();
if(notfoundbk) MoveTextEnd();
bool wb = wholeword ? iscidl(*ft) : false;
bool we = wholeword ? iscidl(*ft.Last()) : false;
int cursor, pos;
if(found)
GetSelection(pos, cursor);
else
GetSelection(cursor, pos);
pos = cursor;
if(ft.IsEmpty()) return false;
foundwild.Clear();
int line = GetLinePos(pos);
int linecount = GetLineCount();
WString ln = GetWLine(line);
const wchar *l = ln;
s = l + pos;
DTIMING("Find3");
for(;;) {
for(;;) {
if(!wb || (s == l || !iscidl(s[-1]))) {
int n = Match(ft, s, line, we, ignorecase);
if(n >= 0) {
DTIMING("Find4");
int pos = GetPos(line, int(s - l));
if(!back || pos + n < cursor) {
foundsel = true;
SetSelection(pos, pos + n);
foundsel = false;
if(!block)
if(!block) {
foundsel = true;
SetSelection(pos, pos + n);
foundsel = false;
CenterCursor();
}
foundpos = pos;
foundsize = n;
found = true;
return true;
}
@ -200,12 +213,14 @@ bool CodeEditor::Find(bool back, const wchar *text, bool wholeword, bool ignorec
}
if(back) {
if(--line < 0) break;
DTIMING("Find5");
ln = GetWLine(line);
l = ln;
s = ln.End();
}
else {
if(++line >= linecount) break;
DTIMING("Find6");
ln = GetWLine(line);
l = s = ln;
}
@ -271,6 +286,7 @@ WString CodeEditor::GetReplaceText()
WString CodeEditor::GetReplaceText(WString rs, bool wildcards, bool samecase)
{
DTIMING("GetReplaceText");
int anyi = 0, onei = 0, spacei = 0, numberi = 0, idi = 0;
WString rt;
const wchar *s = rs;
@ -389,20 +405,21 @@ void CodeEditor::Replace()
int CodeEditor::BlockReplace(WString find, WString replace, bool wholeword, bool ignorecase, bool wildcards, bool samecase)
{
NextUndo();
Refresh(); // Setting full-refresh here avoids Pre/Post Remove/Insert costs
int l, h;
if(!GetSelection(l, h)) return 0;
PlaceCaret(l);
int count = 0;
for(;;) {
if(!Find(false, find, wholeword, ignorecase, wildcards, true) || cursor > h) break;
int hh, ll;
GetSelection(ll, hh);
CachePos(ll);
h = h - (hh - ll) + Paste(GetReplaceText(replace, wildcards, ignorecase && samecase));
foundpos = l;
while(FindFrom(foundpos, false, find, wholeword, ignorecase, wildcards, true) && foundpos + foundsize <= h) {
CachePos(foundpos);
Remove(foundpos, foundsize);
WString rt = GetReplaceText(replace, wildcards, ignorecase && samecase);
Insert(foundpos, rt);
h = h - foundsize + rt.GetCount();
count++;
}
SetSelection(l, h);
Refresh();
return count;
}

View file

@ -698,7 +698,8 @@ void CodeEditor::HighlightLine(int line, Vector<LineEdit::Highlight>& hl, int po
int c = INK_CONST_INT;
bool isDot, isFloat = false;
if(*p == '0') c = INK_CONST_OCT;
while(IsDigit(*p)) p++;
while(IsDigit(*p)) p++;
int fixdigits = p - t;
if(*p == '.' || (*p == 'e' || *p == 'E') && highlight != HIGHLIGHT_CSS) {
if(*p == '.')
isDot = true;
@ -714,8 +715,13 @@ void CodeEditor::HighlightLine(int line, Vector<LineEdit::Highlight>& hl, int po
}
if(c == INK_CONST_OCT && p - t == 1)
c = INK_CONST_INT;
if(p - t > 0)
hls.Put(int(p - t), hl_style[c]);
int n = int(p - t);
for(int i = 0; i < n; i++) {
int q = fixdigits - i;
hls.Put(fixdigits > 4 && q > 0 && q % 3 == 0 && c != INK_CONST_OCT ?
hl_style[c == INK_CONST_INT ? INK_CONST_INT_3 : INK_CONST_FLOAT_3]
: hl_style[c]);
}
}
else
if(pair == MAKELONG('t', '_') && p[2] == '(' && p[3] == '\"') {

View file

@ -19,7 +19,9 @@ HL_COLOR(INK_PAR1, "Brackets level 2", 1)
HL_COLOR(INK_PAR2, "Brackets level 3", 1)
HL_COLOR(INK_PAR3, "Brackets level 4", 1)
HL_COLOR(INK_CONST_INT, "Decimal constant", 1)
HL_COLOR(INK_CONST_INT_3, "Decimal constant thousands", 1)
HL_COLOR(INK_CONST_FLOAT, "FP constant", 1)
HL_COLOR(INK_CONST_FLOAT_3, "FP constant thousands", 1)
HL_COLOR(INK_CONST_HEX, "Hexadecimal constant", 1)
HL_COLOR(INK_CONST_OCT, "Octal constant", 1)
HL_COLOR(INK_CONST_STRINGOP, "Format field", 1)

View file

@ -81,6 +81,7 @@ void TextCtrl::SetSb() {}
void TextCtrl::PlaceCaret(int newcursor, bool sel) {}
void TextCtrl::CachePos(int pos) {
DTIMING("CachePos");
int p = pos;
cline = GetLinePos(p);
cpos = pos - p;
@ -475,6 +476,7 @@ void TextCtrl::RemoveU(int pos, int size) {
}
int TextCtrl::Insert(int pos, const WString& _txt, bool typing) {
DTIMING("Insert");
WString txt = _txt;
if(charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM)
for(int i = 0; i < txt.GetCount(); i++)
@ -491,6 +493,7 @@ int TextCtrl::Insert(int pos, const String& txt, byte charset)
}
void TextCtrl::Remove(int pos, int size) {
DTIMING("Remove");
RemoveU(pos, size);
Undodo();
}
@ -635,6 +638,7 @@ void TextCtrl::SelectAll() {
}
int TextCtrl::Paste(const WString& text) {
DTIMING("Paste");
if(IsReadOnly()) return 0;
RemoveSelection();
int n = Insert(cursor, text);

View file

@ -4,7 +4,7 @@
#define LTIMING(x) // DTIMING(x)
#ifdef _DEBUG
#define LSLOW() Sleep(300)
#define LSLOW() // Sleep(300)
#else
#define LSLOW()
#endif

View file

@ -447,7 +447,7 @@ void Ide::SetupFormat() {
hlt.hlstyle.AddColumn("Bold").Ctrls<Option>();
hlt.hlstyle.AddColumn("Italic").Ctrls<Option>();
hlt.hlstyle.AddColumn("Underline").Ctrls<Option>();
hlt.hlstyle.ColumnWidths("130 70 40 40 70");
hlt.hlstyle.ColumnWidths("211 80 45 45 80");
hlt.hlstyle.EvenRowColor().NoHorzGrid().SetLineCy(EditField::GetStdHeight() + 2);
ReadHlStyles(hlt.hlstyle);
edt.charset <<= (int)default_charset;