auto close pairs, deactivate unclear condifition not to close

and make remove offset from relExpressions to change caret "p" instead
This commit is contained in:
Basile Burg 2019-02-10 04:29:05 +01:00
parent bc42dc300c
commit 3339404419
1 changed files with 17 additions and 9 deletions

View File

@ -2384,7 +2384,10 @@ begin
if fLexToks.Count < 3 then if fLexToks.Count < 3 then
exit; exit;
p := selStart; // -1: selstart is 1-based while tokens offset is 0-based (-1)
// -2: source is lexed before the insertion while this proc is called after the insertion
p := selStart - 2;
if value in [autoCloseBackTick, autoCloseDoubleQuote, autoCloseSingleQuote] then if value in [autoCloseBackTick, autoCloseDoubleQuote, autoCloseSingleQuote] then
begin begin
for i := 0 to fLexToks.Count-1 do for i := 0 to fLexToks.Count-1 do
@ -2392,24 +2395,27 @@ begin
tk0 := fLexToks[i]; tk0 := fLexToks[i];
// opening char is stuck to something, assume this thing is // opening char is stuck to something, assume this thing is
// what has to be between the pair, so don't close. // what has to be between the pair, so don't close.
if (tk0^.offset+2 = p) and (tk0^.kind in dontCloseIfContiguousTo) then if (tk0^.offset = p) and (tk0^.kind in dontCloseIfContiguousTo) then
exit; exit;
if i < fLexToks.Count-1 then if i < fLexToks.Count-1 then
begin begin
tk1 := fLexToks[i+1]; tk1 := fLexToks[i+1];
// inside a strings lit., char lit., comments, don't put the mess. // inside a strings lit., char lit., comments, don't put the mess.
if (tk0^.offset+1 <= p) and (p < tk1^.offset+2) and if (tk0^.offset < p) and (p < tk1^.offset) and
(tk0^.kind in [ltkString, ltkChar, ltkComment]) then (tk0^.kind in [ltkString, ltkChar, ltkComment]) then
exit; exit;
// ?? wut ??
// since the source is scanned before inserting the opening char, // since the source is scanned before inserting the opening char,
// in single line comments, p can be > to next tok offset // in single line comments, p can be > to next tok offset
if (tk0^.offset+1 <= p) and (p > tk1^.offset+2) and // if (tk0^.offset < p) and (p > tk1^.offset) and
(tk0^.kind = ltkComment) and (tk0^.Data[1] = '/') then // (tk0^.kind = ltkComment) and (tk0^.Data[1] = '/') then
exit; // exit;
end end
// at the EOF an illegal tok is likely something that has to be closed so // at the EOF an illegal tok is likely something that has to be closed so
// dont auto insert the pair. // dont auto insert the pair.
else if (tk0^.offset+1 <= p) and (tk0^.kind = ltkIllegal) then else if (tk0^.offset < p) and (tk0^.kind = ltkIllegal) then
exit; exit;
end; end;
end end
@ -2419,12 +2425,14 @@ begin
for i:=0 to fLexToks.Count-2 do for i:=0 to fLexToks.Count-2 do
begin begin
tk0 := fLexToks[i]; tk0 := fLexToks[i];
if (tk0^.offset < p) and (p < tk0^.offset + tk0^.data.length) then
exit;
tk1 := fLexToks[i+1]; tk1 := fLexToks[i+1];
// opening char is stuck to something, assume this thing is // opening char is stuck to something, assume this thing is
// what has to be between the pair, so don't close. // what has to be between the pair, so don't close.
if (tk0^.offset+2 = p) and (tk0^.kind in dontCloseIfContiguousTo) then if (tk0^.offset = p) and (tk0^.kind in dontCloseIfContiguousTo) then
exit; exit;
if (tk0^.offset+1 <= p) and (p < tk1^.offset+2) and if (tk0^.offset < p) and (p < tk1^.offset) and
(tk0^.kind = ltkComment) then (tk0^.kind = ltkComment) then
exit; exit;
end; end;