From 70ea1491682c403d743bbef81a373aa2e6a0b99a Mon Sep 17 00:00:00 2001 From: Fellippe Heitor Date: Thu, 4 Feb 2021 22:21:31 -0300 Subject: [PATCH] Offers to auto-close blocks with Shift+ENTER --- source/ide/ide_global.bas | 1 + source/ide/ide_methods.bas | 56 ++++++++++++++++++++++++++++++++------ source/qb64.bas | 11 ++++---- 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/source/ide/ide_global.bas b/source/ide/ide_global.bas index cc636937d..fba027b07 100644 --- a/source/ide/ide_global.bas +++ b/source/ide/ide_global.bas @@ -191,6 +191,7 @@ TYPE idedbotype END TYPE '-------------------------------------------------------------------------------- DIM SHARED idefocusline 'simply stores the location of the line to highlight in red +DIM SHARED idecompilererrormessage$ DIM SHARED ideautorun DIM SHARED menu$(1 TO 10, 0 TO 20) DIM SHARED menusize(1 TO 10) diff --git a/source/ide/ide_methods.bas b/source/ide/ide_methods.bas index 948b372b5..88a1f5d63 100644 --- a/source/ide/ide_methods.bas +++ b/source/ide/ide_methods.bas @@ -849,11 +849,12 @@ FUNCTION ide2 (ignore) 'scrolling unavailable, but may span multiple lines IF compfailed THEN a$ = MID$(c$, 2, LEN(c$) - 5) - + idecompilererrormessage$ = a$ x = 1 y = idewy - 3 FOR i = 1 TO LEN(a$) IF ASC(a$, i) = 0 THEN + idecompilererrormessage$ = LEFT$(a$, i - 1) IF _DEFAULTCOLOR = 7 THEN COLOR 11 ELSE COLOR 7 _CONTINUE END IF @@ -864,7 +865,7 @@ FUNCTION ide2 (ignore) statusarealink = 1 ELSE a$ = MID$(c$, 2, LEN(c$) - 5) - + idecompilererrormessage$ = a$ l = CVL(RIGHT$(c$, 4)): IF l <> 0 THEN idefocusline = l @@ -3541,18 +3542,39 @@ FUNCTION ide2 (ignore) IF K$ = CHR$(13) THEN IF KSHIFT THEN retval$ = "" - IF EnteringRGB THEN 'The "Hit Shift+ENTER" message is being shown + a$ = idegetline(idecy) + IF EnteringRGB THEN 'The "Shift+ENTER" message is being shown oldkeywordHighlight = keywordHighlight keywordHighlight = 0 HideBracketHighlight keywordHighlight = oldkeywordHighlight retval$ = idergbmixer$(0) + ELSEIF idefocusline > 0 AND LEN(_TRIM$(a$)) = 0 THEN + + 'close open block + IF idefocusline = definingtypeerror THEN + insertAtCursor SCase$("End Type"): GOTO specialchar + ELSEIF idefocusline = controlref(controllevel) AND INSTR(idecompilererrormessage$, " without ") > 0 THEN + SELECT EVERYCASE controltype(controllevel) + CASE 1: insertAtCursor SCase$("End If"): GOTO specialchar + CASE 2: insertAtCursor SCase$("Next"): GOTO specialchar + CASE 3, 4: insertAtCursor SCase$("Loop"): GOTO specialchar + CASE 5: insertAtCursor SCase$("Wend"): GOTO specialchar + CASE 6: insertAtCursor SCase$("$End If"): GOTO specialchar + CASE 10 TO 19: insertAtCursor SCase$("End Select"): GOTO specialchar + CASE 32 + IF LEFT$(subfunc, 4) = "SUB_" THEN + insertAtCursor SCase$("End Sub"): GOTO specialchar + ELSE + insertAtCursor SCase$("End Function"): GOTO specialchar + END IF + END SELECT + END IF ELSE IF ideselect THEN IF ideselecty1 <> idecy THEN GOTO specialchar 'multi line selected END IF - a$ = idegetline(idecy) Found_RGB = 0 Found_RGB = Found_RGB + INSTR(UCASE$(a$), "RGB(") Found_RGB = Found_RGB + INSTR(UCASE$(a$), "RGB32(") @@ -8070,7 +8092,7 @@ SUB ideshowtext a$ = idegetline(l) link_idecx = 0 - rgb_idecx = 0 + shiftEnter_idecx = 0 IF l = idecy THEN IF idecx <= LEN(a$) AND idecx >= 1 THEN cc = ASC(a$, idecx) @@ -8150,8 +8172,8 @@ SUB ideshowtext RIGHT$(a2$, 6) = "RGB32(" OR _ RIGHT$(a2$, 5) = "RGBA(" OR _ RIGHT$(a2$, 7) = "RGBA32(") AND qb64prefix_set = 1) THEN - rgb_idecx = LEN(a$) - a$ = a$ + " --> Hit Shift+ENTER to open the RGB mixer" + shiftEnter_idecx = LEN(a$) + a$ = a$ + " --> Shift+ENTER to open the RGB mixer" EnteringRGB = -1 END IF ELSEIF idecx_comment + idecx_quote = 0 THEN @@ -8177,6 +8199,22 @@ SUB ideshowtext f$ = p$ + ActiveINCLUDELinkFile IF _FILEEXISTS(f$) THEN a$ = a$ + " --> Double-click to open": ActiveINCLUDELink = idecy END IF + ELSE + temp_a$ = idegetline(idecy) + IF idefocusline = l AND LEN(_TRIM$(temp_a$)) = 0 THEN + 'some errors are mere blocks the user just opened and is still + 'working on. This bit will offer to close said blocks. + IF idefocusline = definingtypeerror THEN + shiftEnter_idecx = LEN(a$) + a$ = a$ + " --> Shift+ENTER to close block" + ELSEIF idefocusline = controlref(controllevel) AND INSTR(idecompilererrormessage$, " without ") > 0 THEN + SELECT EVERYCASE controltype(controllevel) + CASE 1 to 6,10 to 19,32 + shiftEnter_idecx = LEN(a$) + a$ = a$ + " --> Shift+ENTER to close block" + END SELECT + END IF + END IF END IF 'l = idecy a2$ = SPACE$(idesx + (idewx - 3)) @@ -8320,8 +8358,8 @@ SUB ideshowtext SkipSyntaxHighlighter: - IF l = idecy AND ((link_idecx > 0 AND m > link_idecx) OR _ - (rgb_idecx > 0 AND m > rgb_idecx)) THEN COLOR 10 + IF l = idecy AND (link_idecx > 0 AND m > link_idecx) THEN COLOR 10 + IF (shiftEnter_idecx > 0 AND m > shiftEnter_idecx) THEN COLOR 10 IF l = idecy AND (m = bracket1 OR m = bracket2) THEN COLOR , 5 diff --git a/source/qb64.bas b/source/qb64.bas index a47178ae5..f03c96fcd 100644 --- a/source/qb64.bas +++ b/source/qb64.bas @@ -764,7 +764,7 @@ DIM SHARED findidsecondarg AS STRING DIM SHARED findanotherid AS INTEGER DIM SHARED findidinternal AS LONG DIM SHARED currentid AS LONG 'is the index of the last ID accessed -DIM SHARED linenumber AS LONG, reallinenumber AS LONG, totallinenumber AS LONG +DIM SHARED linenumber AS LONG, reallinenumber AS LONG, totallinenumber AS LONG, definingtypeerror AS LONG DIM SHARED wholeline AS STRING DIM SHARED linefragment AS STRING 'COMMON SHARED bitmask() AS _INTEGER64 @@ -852,8 +852,8 @@ DIM SHARED everycasenewcase AS LONG -DIM controllevel AS INTEGER '0=not in a control block -DIM controltype(1000) AS INTEGER +DIM SHARED controllevel AS INTEGER '0=not in a control block +DIM SHARED controltype(1000) AS INTEGER '1=IF (awaiting END IF) '2=FOR (awaiting NEXT) '3=DO (awaiting LOOP [UNTIL|WHILE param]) @@ -874,7 +874,7 @@ DIM controltype(1000) AS INTEGER DIM controlid(1000) AS LONG DIM controlvalue(1000) AS LONG DIM controlstate(1000) AS INTEGER -DIM controlref(1000) AS LONG 'the line number the control was created on +DIM SHARED controlref(1000) AS LONG 'the line number the control was created on @@ -1376,6 +1376,7 @@ nextrunlineindex = 1 lasttype = 0 lasttypeelement = 0 definingtype = 0 +definingtypeerror = 0 constlast = -1 'constlastshared = -1 defdatahandle = 18 @@ -3619,7 +3620,7 @@ DO GOTO finishednonexec END IF - IF n < 3 THEN a$ = "Expected element-name AS type or AS type element-list": GOTO errmes + IF n < 3 THEN definingtypeerror = linenumber: a$ = "Expected element-name AS type or AS type element-list": GOTO errmes definingtype = 2 IF firstelement$ = "AS" THEN l$ = SCase$("As")