mirror of https://gitlab.com/basile.b/dexed.git
improve detection of invalid auto close pair
This commit is contained in:
parent
5931ce7ca9
commit
7f1bba9094
|
@ -468,7 +468,7 @@ begin
|
||||||
if not fServerListening then exit;
|
if not fServerListening then exit;
|
||||||
if fDoc = nil then exit;
|
if fDoc = nil then exit;
|
||||||
//
|
//
|
||||||
i := fDoc.MouseStart;
|
i := fDoc.MouseBytePosition;
|
||||||
if i = 0 then exit;
|
if i = 0 then exit;
|
||||||
//
|
//
|
||||||
terminateClient;
|
terminateClient;
|
||||||
|
|
|
@ -45,7 +45,7 @@ type
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TLexTokenKind = (ltkIllegal, ltkChar, ltkComment, ltkIdentifier, ltkKeyword,
|
TLexTokenKind = (ltkIllegal, ltkChar, ltkComment, ltkIdentifier, ltkKeyword,
|
||||||
ltkNumber, ltkOperator, ltkString, ltkSymbol);
|
ltkNumber, ltkOperator, ltkString, ltkSymbol, ltkWhite);
|
||||||
|
|
||||||
const
|
const
|
||||||
LexTokenKindString: array[TLexTokenKind] of string =
|
LexTokenKindString: array[TLexTokenKind] of string =
|
||||||
|
@ -57,7 +57,8 @@ const
|
||||||
'Number ',
|
'Number ',
|
||||||
'Operator ',
|
'Operator ',
|
||||||
'String ',
|
'String ',
|
||||||
'Symbol ');
|
'Symbol ',
|
||||||
|
'White ');
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ type
|
||||||
Data: string;
|
Data: string;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TLexOption = (lxoNoComments);
|
TLexOption = (lxoNoComments, lxoNoWhites);
|
||||||
TLexOptions = set of TLexOption;
|
TLexOptions = set of TLexOption;
|
||||||
|
|
||||||
TLexFoundEvent = procedure(const aToken: PLexToken; out doStop: boolean) of Object;
|
TLexFoundEvent = procedure(const aToken: PLexToken; out doStop: boolean) of Object;
|
||||||
|
@ -140,12 +141,12 @@ procedure lex(const text: string; list: TLexTokenList; clbck: TLexFoundEvent = n
|
||||||
(**
|
(**
|
||||||
* Outputs the module name from a tokenized D source.
|
* Outputs the module name from a tokenized D source.
|
||||||
*)
|
*)
|
||||||
function getModuleName(const list: TLexTokenList): string;
|
function getModuleName(list: TLexTokenList): string;
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Fills a list with all the modules imported in a tokenized D source.
|
* Fills a list with all the modules imported in a tokenized D source.
|
||||||
*)
|
*)
|
||||||
procedure getImports(const list: TLexTokenList; imports: TStrings);
|
procedure getImports(list: TLexTokenList; imports: TStrings);
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Compares two TPoints.
|
* Compares two TPoints.
|
||||||
|
@ -333,11 +334,17 @@ begin
|
||||||
identifier := '';
|
identifier := '';
|
||||||
|
|
||||||
// skip blanks
|
// skip blanks
|
||||||
while isWhite(reader.head^) do
|
if isWhite(reader.head^) then
|
||||||
begin
|
begin
|
||||||
if isOutOfBound then
|
reader.saveBeginning;
|
||||||
exit;
|
while isWhite(reader.head^) do
|
||||||
reader.Next;
|
begin
|
||||||
|
if isOutOfBound then
|
||||||
|
exit;
|
||||||
|
reader.Next;
|
||||||
|
end;
|
||||||
|
if not (lxoNoWhites in Options) then
|
||||||
|
addToken(ltkWhite);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// line comment
|
// line comment
|
||||||
|
@ -989,7 +996,7 @@ begin
|
||||||
Result.fIndex := -1;
|
Result.fIndex := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function getModuleName(const list: TLexTokenList): string;
|
function getModuleName(list: TLexTokenList): string;
|
||||||
var
|
var
|
||||||
ltk: PLexToken;
|
ltk: PLexToken;
|
||||||
mtok: boolean = false;
|
mtok: boolean = false;
|
||||||
|
@ -1016,7 +1023,7 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure getImports(const list: TLexTokenList; imports: TStrings);
|
procedure getImports(list: TLexTokenList; imports: TStrings);
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
imp: boolean = false;
|
imp: boolean = false;
|
||||||
|
|
|
@ -167,7 +167,7 @@ type
|
||||||
fAutoClosedPairs: TAutoClosePairs;
|
fAutoClosedPairs: TAutoClosePairs;
|
||||||
procedure decCallTipsLvl;
|
procedure decCallTipsLvl;
|
||||||
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
procedure setMatchOpts(value: TIdentifierMatchOptions);
|
||||||
function getMouseFileBytePos: Integer;
|
function getMouseBytePosition: Integer;
|
||||||
procedure changeNotify(Sender: TObject);
|
procedure changeNotify(Sender: TObject);
|
||||||
procedure highlightCurrentIdentifier;
|
procedure highlightCurrentIdentifier;
|
||||||
procedure saveCache;
|
procedure saveCache;
|
||||||
|
@ -257,7 +257,7 @@ type
|
||||||
property phobosDocRoot: string read fPhobosDocRoot write fPhobosDocRoot;
|
property phobosDocRoot: string read fPhobosDocRoot write fPhobosDocRoot;
|
||||||
property detectIndentMode: boolean read fDetectIndentMode write fDetectIndentMode;
|
property detectIndentMode: boolean read fDetectIndentMode write fDetectIndentMode;
|
||||||
property disableFileDateCheck: boolean read fDisableFileDateCheck write fDisableFileDateCheck;
|
property disableFileDateCheck: boolean read fDisableFileDateCheck write fDisableFileDateCheck;
|
||||||
property MouseStart: Integer read getMouseFileBytePos;
|
property MouseBytePosition: Integer read getMouseBytePosition;
|
||||||
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
property D2Highlighter: TSynD2Syn read fD2Highlighter;
|
||||||
property TxtHighlighter: TSynTxtSyn read fTxtHighlighter;
|
property TxtHighlighter: TSynTxtSyn read fTxtHighlighter;
|
||||||
property defaultFontSize: Integer read fDefaultFontSize write setDefaultFontSize;
|
property defaultFontSize: Integer read fDefaultFontSize write setDefaultFontSize;
|
||||||
|
@ -1355,9 +1355,10 @@ procedure TCESynMemo.autoClosePair(value: TAutoClosedPair);
|
||||||
var
|
var
|
||||||
i, p: integer;
|
i, p: integer;
|
||||||
tk0, tk1: PLexToken;
|
tk0, tk1: PLexToken;
|
||||||
|
str: string;
|
||||||
begin
|
begin
|
||||||
// TODO: editor SelStart doesnt match exactly, see why, also a problem in lexCanCloseBrace().
|
// TODO: editor SelStart doesnt match exactly, see why, also a problem in lexCanCloseBrace().
|
||||||
if value <> autoCloseSquareBracket then
|
if value in [autoCloseBackTick, autoCloseDoubleQuote] then
|
||||||
begin
|
begin
|
||||||
p := selStart;
|
p := selStart;
|
||||||
lex(Lines.Text, fLexToks);
|
lex(Lines.Text, fLexToks);
|
||||||
|
@ -1369,6 +1370,24 @@ begin
|
||||||
if tk0^.kind = TLexTokenKind.ltkString then
|
if tk0^.kind = TLexTokenKind.ltkString then
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
end else if value = autoCloseSingleQuote then
|
||||||
|
begin
|
||||||
|
p := selStart;
|
||||||
|
lex(Lines.Text, fLexToks);
|
||||||
|
for i:=0 to fLexToks.Count-2 do
|
||||||
|
begin
|
||||||
|
tk0 := fLexToks[i];
|
||||||
|
tk1 := fLexToks[i+1];
|
||||||
|
if (tk0^.offset+1 <= p) and (tk1^.offset+1 > p) then
|
||||||
|
if tk0^.kind = TLexTokenKind.ltkChar then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end else if value = autoCloseSquareBracket then
|
||||||
|
begin
|
||||||
|
str := lineText;
|
||||||
|
i := LogicalCaretXY.X;
|
||||||
|
if (i <= str.length) and (lineText[i] = ']') then
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
BeginUndoBlock;
|
BeginUndoBlock;
|
||||||
ExecuteCommand(ecChar, autoClosePair2Char[value], nil);
|
ExecuteCommand(ecChar, autoClosePair2Char[value], nil);
|
||||||
|
@ -1839,7 +1858,7 @@ begin
|
||||||
fFileDate := newDate;
|
fFileDate := newDate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCESynMemo.getMouseFileBytePos: Integer;
|
function TCESynMemo.getMouseBytePosition: Integer;
|
||||||
var
|
var
|
||||||
i, len, llen: Integer;
|
i, len, llen: Integer;
|
||||||
begin
|
begin
|
||||||
|
@ -1847,10 +1866,6 @@ begin
|
||||||
if fMousePos.y-1 > Lines.Count-1 then exit;
|
if fMousePos.y-1 > Lines.Count-1 then exit;
|
||||||
llen := Lines[fMousePos.y-1].length;
|
llen := Lines[fMousePos.y-1].length;
|
||||||
if fMousePos.X > llen then exit;
|
if fMousePos.X > llen then exit;
|
||||||
//
|
|
||||||
// something note really clear:
|
|
||||||
// TCEEditorWidget.getSymbolLoc works when using the line ending of the file.
|
|
||||||
// TCESynMemo.getMouseFileBytePos works when using the line ending from the system.
|
|
||||||
len := getSysLineEndLen;
|
len := getSysLineEndLen;
|
||||||
for i:= 0 to fMousePos.y-2 do
|
for i:= 0 to fMousePos.y-2 do
|
||||||
result += Lines[i].length + len;
|
result += Lines[i].length + len;
|
||||||
|
|
Loading…
Reference in New Issue