@@ -81,7 +81,11 @@ enum programState runEditor()
8181 {
8282 editor_ScrollDownUnwrapped ();
8383 editor .redrawText = true;
84- // while(kb_IsDown(kb_KeyDown)) kb_Scan();
84+ }
85+ if (kb_IsDown (kb_KeyUp ))
86+ {
87+ editor_ScrollUpUnwrapped ();
88+ editor .redrawText = true;
8589 }
8690 }
8791
@@ -112,12 +116,15 @@ void drawEditorBackground()
112116
113117void drawEditorText ()
114118{
119+ dbg_printf ("drawing lines:\n" );
115120 fontlib_SetForegroundColor (black );
116121 for (int i = 0 , y = 20 ; i < MAX_LINES_ON_EDITOR_SCREEN ; i ++ , y += 15 )
117122 {
118123 fontlib_SetCursorPosition (2 , y );
119124 drawLine (editor .linePointers [i ], editor .lineLengths [editor .lineOffset + i ]);
125+ dbg_printf ("line %d, len %d\n" , i , (editor .lineLengths [editor .lineOffset + i ]));
120126 }
127+ dbg_printf ("\n" );
121128}
122129
123130struct menuBar * loadEditorMenuBar ()
@@ -278,7 +285,7 @@ char *editor_LoadWord(char *readPos, int *lenBuffer, int *widthBuffer, int maxWi
278285 return readPos ;
279286}
280287
281- char * editor_LoadLine (char * readPos , int * lenBuffer )
288+ char * editor_LoadWrappedLine (char * readPos , int * lenBuffer )
282289{
283290 char * prevReadPos ;
284291 int lineLen = 0 , lineWidth = 0 ;
@@ -432,7 +439,7 @@ void drawLine(char *start, int len)
432439 }
433440}
434441
435- bool editor_ScrollDown (void )
442+ bool editor_ScrollDownWrapped (void )
436443{
437444 char * lastLine = editor .linePointers [MAX_LINES_ON_EDITOR_SCREEN - 1 ];
438445 int lastLineLen = editor .lineLengths [editor .lineOffset + MAX_LINES_ON_EDITOR_SCREEN - 1 ];
@@ -534,7 +541,6 @@ bool editor_ScrollDownUnwrapped(void)
534541 for (int i = 0 ; i < MAX_LINES_ON_EDITOR_SCREEN - 1 ; i ++ )
535542 {
536543 editor .linePointers [i ] = editor .linePointers [i + 1 ];
537- editor .lineLengths [i ] = editor .lineLengths [i + 1 ];
538544 }
539545
540546 // increment the line offset
@@ -549,6 +555,31 @@ bool editor_ScrollDownUnwrapped(void)
549555 return true;
550556}
551557
558+ bool editor_ScrollUpUnwrapped (void )
559+ {
560+ // if we can't scroll up, too bad so sad
561+ if (editor .lineOffset < 1 )
562+ {
563+ return false;
564+ }
565+
566+ // shift all the line pointers down one
567+ for (int i = (MAX_LINES_ON_EDITOR_SCREEN - 1 ); i >= 1 ; i -- )
568+ {
569+ editor .linePointers [i ] = editor .linePointers [i - 1 ];
570+ }
571+
572+ // decrement the line offset
573+ editor .lineOffset -- ;
574+
575+ // to find the pointer to the line we are scrolling up to,
576+ // subtract its stored length from the pointer to the line right below it
577+ editor .linePointers [0 ] = editor .linePointers [1 ] - editor .lineLengths [editor .lineOffset ];
578+
579+ // we scrolled up, so success!
580+ return true;
581+ }
582+
552583void editor_LoadUnwrappedScreen (char * startingPtr , int startingLine )
553584{
554585 int length ;
0 commit comments