Page 1 of 1
Autocomplete for bracket and quote
Posted: Thu Dec 10, 2015 1:08 pm
by Wolfram
Would be grate to have a autocomplete for bracket and quotes.
I mean, if I type ( I will get () and the cursor is between the bracket.
If I type () the cursor is behind the brackets.
Re: Autocomplete for bracket and quote
Posted: Sat Dec 30, 2017 11:51 am
by Sicro
+1
Re: Autocomplete for bracket and quote
Posted: Mon Jan 01, 2018 12:18 am
by Dude
Wolfram wrote:if I type ( I will get () and the cursor is between the bracket.
If I type () the cursor is behind the brackets.
You'll
never be able to type () and have the cursor behind the brackets, because as soon as you type the first bracket then the second will be added and the cursor put between them (ie. your first request will be done).

Re: Autocomplete for bracket and quote
Posted: Mon Jan 01, 2018 1:43 am
by Sicro
@Dude:
Think about it again.

1. You type "(" and ")" is appended. The cursor is now inside the brackets.
2. You type ")" and the automatically appended ")" will be overwritten. The cursor is now behind the ")".
P.S. Happy New Year

Re: Autocomplete for bracket and quote
Posted: Mon Jan 01, 2018 8:47 am
by Dude
Sorry, I don't get it.
After typing "(" the IDE puts "(|)" with the cursor in the middle. Correct? (Note the "|" means cursor).
But then the user then types ")" and the IDE shows "(|))" for a moment, but deletes it and makes it "()|" instead?
Is that right?
Re: Autocomplete for bracket and quote
Posted: Mon Jan 01, 2018 3:09 pm
by Sicro
Dude wrote:After typing "(" the IDE puts "(|)" with the cursor in the middle. Correct? (Note the "|" means cursor).
Yes.
Dude wrote:But then the user then types ")" and the IDE shows "(|))" for a moment, but deletes it and makes it "()|" instead?
Yes, but strictly speaking it looks like this:
I thought about it again and now I have come to the conclusion that the auto-completion algorithm for brackets (and quotes) should work like this:
Code: Select all
Procedure OnKeyPress(Char$)
Select Char$
Case "("
WriteChar(Char$) ; | => (|
WriteChar(")") ; (| => ()|
SetCursorPos(GetCursorPos() - 1) ; ()| => (|)
Case ")"
If GetCharBeforeCursor() = "(" And GetCharAfterCursor() = ")"
SetCursorPos(GetCursorPos() + 1) ; (|) => ()|
Else
WriteChar(Char$) ; ?|? => ?)|?
EndIf
EndSelect
EndProcedure