1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-03 03:01:21 +00:00

Improves on listbox search, allowing for more than the first letter to be searched (repeatedly pressing the same letter still works as before).

This commit is contained in:
FellippeHeitor 2015-12-31 02:23:06 -02:00
parent 649d44b27e
commit cf05f689a4

View file

@ -6772,6 +6772,7 @@ LOOP
END FUNCTION END FUNCTION
SUB ideobjupdate (o AS idedbotype, focus, f, focusoffset, kk$, altletter$, mb, mousedown, mouseup, mx, my, info, mw) SUB ideobjupdate (o AS idedbotype, focus, f, focusoffset, kk$, altletter$, mb, mousedown, mouseup, mx, my, info, mw)
STATIC SearchTerm$, LastKeybInput as single
DIM sep AS STRING * 1 DIM sep AS STRING * 1
sep = CHR$(0) sep = CHR$(0)
@ -6976,50 +6977,71 @@ IF t = 2 THEN 'list box
END IF END IF
IF LEN(kk$) = 1 THEN IF LEN(kk$) = 1 THEN
ResetKeybTimer = 0
IF TIMER - LastKeybInput > 1 THEN SearchTerm$ = "": ResetKeybTimer = -1
LastKeybInput = TIMER
k = ASC(UCASE$(kk$)): IF k < 32 OR k > 126 THEN k = 255 k = ASC(UCASE$(kk$)): IF k < 32 OR k > 126 THEN k = 255
old_sel = o.sel 'Populate ListBoxITEMS:
a$ = idetxt(o.txt) a$ = idetxt(o.txt)
redim ListBoxITEMS(0) as string
retryfind: if len(a$) > 0 then
n = 1 n = 0: x = 1
x = 1 do
x2 = INSTR(x, a$, sep) x2 = INSTR(x, a$, sep)
IF LEN(a$) THEN again = 1 ELSE again = 0 if x2 > 0 then
DO WHILE x2 <> 0 OR again <> 0 n = n + 1
IF x2 THEN redim _preserve ListBoxITEMS(1 to n) as string
ca2$ = MID$(a$, x, x2 - x) ListBoxITEMS(n) = mid$(a$, x, x2 - x)
a2$ = UCASE$(ca2$) else
n = n + 1
redim _preserve ListBoxITEMS(1 to n) as string
ListBoxITEMS(n) = right$(a$, len(a$) - x + 1)
exit do
end if
x = x2 + 1 x = x2 + 1
again = 1 loop
ELSE end if
ca2$ = RIGHT$(a$, LEN(a$) - x + 1)
a2$ = UCASE$(ca2$)
again = 0
END IF
IF n > old_sel THEN if k = 255 then
match = 0 if o.sel > 0 then idetxt(o.stx) = ListBoxITEMS(o.sel)
FOR ai = 1 TO LEN(a2$) goto selected 'Search is not performed if kk$ isn't a printable character
aa = ASC(a2$, ai) else
IF aa > 126 OR (k <> 95 AND aa = 95) THEN SearchTerm$ = SearchTerm$ + UCASE$(kk$)
'ignore END IF
ELSE
IF aa = k THEN match = 1 if len(SearchTerm$) = 2 and left$(SearchTerm$, 1) = right$(SearchTerm$, 1) then
EXIT FOR 'if the user is pressing the same letter again, we deduce the search
END IF 'is only for the initials
NEXT ResetKeybTimer = -1
IF match = 1 THEN SearchTerm$ = ucase$(kk$)
o.sel = n end if
GOTO selected
SearchPass = 1
if not ResetKeybTimer then StartSearch = abs(o.sel) else StartSearch = abs(o.sel) + 1
if StartSearch < 1 or StartSearch > n then StartSearch = 1
retryfind:
if SearchPass > 2 then goto selected
for findMatch = StartSearch to n
validCHARS$ = ""
FOR ai = 1 TO LEN(ListBoxITEMS(FindMatch))
aa = ASC(ucase$(ListBoxITEMS(findMatch)), ai)
IF aa > 126 OR (k <> 95 AND aa = 95) THEN
'ignore
ELSE
validCHARS$ = validCHARS$ + CHR$(aa)
END IF END IF
END IF NEXT
if findMatch = o.sel then idetxt(o.stx) = ListBoxITEMS(FindMatch)
IF n = o.sel THEN idetxt(o.stx) = ca2$ IF left$(validCHARS$, len(SearchTerm$)) = SearchTerm$ THEN
n = n + 1 o.sel = findMatch
x2 = INSTR(x, a$, sep) GOTO selected
LOOP end if
IF old_sel THEN old_sel = 0: GOTO retryfind next findMatch
'No match, try again:
StartSearch = 1
SearchPass = SearchPass + 1
goto retryfind
selected: selected:
END IF END IF