1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-06-29 09:20:38 +00:00

Makes F1 contextual help more flexible.

The detection of the keyword at the cursor will consider cases in which 
the cursor is just to the right of the last typed word.
This commit is contained in:
Fellippe Heitor 2021-01-26 22:53:30 -03:00
parent fe4c4996c9
commit e735ae1898

View file

@ -2445,177 +2445,172 @@ FUNCTION ide2 (ignore)
contextualhelp: contextualhelp:
IdeContextHelpSF = 0 IdeContextHelpSF = 0
'identify word or character at current cursor position 'identify word or character at current cursor position
a$ = idegetline(idecy) a2$ = UCASE$(getWordAtCursor$)
x = idecx 'check if F1 is in help links
IF LEN(a$) > 0 AND x = LEN(a$) + 1 THEN x = x - 1 fh = FREEFILE
IF x <= LEN(a$) THEN OPEN "internal\help\links.bin" FOR INPUT AS #fh
a2$ = UCASE$(getWordAtCursor$) lnks = 0: lnks$ = CHR$(0)
'check if F1 is in help links DO UNTIL EOF(fh)
fh = FREEFILE LINE INPUT #fh, l$
OPEN "internal\help\links.bin" FOR INPUT AS #fh c = INSTR(l$, ","): l1$ = LEFT$(l$, c - 1): l2$ = RIGHT$(l$, LEN(l$) - c)
lnks = 0: lnks$ = CHR$(0) IF a2$ = UCASE$(l1$) OR (qb64prefix_set = 1 AND LEFT$(l1$, 1) = "_" AND a2$ = MID$(l1$, 2)) THEN
DO UNTIL EOF(fh) IF INSTR(lnks$, CHR$(0) + l2$ + CHR$(0)) = 0 THEN
LINE INPUT #fh, l$ lnks = lnks + 1
c = INSTR(l$, ","): l1$ = LEFT$(l$, c - 1): l2$ = RIGHT$(l$, LEN(l$) - c) IF l2$ = l1$ THEN
IF a2$ = UCASE$(l1$) OR (qb64prefix_set = 1 AND LEFT$(l1$, 1) = "_" AND a2$ = MID$(l1$, 2)) THEN lnks$ = CHR$(0) + l2$ + lnks$
IF INSTR(lnks$, CHR$(0) + l2$ + CHR$(0)) = 0 THEN ELSE
lnks = lnks + 1 lnks$ = lnks$ + l2$ + CHR$(0)
IF l2$ = l1$ THEN
lnks$ = CHR$(0) + l2$ + lnks$
ELSE
lnks$ = lnks$ + l2$ + CHR$(0)
END IF
END IF END IF
END IF END IF
LOOP END IF
CLOSE #fh LOOP
CLOSE #fh
IF lnks THEN IF lnks THEN
lnks$ = MID$(lnks$, 2, LEN(lnks$) - 2) lnks$ = MID$(lnks$, 2, LEN(lnks$) - 2)
lnk$ = lnks$ lnk$ = lnks$
IF lnks > 1 THEN IF lnks > 1 THEN
'clarify context 'clarify context
lnk$ = idef1box$(lnks$, lnks) lnk$ = idef1box$(lnks$, lnks)
IF lnk$ = "C" THEN GOTO ideloop IF lnk$ = "C" THEN GOTO ideloop
END IF
IF INSTR(UCASE$(lnk$), "PARENTHESIS") THEN GOTO ideloop
OpenHelpLnk:
Help_Back(Help_Back_Pos).sx = Help_sx 'update position
Help_Back(Help_Back_Pos).sy = Help_sy
Help_Back(Help_Back_Pos).cx = Help_cx
Help_Back(Help_Back_Pos).cy = Help_cy
top = UBOUND(back$)
IF Back$(Help_Back_Pos) = lnk$ THEN Help_Back_Pos = Help_Back_Pos - 1: GOTO usenextentry2
IF Help_Back_Pos < top THEN
IF Back$(Help_Back_Pos + 1) = lnk$ THEN
GOTO usenextentry2
END IF END IF
END IF
OpenHelpLnk: top = top + 1
REDIM _PRESERVE Back(top) AS STRING
REDIM _PRESERVE Help_Back(top) AS Help_Back_Type
REDIM _PRESERVE Back_Name(top) AS STRING
'Shuffle array upwards after current pos
FOR x = top - 1 TO Help_Back_Pos + 1 STEP -1
Back_Name$(x + 1) = Back_Name$(x)
Back$(x + 1) = Back$(x)
Help_Back(x + 1).sx = Help_Back(x).sx
Help_Back(x + 1).sy = Help_Back(x).sy
Help_Back(x + 1).cx = Help_Back(x).cx
Help_Back(x + 1).cy = Help_Back(x).cy
NEXT
usenextentry2:
Help_Back_Pos = Help_Back_Pos + 1
Back$(Help_Back_Pos) = lnk$
Back_Name$(Help_Back_Pos) = Back2BackName$(lnk$)
Help_Back(Help_Back_Pos).sx = 1
Help_Back(Help_Back_Pos).sy = 1
Help_Back(Help_Back_Pos).cx = 1
Help_Back(Help_Back_Pos).cy = 1
Help_sx = 1: Help_sy = 1: Help_cx = 1: Help_cy = 1
a$ = Wiki(lnk$)
Help_Back(Help_Back_Pos).sx = Help_sx 'update position IF idehelp = 0 THEN
Help_Back(Help_Back_Pos).sy = Help_sy IF idesubwindow THEN PCOPY 3, 0: SCREEN , , 3, 0: GOTO ideloop
Help_Back(Help_Back_Pos).cx = Help_cx idesubwindow = idewy \ 2: idewy = idewy - idesubwindow
Help_Back(Help_Back_Pos).cy = Help_cy Help_wx1 = 2: Help_wy1 = idewy + 1: Help_wx2 = idewx - 1: Help_wy2 = idewy + idesubwindow - 2: Help_ww = Help_wx2 - Help_wx1 + 1: Help_wh = Help_wy2 - Help_wy1 + 1
top = UBOUND(back$)
IF Back$(Help_Back_Pos) = lnk$ THEN Help_Back_Pos = Help_Back_Pos - 1: GOTO usenextentry2
IF Help_Back_Pos < top THEN
IF Back$(Help_Back_Pos + 1) = lnk$ THEN
GOTO usenextentry2
END IF
END IF
top = top + 1
REDIM _PRESERVE Back(top) AS STRING
REDIM _PRESERVE Help_Back(top) AS Help_Back_Type
REDIM _PRESERVE Back_Name(top) AS STRING
'Shuffle array upwards after current pos
FOR x = top - 1 TO Help_Back_Pos + 1 STEP -1
Back_Name$(x + 1) = Back_Name$(x)
Back$(x + 1) = Back$(x)
Help_Back(x + 1).sx = Help_Back(x).sx
Help_Back(x + 1).sy = Help_Back(x).sy
Help_Back(x + 1).cx = Help_Back(x).cx
Help_Back(x + 1).cy = Help_Back(x).cy
NEXT
usenextentry2:
Help_Back_Pos = Help_Back_Pos + 1
Back$(Help_Back_Pos) = lnk$
Back_Name$(Help_Back_Pos) = Back2BackName$(lnk$)
Help_Back(Help_Back_Pos).sx = 1
Help_Back(Help_Back_Pos).sy = 1
Help_Back(Help_Back_Pos).cx = 1
Help_Back(Help_Back_Pos).cy = 1
Help_sx = 1: Help_sy = 1: Help_cx = 1: Help_cy = 1
a$ = Wiki(lnk$)
IF idehelp = 0 THEN
IF idesubwindow THEN PCOPY 3, 0: SCREEN , , 3, 0: GOTO ideloop
idesubwindow = idewy \ 2: idewy = idewy - idesubwindow
Help_wx1 = 2: Help_wy1 = idewy + 1: Help_wx2 = idewx - 1: Help_wy2 = idewy + idesubwindow - 2: Help_ww = Help_wx2 - Help_wx1 + 1: Help_wh = Help_wy2 - Help_wy1 + 1
WikiParse a$
idehelp = 1
skipdisplay = 0
IdeSystem = 3
retval = 1
END IF
WikiParse a$ WikiParse a$
idehelp = 1
skipdisplay = 0
IdeSystem = 3 IdeSystem = 3
GOSUB redrawitall retval = 1
GOTO specialchar END IF
ELSE WikiParse a$
'No help found; Does the user want help for a SUB or FUNCTION? IdeSystem = 3
a2$ = LTRIM$(RTRIM$(a2$)) GOSUB redrawitall
IF LEN(a2$) THEN GOTO specialchar
DO UNTIL alphanumeric(ASC(RIGHT$(a2$, 1)))
a2$ = LEFT$(a2$, LEN(a2$) - 1) 'removes sigil, if any
IF LEN(a2$) = 0 THEN GOTO NoKeywordFound
LOOP
FOR y = 1 TO iden ELSE
a$ = idegetline(y) 'No help found; Does the user want help for a SUB or FUNCTION?
a$ = LTRIM$(RTRIM$(a$)) a2$ = LTRIM$(RTRIM$(a2$))
sf = 0 IF LEN(a2$) THEN
nca$ = UCASE$(a$) DO UNTIL alphanumeric(ASC(RIGHT$(a2$, 1)))
IF LEFT$(nca$, 4) = "SUB " THEN sf = 1: sf$ = "SUB " a2$ = LEFT$(a2$, LEN(a2$) - 1) 'removes sigil, if any
IF LEFT$(nca$, 9) = "FUNCTION " THEN sf = 2: sf$ = "FUNCTION " IF LEN(a2$) = 0 THEN GOTO NoKeywordFound
IF sf THEN LOOP
IF RIGHT$(nca$, 7) = " STATIC" THEN
a$ = RTRIM$(LEFT$(a$, LEN(a$) - 7))
END IF
IF sf = 1 THEN FOR y = 1 TO iden
a$ = RIGHT$(a$, LEN(a$) - 4) a$ = idegetline(y)
ELSE a$ = LTRIM$(RTRIM$(a$))
a$ = RIGHT$(a$, LEN(a$) - 9) sf = 0
END IF nca$ = UCASE$(a$)
a$ = LTRIM$(RTRIM$(a$)) IF LEFT$(nca$, 4) = "SUB " THEN sf = 1: sf$ = "SUB "
x = INSTR(a$, "(") IF LEFT$(nca$, 9) = "FUNCTION " THEN sf = 2: sf$ = "FUNCTION "
IF x THEN IF sf THEN
n$ = RTRIM$(LEFT$(a$, x - 1)) IF RIGHT$(nca$, 7) = " STATIC" THEN
args$ = RIGHT$(a$, LEN(a$) - x + 1) a$ = RTRIM$(LEFT$(a$, LEN(a$) - 7))
x = INSTR(args$, ")"): IF x THEN args$ = LEFT$(args$, x)
ELSE
n$ = a$
args$ = ""
cleanSubName n$
END IF
backupn$ = n$
DO UNTIL alphanumeric(ASC(RIGHT$(n$, 1)))
n$ = LEFT$(n$, LEN(n$) - 1) 'removes sigil, if any
LOOP
IF UCASE$(n$) = a2$ THEN
a$ = "'''" + backupn$ + "''' is a symbol that is used in your program as follows:"
a$ = a$ + CHR$(10) + CHR$(10) + "{{PageSyntax}}" + CHR$(10)
a$ = a$ + ": " + sf$ + "'''" + backupn$ + "''' " + args$
a$ = a$ + CHR$(10) + "{{PageNavigation}}"
IdeContextHelpSF = -1
IF idehelp = 0 THEN
IF idesubwindow THEN PCOPY 3, 0: SCREEN , , 3, 0: GOTO ideloop
idesubwindow = idewy \ 2: idewy = idewy - idesubwindow
Help_wx1 = 2: Help_wy1 = idewy + 1: Help_wx2 = idewx - 1: Help_wy2 = idewy + idesubwindow - 2: Help_ww = Help_wx2 - Help_wx1 + 1: Help_wh = Help_wy2 - Help_wy1 + 1
WikiParse a$
idehelp = 1
skipdisplay = 0
IdeSystem = 3
retval = 1
END IF
WikiParse a$
IdeSystem = 3
GOTO specialchar
EXIT FOR
END IF
END IF END IF
NEXT
END IF
NoKeywordFound:
END IF 'lnks
END IF IF sf = 1 THEN
a$ = RIGHT$(a$, LEN(a$) - 4)
ELSE
a$ = RIGHT$(a$, LEN(a$) - 9)
END IF
a$ = LTRIM$(RTRIM$(a$))
x = INSTR(a$, "(")
IF x THEN
n$ = RTRIM$(LEFT$(a$, x - 1))
args$ = RIGHT$(a$, LEN(a$) - x + 1)
x = INSTR(args$, ")"): IF x THEN args$ = LEFT$(args$, x)
ELSE
n$ = a$
args$ = ""
cleanSubName n$
END IF
backupn$ = n$
DO UNTIL alphanumeric(ASC(RIGHT$(n$, 1)))
n$ = LEFT$(n$, LEN(n$) - 1) 'removes sigil, if any
LOOP
IF UCASE$(n$) = a2$ THEN
a$ = "'''" + backupn$ + "''' is a symbol that is used in your program as follows:"
a$ = a$ + CHR$(10) + CHR$(10) + "{{PageSyntax}}" + CHR$(10)
a$ = a$ + ": " + sf$ + "'''" + backupn$ + "''' " + args$
a$ = a$ + CHR$(10) + "{{PageNavigation}}"
IdeContextHelpSF = -1
IF idehelp = 0 THEN
IF idesubwindow THEN PCOPY 3, 0: SCREEN , , 3, 0: GOTO ideloop
idesubwindow = idewy \ 2: idewy = idewy - idesubwindow
Help_wx1 = 2: Help_wy1 = idewy + 1: Help_wx2 = idewx - 1: Help_wy2 = idewy + idesubwindow - 2: Help_ww = Help_wx2 - Help_wx1 + 1: Help_wh = Help_wy2 - Help_wy1 + 1
WikiParse a$
idehelp = 1
skipdisplay = 0
IdeSystem = 3
retval = 1
END IF
WikiParse a$
IdeSystem = 3
GOTO specialchar
EXIT FOR
END IF
END IF
NEXT
END IF
NoKeywordFound:
END IF 'lnks
GOTO specialchar GOTO specialchar
END IF END IF
@ -13147,7 +13142,7 @@ SUB IdeMakeContextualMenu
IF LEN(l2$) > 15 THEN IF LEN(l2$) > 15 THEN
l2$ = LEFT$(l2$, 12) + STRING$(3, 250) l2$ = LEFT$(l2$, 12) + STRING$(3, 250)
END IF END IF
IF INSTR(l2$, "Parenthesis") = 0 THEN IF INSTR(l2$, "PARENTHESIS") = 0 THEN
menu$(m, i) = "#Help On '" + l2$ + "'": i = i + 1 menu$(m, i) = "#Help On '" + l2$ + "'": i = i + 1
END IF END IF
END IF END IF
@ -14416,6 +14411,10 @@ FUNCTION getWordAtCursor$
a$ = idegetline(idecy) a$ = idegetline(idecy)
x = idecx x = idecx
IF x <= LEN(a$) THEN IF x <= LEN(a$) THEN
IF ASC(a$, x) = 32 AND x > 1 THEN
IF ASC(a$, x - 1) <> 32 THEN x = x - 1
END IF
try:
IF alphanumeric(ASC(a$, x)) THEN IF alphanumeric(ASC(a$, x)) THEN
x1 = x x1 = x
DO WHILE x1 > 1 DO WHILE x1 > 1
@ -14430,6 +14429,8 @@ FUNCTION getWordAtCursor$
a2$ = CHR$(ASC(a$, x)) a2$ = CHR$(ASC(a$, x))
END IF END IF
getWordAtCursor$ = a2$ 'a2$ now holds the word or character at current cursor position getWordAtCursor$ = a2$ 'a2$ now holds the word or character at current cursor position
ELSEIF x = LEN(a$) + 1 AND x > 1 THEN
IF ASC(a$, x - 1) <> 32 THEN x = x - 1: GOTO try
END IF END IF
END FUNCTION END FUNCTION