more searching tweaks

This commit is contained in:
~d6 2022-03-31 13:48:08 -04:00
parent ac49260c04
commit 6668d45bd8
1 changed files with 41 additions and 25 deletions

View File

@ -509,26 +509,37 @@
;jump-to-line JSR2
;redraw-all JSR2 ;return JMP2
@jump-to-line ( n* -> )
.term/rows LDZ2 INC2 #0002 DIV2 LTH2k ( n rows/2 n<rows/2? ) ,&early JCN
OVR2 SWP2 SUB2 ( n n-rows/2 )
.buffer/line-count LDZ2 ( n n-rows/2 lines )
.term/rows LDZ2 SUB2 ( n n-rows/2 lines-rows )
GTH2k ( n n-rows/2 lines-rows n-rows/2>lines-rows? )
,&late JCN ( n n-rows/2 lines-rows )
@move-to-coord ( col* row* -> )
DUP2 ;line-is-visible JSR2 ;jump-to-coord/short JCN2
;jump-to-coord JMP2
@jump-to-coord ( x* y* -> )
.term/rows LDZ2 INC2 #0002 DIV2 LTH2k ( x y rows/2 y<rows/2? ) ,&early JCN
OVR2 SWP2 SUB2 ( x y y-rows/2 )
.buffer/line-count LDZ2 ( x y y-rows/2 lines )
.term/rows LDZ2 SUB2 ( x y y-rows/2 lines-rows )
GTH2k ( x y y-rows/2 lines-rows y-rows/2>lines-rows? )
,&late JCN ( x y y-rows/2 lines-rows )
POP2 ,&finish JMP
&early ( n rows/2 )
POP2 #0000 ,&finish JMP ( n 0000 )
&late ( n n-rows/2 lines-rows )
&early ( x y rows/2 )
POP2 #0000 ,&finish JMP ( x y 0000 )
&late ( x y y-rows/2 lines-rows )
NIP2
&finish ( n o )
SUB2k STH2 DUP2 ( n o o [n-o] )
.buffer/line-offset STZ2 ( n o [n-o] )
;abs-line JSR2 .buffer/offset STZ2 ( n [n-o] )
#0000 .cursor/col STZ2 ( n [n-o] )
POP2r .cursor/row STZ2
&finish ( x y o )
;redraw-all JSR2
SUB2k STH2 DUP2 ( x y o o [y-o] )
.buffer/line-offset STZ2 ( x y o [y-o] )
;abs-line JSR2 .buffer/offset STZ2 ( x y [y-o] )
POP2r
&short
;redraw-statusbar-and-cursor JSR2
.cursor/row STZ2 ( x )
.cursor/col STZ2
JMP2r
@jump-to-line ( n* -> )
#0000 SWP2 ;jump-to-coord JMP2
@ensure-visible-cursor
;cur-rel-row JSR2 .term/rows LDZ2 LTH2 ,&noop JCN
;cur-abs-row JSR2 ;jump-to-line JSR2
@ -602,6 +613,8 @@
;redraw-prompt-and-cursor JSR2 ;return JMP2
@do-search ( -> )
( TODO: verify the match found anything )
( if not we should display an error instead of activating searching )
#01 .searching/active STZ
;move-to-next-match JMP2
@ -699,12 +712,10 @@
ORA ,&found JCN
INC2 ,&loop JMP
&found
NIP2 ;jump-to-pos JSR2
,&done JMP
NIP2 ;jump-to-pos JSR2 ,&done JMP
&fail
POP2 POP2
&done
;redraw-all JSR2
;return JMP2
@move-to-prev-match
@ -718,12 +729,10 @@
ORA ,&found JCN
#0001 SUB2 ,&loop JMP
&found
NIP2 ;jump-to-pos JSR2
,&done JMP
NIP2 ;jump-to-pos JSR2 ,&done JMP
&fail
POP2 POP2
&done
;redraw-all JSR2
;return JMP2
@on-key-searching
@ -1088,12 +1097,19 @@
&tabs #0004 ADD2 ,&loop JMP
&done POP2 STH2r JMP2r )
@line-is-visible ( n* -> bool^ )
.buffer/line-offset LDZ2 LTH2k ,&no JCN
.term/rows LDZ2 ADD2 LTH2 JMP2r
&no POP2 POP2 #00 JMP2r
( TODO: leaving stuff on stack it seems )
@jump-to-pos ( s* -> )
;pos-to-row-col JSR2 ( row col )
SWP2 ;jump-to-line JSR2
.cursor/col STZ2
JMP2r
SWP2 ( DUP2 ;line-is-visible JSR2 ,&short JCN
;jump-to-line JSR2 ,&done JMP
&short .cursor/row STZ2
&done .cursor/col STZ2 JMP2r )
;move-to-coord JMP2
@pos-to-row-col ( s* -> row* col* )
#0000 ,&row STR2