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

Adds ability to search only in comments and strings.

This commit is contained in:
FellippeHeitor 2021-01-06 02:17:19 -03:00
parent c88c56330c
commit 032dd33b6f
2 changed files with 114 additions and 62 deletions

View file

@ -149,6 +149,7 @@ DIM SHARED idefindcasesens AS INTEGER
DIM SHARED idefindwholeword AS INTEGER DIM SHARED idefindwholeword AS INTEGER
DIM SHARED idefindbackwards AS INTEGER DIM SHARED idefindbackwards AS INTEGER
DIM SHARED idefindnocomments AS INTEGER, idefindnostrings AS INTEGER DIM SHARED idefindnocomments AS INTEGER, idefindnostrings AS INTEGER
DIM SHARED idefindonlycomments AS INTEGER, idefindonlystrings AS INTEGER
DIM SHARED idefindinvert AS INTEGER DIM SHARED idefindinvert AS INTEGER
DIM SHARED idechangeto AS STRING DIM SHARED idechangeto AS STRING
DIM SHARED idechangemade AS INTEGER DIM SHARED idechangemade AS INTEGER

View file

@ -5353,9 +5353,11 @@ FUNCTION ide2 (ignore)
DIM comment AS _BYTE, quote AS _BYTE DIM comment AS _BYTE, quote AS _BYTE
IF x THEN IF x THEN
findquotecomment$ = LEFT$(l$, x): GOSUB FindQuoteComment FindQuoteComment l$, x, comment, quote
IF idefindnocomments <> 0 AND comment THEN x = 0 IF idefindnocomments <> 0 AND comment THEN x = 0
IF idefindnostrings <> 0 AND quote THEN x = 0 IF idefindnostrings <> 0 AND quote THEN x = 0
IF idefindonlycomments <> 0 AND comment = 0 THEN x = 0
IF idefindonlystrings <> 0 AND quote = 0 THEN x = 0
END IF END IF
IF x THEN IF x THEN
@ -5886,17 +5888,6 @@ FUNCTION ide2 (ignore)
END IF END IF
END IF END IF
RETURN RETURN
FindQuoteComment:
comment = 0: quote = 0
FOR find_k = 1 TO LEN(findquotecomment$)
SELECT CASE MID$(findquotecomment$, find_k, 1)
CASE CHR$(34): quote = NOT quote
CASE "'": IF quote = 0 THEN comment = -1: EXIT FOR
END SELECT
NEXT find_k
RETURN
END FUNCTION END FUNCTION
SUB idebox (x, y, w, h) SUB idebox (x, y, w, h)
@ -6032,12 +6023,26 @@ FUNCTION idechange$
o(i).nam = idenewtxt("#Ignore 'comments") o(i).nam = idenewtxt("#Ignore 'comments")
o(i).sel = idefindnocomments o(i).sel = idefindnocomments
i = i + 1
o(i).typ = 4 'check box
o(i).x = 29
o(i).y = 11
o(i).nam = idenewtxt("#Look only in 'comments")
o(i).sel = idefindonlycomments
i = i + 1 i = i + 1
o(i).typ = 4 'check box o(i).typ = 4 'check box
o(i).y = 12 o(i).y = 12
o(i).nam = idenewtxt("#Ignore " + CHR$(34) + "strings" + CHR$(34)) o(i).nam = idenewtxt("Ignore " + CHR$(34) + "#strings" + CHR$(34))
o(i).sel = idefindnostrings o(i).sel = idefindnostrings
i = i + 1
o(i).typ = 4 'check box
o(i).x = 29
o(i).y = 12
o(i).nam = idenewtxt("Look only in " + CHR$(34) + "st#rings" + CHR$(34))
o(i).sel = idefindonlystrings
i = i + 1 i = i + 1
o(i).typ = 3 o(i).typ = 3
o(i).y = 14 o(i).y = 14
@ -6133,7 +6138,22 @@ FUNCTION idechange$
END IF END IF
END IF END IF
IF K$ = CHR$(27) OR (focus = 10 AND info <> 0) THEN 'mutually exclusive options
IF focus = 6 AND o(6).sel = 1 THEN
o(7).sel = 0
ELSEIF focus = 7 AND o(7).sel = 1 THEN
o(6).sel = 0
o(8).sel = 0
o(9).sel = 0
ELSEIF focus = 8 AND o(8).sel = 1 THEN
o(9).sel = 0
ELSEIF focus = 9 AND o(9).sel = 1 THEN
o(6).sel = 0
o(7).sel = 0
o(8).sel = 0
END IF
IF K$ = CHR$(27) OR (focus = 12 AND info <> 0) THEN
idechange$ = "C" idechange$ = "C"
EXIT FUNCTION EXIT FUNCTION
END IF END IF
@ -6158,12 +6178,14 @@ FUNCTION idechange$
END IF END IF
END IF END IF
IF focus = 9 AND info <> 0 THEN 'change all IF focus = 11 AND info <> 0 THEN 'change all
idefindcasesens = o(3).sel idefindcasesens = o(3).sel
idefindwholeword = o(4).sel idefindwholeword = o(4).sel
idefindbackwards = o(5).sel idefindbackwards = o(5).sel
idefindnocomments = o(6).sel idefindnocomments = o(6).sel
idefindnostrings = o(7).sel idefindonlycomments = o(7).sel
idefindnostrings = o(8).sel
idefindonlystrings = o(9).sel
s$ = idetxt(o(1).txt) s$ = idetxt(o(1).txt)
idefindtext$ = s$ idefindtext$ = s$
@ -6210,9 +6232,11 @@ FUNCTION idechange$
DIM comment AS _BYTE, quote AS _BYTE DIM comment AS _BYTE, quote AS _BYTE
IF x THEN IF x THEN
findquotecomment$ = LEFT$(l$, x): GOSUB FindQuoteComment FindQuoteComment l$, x, comment, quote
IF idefindnocomments <> 0 AND comment THEN x = 0 IF idefindnocomments <> 0 AND comment THEN x = 0
IF idefindnostrings <> 0 AND quote THEN x = 0 IF idefindnostrings <> 0 AND quote THEN x = 0
IF idefindonlycomments <> 0 AND comment = 0 THEN x = 0
IF idefindonlystrings <> 0 AND quote = 0 THEN x = 0
END IF END IF
IF x THEN IF x THEN
@ -6233,12 +6257,14 @@ FUNCTION idechange$
END IF 'change all END IF 'change all
IF (focus = 8 AND info <> 0) OR K$ = CHR$(13) THEN IF (focus = 10 AND info <> 0) OR K$ = CHR$(13) THEN
idefindcasesens = o(3).sel idefindcasesens = o(3).sel
idefindwholeword = o(4).sel idefindwholeword = o(4).sel
idefindbackwards = o(5).sel idefindbackwards = o(5).sel
idefindnocomments = o(6).sel idefindnocomments = o(6).sel
idefindnostrings = o(7).sel idefindonlycomments = o(7).sel
idefindnostrings = o(8).sel
idefindonlystrings = o(9).sel
idefindtext$ = idetxt(o(1).txt) idefindtext$ = idetxt(o(1).txt)
idechangeto$ = idetxt(o(2).txt) idechangeto$ = idetxt(o(2).txt)
idechange$ = "V" idechange$ = "V"
@ -6254,18 +6280,30 @@ FUNCTION idechange$
mouseup = 0 mouseup = 0
LOOP LOOP
EXIT FUNCTION END FUNCTION
FindQuoteComment:
comment = 0: quote = 0 SUB FindQuoteComment (text$, __cursor AS LONG, c AS _BYTE, q AS _BYTE)
FOR find_k = 1 TO LEN(findquotecomment$) c = 0: q = 0
SELECT CASE MID$(findquotecomment$, find_k, 1) cursor = __cursor
CASE CHR$(34): quote = NOT quote IF cursor > LEN(text$) THEN cursor = LEN(text$)
CASE "'": IF quote = 0 THEN comment = -1: EXIT FOR FOR find_k = 1 TO cursor
SELECT CASE MID$(text$, find_k, 1)
CASE CHR$(34): q = NOT q
CASE "'": IF q = 0 THEN c = -1: EXIT FOR
CASE "R", "r"
IF q = 0 THEN
IF UCASE$(MID$(text$, find_k - 1, 5)) = " REM " OR _
UCASE$(MID$(text$, find_k - 1, 5)) = ":REM " OR _
(find_k + 2 = LEN(text$) AND UCASE$(MID$(text$, find_k - 1, 4)) = " REM") OR _
(find_k + 2 = LEN(text$) AND UCASE$(MID$(text$, find_k - 1, 4)) = ":REM") OR _
(find_k = 1 AND UCASE$(LEFT$(text$, 4)) = "REM ") OR _
(find_k = 1 AND UCASE$(text$) = "REM") THEN
c = -1: EXIT FOR
END IF
END IF
END SELECT END SELECT
NEXT find_k NEXT find_k
RETURN END SUB
END FUNCTION
SUB idechanged SUB idechanged
@ -7059,12 +7097,26 @@ FUNCTION idefind$
o(i).nam = idenewtxt("#Ignore 'comments") o(i).nam = idenewtxt("#Ignore 'comments")
o(i).sel = idefindnocomments o(i).sel = idefindnocomments
i = i + 1
o(i).typ = 4 'check box
o(i).x = 29
o(i).y = 8
o(i).nam = idenewtxt("#Look only in 'comments")
o(i).sel = idefindonlycomments
i = i + 1 i = i + 1
o(i).typ = 4 'check box o(i).typ = 4 'check box
o(i).y = 9 o(i).y = 9
o(i).nam = idenewtxt("#Ignore " + CHR$(34) + "strings" + CHR$(34)) o(i).nam = idenewtxt("Ignore " + CHR$(34) + "s#trings" + CHR$(34))
o(i).sel = idefindnostrings o(i).sel = idefindnostrings
i = i + 1
o(i).typ = 4 'check box
o(i).x = 29
o(i).y = 9
o(i).nam = idenewtxt("Look only in " + CHR$(34) + "st#rings" + CHR$(34))
o(i).sel = idefindonlystrings
i = i + 1 i = i + 1
o(i).typ = 3 o(i).typ = 3
o(i).y = 11 o(i).y = 11
@ -7155,17 +7207,34 @@ FUNCTION idefind$
END IF END IF
END IF END IF
IF K$ = CHR$(27) OR (focus = 8 AND info <> 0) THEN IF K$ = CHR$(27) OR (focus = 10 AND info <> 0) THEN
idefind$ = "C" idefind$ = "C"
EXIT FUNCTION EXIT FUNCTION
END IF END IF
IF K$ = CHR$(13) OR (focus = 7 AND info <> 0) THEN 'mutually exclusive options
IF focus = 5 AND o(5).sel = 1 THEN
o(6).sel = 0
ELSEIF focus = 6 AND o(6).sel = 1 THEN
o(5).sel = 0
o(7).sel = 0
o(8).sel = 0
ELSEIF focus = 7 AND o(7).sel = 1 THEN
o(8).sel = 0
ELSEIF focus = 8 AND o(8).sel = 1 THEN
o(5).sel = 0
o(6).sel = 0
o(7).sel = 0
END IF
IF K$ = CHR$(13) OR (focus = 9 AND info <> 0) THEN
idefindcasesens = o(2).sel idefindcasesens = o(2).sel
idefindwholeword = o(3).sel idefindwholeword = o(3).sel
idefindbackwards = o(4).sel idefindbackwards = o(4).sel
idefindnocomments = o(5).sel idefindnocomments = o(5).sel
idefindnostrings = o(6).sel idefindonlycomments = o(6).sel
idefindnostrings = o(7).sel
idefindonlystrings = o(8).sel
s$ = idetxt(o(1).txt) s$ = idetxt(o(1).txt)
idefindtext$ = s$ idefindtext$ = s$
IdeAddSearched idefindtext IdeAddSearched idefindtext
@ -7284,9 +7353,11 @@ SUB idefindagain
END IF END IF
IF x THEN IF x THEN
findquotecomment$ = LEFT$(l$, x): GOSUB FindQuoteComment FindQuoteComment l$, x, comment, quote
IF idefindnocomments <> 0 AND comment THEN x = 0 IF idefindnocomments <> 0 AND comment THEN x = 0
IF idefindnostrings <> 0 AND quote THEN x = 0 IF idefindnostrings <> 0 AND quote THEN x = 0
IF idefindonlycomments <> 0 AND comment = 0 THEN x = 0
IF idefindonlystrings <> 0 AND quote = 0 THEN x = 0
END IF END IF
IF x THEN IF x THEN
@ -7326,18 +7397,6 @@ SUB idefindagain
IF y > iden THEN y = 1: looped = 1 IF y > iden THEN y = 1: looped = 1
GOTO idefindnext2 GOTO idefindnext2
END IF END IF
EXIT SUB
FindQuoteComment:
comment = 0: quote = 0
FOR find_k = 1 TO LEN(findquotecomment$)
SELECT CASE MID$(findquotecomment$, find_k, 1)
CASE CHR$(34): quote = NOT quote
CASE "'": IF quote = 0 THEN comment = -1: EXIT FOR
END SELECT
NEXT find_k
RETURN
END SUB END SUB
FUNCTION idegetline$ (i) FUNCTION idegetline$ (i)
@ -8696,6 +8755,8 @@ SUB ideshowtext
initialNum.char$ = "0123456789-.&" initialNum.char$ = "0123456789-.&"
num.char$ = "0123456789EDed+-.`%&!#~HBOhboACFacf" num.char$ = "0123456789EDed+-.`%&!#~HBOhboACFacf"
DIM ideshowtext_comment AS _BYTE, ideshowtext_quote AS _BYTE
STATIC prevListOfCustomWords$, manualList AS _BYTE STATIC prevListOfCustomWords$, manualList AS _BYTE
DIM startTime AS SINGLE DIM startTime AS SINGLE
@ -8815,12 +8876,12 @@ SUB ideshowtext
idecy_multilinestart = 0 idecy_multilinestart = 0
idecy_multilineend = 0 idecy_multilineend = 0
a$ = idegetline(idecy) a$ = idegetline(idecy)
findquotecomment$ = a$: GOSUB FindQuoteComment FindQuoteComment a$, LEN(a$), ideshowtext_comment, ideshowtext_quote
IF RIGHT$(a$, 1) = "_" AND ideshowtext_comment = 0 THEN IF RIGHT$(a$, 1) = "_" AND ideshowtext_comment = 0 THEN
'Find the beginning of the multiline 'Find the beginning of the multiline
FOR idecy_i = idecy - 1 TO 1 STEP -1 FOR idecy_i = idecy - 1 TO 1 STEP -1
b$ = idegetline(idecy_i) b$ = idegetline(idecy_i)
findquotecomment$ = b$: GOSUB FindQuoteComment FindQuoteComment b$, LEN(b$), ideshowtext_comment, ideshowtext_quote
IF RIGHT$(b$, 1) <> "_" OR ideshowtext_comment = -1 THEN idecy_multilinestart = idecy_i + 1: EXIT FOR IF RIGHT$(b$, 1) <> "_" OR ideshowtext_comment = -1 THEN idecy_multilinestart = idecy_i + 1: EXIT FOR
NEXT NEXT
IF idecy_multilinestart = 0 THEN idecy_multilinestart = 1 IF idecy_multilinestart = 0 THEN idecy_multilinestart = 1
@ -8828,20 +8889,20 @@ SUB ideshowtext
'Find the end of the multiline 'Find the end of the multiline
FOR idecy_i = idecy + 1 TO iden FOR idecy_i = idecy + 1 TO iden
b$ = idegetline(idecy_i) b$ = idegetline(idecy_i)
findquotecomment$ = b$: GOSUB FindQuoteComment FindQuoteComment b$, LEN(b$), ideshowtext_comment, ideshowtext_quote
IF RIGHT$(b$, 1) <> "_" OR ideshowtext_comment = -1 THEN idecy_multilineend = idecy_i: EXIT FOR IF RIGHT$(b$, 1) <> "_" OR ideshowtext_comment = -1 THEN idecy_multilineend = idecy_i: EXIT FOR
NEXT NEXT
IF idecy_multilineend = 0 THEN idecy_multilinestart = iden IF idecy_multilineend = 0 THEN idecy_multilinestart = iden
ELSE ELSE
IF idecy > 1 THEN b$ = idegetline(idecy - 1) ELSE b$ = "" IF idecy > 1 THEN b$ = idegetline(idecy - 1) ELSE b$ = ""
findquotecomment$ = b$: GOSUB FindQuoteComment FindQuoteComment b$, LEN(b$), ideshowtext_comment, ideshowtext_quote
IF RIGHT$(b$, 1) = "_" AND ideshowtext_comment = 0 THEN IF RIGHT$(b$, 1) = "_" AND ideshowtext_comment = 0 THEN
idecy_multilineend = idecy idecy_multilineend = idecy
'Find the beginning of the multiline 'Find the beginning of the multiline
FOR idecy_i = idecy - 1 TO 1 STEP -1 FOR idecy_i = idecy - 1 TO 1 STEP -1
b$ = idegetline(idecy_i) b$ = idegetline(idecy_i)
findquotecomment$ = b$: GOSUB FindQuoteComment FindQuoteComment b$, LEN(b$), ideshowtext_comment, ideshowtext_quote
IF RIGHT$(b$, 1) <> "_" OR ideshowtext_comment = -1 THEN idecy_multilinestart = idecy_i + 1: EXIT FOR IF RIGHT$(b$, 1) <> "_" OR ideshowtext_comment = -1 THEN idecy_multilinestart = idecy_i + 1: EXIT FOR
NEXT NEXT
IF idecy_multilinestart = 0 THEN idecy_multilinestart = 1 IF idecy_multilinestart = 0 THEN idecy_multilinestart = 1
@ -8885,7 +8946,7 @@ SUB ideshowtext
'Check if the cursor is positioned inside a comment or 'Check if the cursor is positioned inside a comment or
'quotation marks: 'quotation marks:
findquotecomment$ = LEFT$(a$, idecx): GOSUB FindQuoteComment FindQuoteComment a$, idecx, ideshowtext_comment, ideshowtext_quote
idecx_comment = ideshowtext_comment idecx_comment = ideshowtext_comment
idecx_quote = ideshowtext_quote idecx_quote = ideshowtext_quote
@ -9287,16 +9348,6 @@ SUB ideshowtext
SCREEN , , 0, 0: LOCATE idecy - idesy + 3, maxLineNumberLength + idecx - idesx + 2: SCREEN , , 3, 0 SCREEN , , 0, 0: LOCATE idecy - idesy + 3, maxLineNumberLength + idecx - idesx + 2: SCREEN , , 3, 0
EXIT SUB EXIT SUB
FindQuoteComment:
ideshowtext_comment = 0: ideshowtext_quote = 0
FOR ideshowtext_k = 1 TO LEN(findquotecomment$)
SELECT CASE MID$(findquotecomment$, ideshowtext_k, 1)
CASE CHR$(34): ideshowtext_quote = NOT ideshowtext_quote
CASE "'": IF ideshowtext_quote = 0 THEN ideshowtext_comment = -1: EXIT FOR
END SELECT
NEXT ideshowtext_k
RETURN
ShowLineNumber: ShowLineNumber:
IF ShowLineNumbersUseBG THEN COLOR , 6 IF ShowLineNumbersUseBG THEN COLOR , 6
PRINT SPACE$(maxLineNumberLength); PRINT SPACE$(maxLineNumberLength);