USING: accessors ui.gadgets.editors tools.test kernel io
io.streams.plain definitions namespaces ui.gadgets
ui.gadgets.grids prettyprint documents ui.gestures tools.test.ui
-models documents.elements ui.gadgets.scrollers sequences ;
+models documents.elements ui.gadgets.scrollers ui.gadgets.line-support
+sequences ;
IN: ui.gadgets.editors.tests
[ "foo bar" ] [
[ ] [ <editor> "A" over set-editor-string com-join-lines ] unit-test
[ "A B" ] [ <editor> "A\nB" over set-editor-string [ com-join-lines ] [ editor-string ] bi ] unit-test
-[ 2 ] [ <editor> 20 >>min-rows 20 >>min-cols pref-viewport-dim length ] unit-test
\ No newline at end of file
+[ 2 ] [ <editor> 20 >>min-rows 20 >>min-cols pref-viewport-dim length ] unit-test
+
+[ 20 ] [
+ <editor> 20 >>min-rows 20 >>min-cols
+ dup pref-viewport-dim >>dim
+ visible-lines
+] unit-test
+
: next-line ( editor -- ) line-elt editor-next ;
-: select-previous-line ( editor -- )
- line-elt editor-select-prev ;
+<PRIVATE
-: select-next-line ( editor -- )
- line-elt editor-select-next ;
+: page-elt ( editor -- editor element ) dup visible-lines <page-elt> ;
+
+PRIVATE>
+
+: previous-page ( editor -- ) page-elt editor-prev ;
+
+: next-page ( editor -- ) page-elt editor-next ;
+
+: select-previous-line ( editor -- ) line-elt editor-select-prev ;
+
+: select-next-line ( editor -- ) line-elt editor-select-next ;
+
+: select-previous-page ( editor -- ) page-elt editor-select-prev ;
+
+: select-next-page ( editor -- ) page-elt editor-select-next ;
: insert-newline ( editor -- )
"\n" swap user-input* drop ;
{ T{ key-down f f "DOWN" } next-line }
{ T{ key-down f { S+ } "UP" } select-previous-line }
{ T{ key-down f { S+ } "DOWN" } select-next-line }
+ { T{ key-down f f "PAGE_UP" } previous-page }
+ { T{ key-down f f "PAGE_DOWN" } next-page }
+ { T{ key-down f { S+ } "PAGE_UP" } select-previous-page }
+ { T{ key-down f { S+ } "PAGE_DOWN" } select-next-page }
{ T{ key-down f f "RET" } insert-newline }
{ T{ key-down f { S+ } "RET" } insert-newline }
{ T{ key-down f f "ENTER" } insert-newline }
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators fry kernel math math.functions math.order
math.ranges math.vectors namespaces opengl sequences ui.gadgets
-ui.render ui.text ui.gadgets.scrollers ;
+ui.render ui.text ui.gadgets.scrollers ui.gadgets.viewports ;
IN: ui.gadgets.line-support
! Some code shared by table and editor gadgets
[ pref-dim ] keep
[ line-gadget-width ]
[ line-gadget-height ]
- 2bi 2array ;
\ No newline at end of file
+ 2bi 2array ;
+
+: visible-lines ( gadget -- n )
+ [ visible-dim second ] [ line-height ] bi /i 1- ;
\ No newline at end of file