With following change in Document::BraceMatch():
- position = NextPosition(position, direction);
+ position = NextPosition(maxReStyle ? maxReStyle : position, direction);
This is useful for application that implement auto completion for braces/parentheses/brackets, though the change might not at right place as maxReStyle is reserved for further use.
Consider following tow cases, after typing left parenthesis, caret is after it, in SCN_CHARADDED:
BraceMatch(GetCurrentPos() - 1, 0) to find the right parenthesis position rightPos.BraceMatch(rightPos, GetCurrentPos() - 1) to check whether the right parenthesis already matched before typing left parenthesis.// case 1
( ... ( ... )
^
// case 2
( ....)
^
BraceMatch checks that styles match in order to prevent matching unbalanced braces inside strings or literals. When checking beyond the valid styles, any style is considered matching but this may be incorrect, so
maxReStyleis for extending styling further. It just hasn't been implemented as it is low priority.The proposed change to the second argument is dificult to explain so should be a distinct API.
How about:
It's same as BraceMatch, except that only finds matching brace in target range (inclusive like SearchInTarget?), through the brace position pos it self may not in target range.
BraceMatch can be treated as BraceMatchInTarget with whole document target.
Last edit: Zufu Liu 2020-07-08
BraceMatchInTarget is easier to understand.
It may be better to go back to your motivation here: the task is to work out the matching state prior to the character insertion. Perhaps a more direct implementation would be
BraceMatch(position, ignoring: insertionPosition).Its not much use adding APIs that won't be used when its not clear why you would want to use them.
Both approach does not work: after typing left parenthesis, endStyled is set to
GetCurrentPos() - 1, so BraceMatch() returns a random position for first matching right parenthesis regardless of the style.Its likely you can force styling with SCI_COLOURISE inside your SCN_CHARADDED.
How about
BraceMatchNext=(position, startPosition), similar to BraceMatch, but set the explicit start position instead of the implicitly next positionposition ± 1.OK.
Added a implementation, changed Document::BraceMatch() into:
Committed as [a2ce85].
Related
Commit: [a2ce85]